Beispiel #1
0
        public static Command GifCommand(Bot bot)
        {
            return(new Command("!gif {search parameters}", "Search for a random gif in Giphy.", "!gif angelina taxi srs", bot,
                               (message) =>
            {
                return (message.text.ToUpper().StartsWith("!GIF "));
            },
                               (message) =>
            {
                const int maxGifCounter = 3;
                var timeBeforeDecreasingGifCounter = new TimeSpan(0, 5, 0);
                var userGifCounter = bot.GetUserGifSpamCounter(message.sender_id);
                if (userGifCounter.GifCounter < maxGifCounter)
                {
                    userGifCounter.HasBeenWarned = false;

                    var searchParams = message.text.Substring(5);
                    if (searchParams.ToUpper().Contains("ALCKIE") && searchParams.ToUpper().Contains("BOT"))
                    {
                        var randomNumber = RandomHelper.GetRandomNumber(5);
                        switch (randomNumber)
                        {
                        case 1:
                            bot.SendMessage("Try searching for awesome instead.");
                            break;

                        case 2:
                            bot.SendMessage("Do you know how many times people search for that? F*****g boring...");
                            break;

                        case 3:
                            bot.SendMessage("I won't search for it, just to avoid AlckieBotception.");
                            break;

                        case 4:
                            bot.SendMessage("There are no gifs in this world that can represent my awesome self.");
                            break;

                        default:
                            bot.SendMessage("F**k off.");
                            break;
                        }
                    }
                    else
                    {
                        var url = Giphy.GetGiphyUrl(searchParams);
                        if (url != "")
                        {
                            bot.SendMessage(url);
                            userGifCounter.GifCounter++;
                            TimerHelper.ExecuteDelayedActionAsync(() =>
                            {
                                userGifCounter.GifCounter--;
                            }, timeBeforeDecreasingGifCounter);
                        }
                        else
                        {
                            bot.SendMessage("I can't find shit. Either you are an idiot, or Giphy sucks too much...");
                        }
                    }
                }
                else if (!userGifCounter.HasBeenWarned)
                {
                    userGifCounter.HasBeenWarned = true;
                    bot.SendMessage("F**k off... Just leave me alone for a while.");
                }
            }));
        }