コード例 #1
0
ファイル: YammerTaskRunner.cs プロジェクト: cbadke/yammerbot
 public YammerTaskRunner(IYammerMessagePoster poster, IYammerMessageFetcher messageFetcher, IYammerMessageDatabaseManager databaseManager, IYammerResponseFetcher responseFetcher, IRandomNumberGenerator randomNumberGenerator, IYammerCommandFetcher commandFetcher)
 {
     _poster = poster;
     _messageFetcher = messageFetcher;
     _databaseManager = databaseManager;
     _responseFetcher = responseFetcher;
     _randomNumberGenerator = randomNumberGenerator;
     _commandFetcher = commandFetcher;
 }
コード例 #2
0
 public void YammerMessagePosterSetup()
 {
     _serviceManager = new Mock<IYammerMessageServiceManager>();
     _deserializer = new Mock<IYammerMessageResponseDeserializer>();
     _messagePoster = new YammerMessagePoster(_serviceManager.Object, _deserializer.Object);
 }
コード例 #3
0
        public YammerCommandFetcher(IRandomNumberGenerator randomNumberGenerator, 
                                    IYammerMessagePoster poster, 
                                    IQuoteRetriever quoteRetriever, 
                                    IComplimentFetcher complimentFetcher,
                                    IDictionaryService dictionaryService)
        {
            _randomNumberGenerator = randomNumberGenerator;
            _poster = poster;
            _quoteRetriever = quoteRetriever;
            _complimentFetcher = complimentFetcher;
            _dictionaryService = dictionaryService;
            _allCommands = new Dictionary<string, Func<Message, Message>>
                                  {
                                      {
                                          "randomquote", (message) =>
                                                             {
                                                                 string quote = null;
                                                                 try
                                                                 {
                                                                     quote = _quoteRetriever.GetNextQuote();
                                                                 }
                                                                 finally
                                                                 {
                                                                     if (quote == null)
                                                                         quote = "I don't have any more quotes...";
                                                                 }
                                                                 return _poster.PostReply(quote, message.ID);
                                                             }
                                      },
                                      {
                                          "tellmetofuckoff", (message) =>
                                                                 {
                                                                     return _poster.PostReply("F**k off", message.ID);
                                                                 }
                                      },
                                      {
                                          "help", (message) =>
                                                      {
                                                          return _poster.PostReply(
                                                              "@@RandomQuote gives a random quote, @@TellMeToFuckOff tells you to f**k off, @@CatFacts will send you a random cat fact",
                                                              message.ID);
                                                      }
                                      },
                                      {
                                          "catfacts", (message) =>
                                                          {
                                                              var responses = new Dictionary<int, string>
                                                                                  {
                                                                                      {0, "Cats have 9 lives"},
                                                                                      {1, "Cats are cute"},
                                                                                      {2, "Cats just don't give a f**k"}
                                                                                  };
                                                              var selectedResponse =
                                                                  responses[_randomNumberGenerator.GetRandomInt32(0, 3)];
                                                              return _poster.PostReply(selectedResponse, message.ID);
                                                          }
                                      },
                                      {
                                          "whispersweetnothingstome", (message) =>
                                                          {
                                                              return _poster.PostReply(_complimentFetcher.GetRandomComplimentPhrase(), message.ID);
                                                          }
                                      },
                                      {
                                          "sexify", (message) =>
                                                          {
                                                              var cmd = new Command(message.Body.Plain);
                                                              var wordDefinitions = cmd.Argument.Split(' ')
                                                                                       .Select(word => WordProcessor.NormalizeWord(word))
                                                                                       .Aggregate(new Dictionary<string,IEnumerable<string>>(),(accum, word) =>
                                                                                                   {
                                                                                                       if (!accum.Keys.Contains(word))
                                                                                                           accum.Add(word, _dictionaryService.GetDefinitions(word));
                                                                                                       return accum;
                                                                                                   });

                                                              return _poster.PostReply(WordProcessor.Sexify(cmd.Argument, wordDefinitions), message.ID);
                                                          }
                                      },
                                  };
        }