Example #1
0
 private IEnumerable<ResponseMessage> StopPingingHandler(IncomingMessage message, string matchedHandle)
 {
     if (_pingPlugin.StopPingingUser(message.UserId))
     {
         yield return message.ReplyToChannel($"Ok, I will stop pinging @{message.Username}");
     }
     else
     {
         yield return message.ReplyToChannel($"BUT I AM NOT PINGING @{message.Username}");
     }
 }
Example #2
0
        private IEnumerable<ResponseMessage> CalculateHandler(IncomingMessage message, string matchedHandle)
        {
            string response = string.Empty;

            if (matchedHandle != null)
            {
                string expression = message.FullText.Substring(matchedHandle.Length).Trim();
                Parser parser = new Parser();

                try
                {
                    IExpression parsedExpression = parser.Parse(expression);
                    object result = parsedExpression.Calculate();
                    response = $"{parsedExpression} = {result}";
                }
                catch (Exception e)
                {
                    bool showErrors = !string.IsNullOrEmpty(matchedHandle);

                    if (showErrors)
                    {
                        response = $"Who taught you maths? {e.Message}";
                    }
                }
            }

            if (!string.IsNullOrEmpty(response))
            {
                yield return message.ReplyToChannel($"@{message.Username}: {response}");
            }
        }
Example #3
0
        private IEnumerable<ResponseMessage> JokeHandler(IncomingMessage message, string matchedHandle)
        {
            yield return message.ReplyToChannel("Hmm... let me think");

            IRestResponse jokeResponse = new Random().Next(0, 100) < 70 ? GetTambalJoke() : GetMommaJoke();
            if (jokeResponse.StatusCode == HttpStatusCode.OK)
            {
                var joke = JsonConvert.DeserializeObject<JokeContainer>(jokeResponse.Content);

                yield return message.ReplyToChannel("Ok...");
                yield return message.ReplyToChannel(joke.Joke);
            }
            else
            {
                yield return message.ReplyToChannel($"Dam, I can't think of one. [{jokeResponse.StatusCode}]");
            }
        }
Example #4
0
        private IEnumerable<ResponseMessage> FlickrHandler(IncomingMessage message, string matchedHandle)
        {
            string searchTerm = message.TargetedText.Substring(matchedHandle.Length).Trim();

            if (string.IsNullOrEmpty(searchTerm))
            {
                yield return message.ReplyToChannel($"Please give me something to search, e.g. {matchedHandle} trains");
            }
            else
            {
                yield return message.ReplyToChannel($"Ok, let's find you something about '{searchTerm}'");
                string apiKey = _configReader.GetConfig().Flickr?.ApiKey;

                if (string.IsNullOrEmpty(apiKey))
                {
                    yield return message.ReplyToChannel("Woops, looks like a Flickr API Key has not been entered. Please ask the admin to fix this");
                }
                else
                {
                    var flickr = new Flickr(apiKey);

                    var options = new PhotoSearchOptions { Tags = searchTerm, PerPage = 50, Page = 1};
                    PhotoCollection photos = flickr.PhotosSearch(options);

                    if (photos.Any())
                    {
                        int i = new Random().Next(0, photos.Count);
                        Photo photo = photos[i];
                        yield return message.ReplyToChannel(photo.LargeUrl);
                    }
                    else
                    {
                        yield return message.ReplyToChannel($"Sorry @{message.Username}, I couldn't find anything about {searchTerm}");
                    }
                }
            }
        }
Example #5
0
 private IEnumerable<ResponseMessage> PingHandler(IncomingMessage message, string matchedHandle)
 {
     yield return message.ReplyToChannel($"Ok, I will start pinging @{message.Username}");
     _pingPlugin.StartPingingUser(message.UserId);
 }
Example #6
0
 private IEnumerable<ResponseMessage> TestHandler(IncomingMessage message, string matchedHandle)
 {
     yield return message.ReplyToChannel($"Hey @{message.Username}, how you doing?");
     Thread.Sleep(TimeSpan.FromSeconds(5));
     yield return message.ReplyDirectlyToUser("I know where you live...");
 }