示例#1
0
        public async Task buyCmd([Remainder] string query)
        {
            string username = Context.User.ToString();

            //check Cooldown
            if (!RexTimers.canRunCmd(username, "buy"))
            {
                await Context.Channel.SendMessageAsync("`" + RexTimers.getWaitMsg(username, "buy") + "`");

                return;
            }


            // DataUtils.coins[username] = 1000; //test purposes
            //Check query argument count validity
            string[] words = query.Split(' ');

            //this condition will never be met.. as fun;ction will not be called (will call !help !buy)
            if (words.Length < 1)
            {
                await Context.Channel.SendMessageAsync("Specify what you want to buy");

                return;
            }

            int index = DataUtils.shop.FindIndex(f => f.Callname == words[0]);

            if (index < 0)
            {
                await Context.Channel.SendMessageAsync("You entered an invalid item");

                return;
            }

            ShopItem item = DataUtils.shop.ElementAt(index);

            if (item.Argcount != words.Length)
            {
                await Context.Channel.SendMessageAsync("Check your arguments bruh");

                return;
            }

            //Check if we have enough coins to buy item
            int cost = item.Cost;

            if (!DataUtils.canBuy(username, cost))
            {
                await Context.Channel.SendMessageAsync("You dont have enough money you poor thing");

                return;
            }

            //Actually buy the item
            DataUtils.spendCoins(username, cost);
            string name;
            int    dice;


            switch (item.Callname)
            {
            case "report":
                //check if valid user ->
                name = words[1];
                if (AliasUtils.getAliasKey(name).Contains("None"))
                {
                    await Context.Channel.SendMessageAsync("Invalid user!");
                }
                name = DataUtils.aliases[AliasUtils.getAliasKey(name)];
                dice = DataUtils.rnd.Next(1, 101);

                if (dice < 50)
                {
                    DataUtils.gainReports(name, 77);
                    await Context.Channel.SendMessageAsync(name + "has been reported 77 times LOL!");
                }
                else
                {
                    await Context.Channel.SendMessageAsync("I decided not to report anyone");
                }
                break;

            case "forgive":
                //check if valid user ->
                name = words[1];
                if (AliasUtils.getAliasKey(name).Contains("None"))
                {
                    await Context.Channel.SendMessageAsync("Invalid user!");
                }
                name = DataUtils.aliases[AliasUtils.getAliasKey(name)];
                dice = DataUtils.rnd.Next(1, 101);
                if (dice < 50)
                {
                    DataUtils.gainReports(name, -77);
                    await Context.Channel.SendMessageAsync(name + "has been forgiven 77 times!");
                }
                else
                {
                    await Context.Channel.SendMessageAsync("I decided not to forgive anyone");
                }
                break;

            case "w":
                await Context.Channel.SendMessageAsync(MasterUtils.getAnnoyingTTSString(), true);

                break;

            case "wchance":
                DataUtils.incWAddChances(username);
                await Context.Channel.SendMessageAsync("Successfully increased your !w chances by 1%");

                break;

            //case "beg":
            //break;
            case "catmode":
                //length of temp catmode in MasterHandler
                RexTimers.catModeClock.Start();
                break;

            case "restrain":
                name = words[1];
                if (AliasUtils.getAliasKey(name).Contains("None"))
                {
                    await Context.Channel.SendMessageAsync("Invalid user!");
                }
                name = DataUtils.aliases[AliasUtils.getAliasKey(name)];

                int timeInSeconds = DataUtils.rnd.Next(121, 181);
                AdminUtils.addRestriction(name, timeInSeconds);
                await Context.Channel.SendMessageAsync(name + " is restrained for " + timeInSeconds + "s!");

                break;

            case "purge":
                if (int.Parse(words[1]) > 30)
                {
                    await Context.Channel.SendMessageAsync("You tried to purge too many messages! What a waste of coins...");
                }
                var messages = await Context.Channel.GetMessagesAsync((int.Parse(words[1]) + 1)).Flatten();

                await Context.Channel.DeleteMessagesAsync(messages);

                break;

            case "tts":
                name = words[1];
                if (AliasUtils.getAliasKey(name).Contains("None"))
                {
                    await Context.Channel.SendMessageAsync("Invalid user! What a waste of coins...");
                }
                name = DataUtils.aliases[AliasUtils.getAliasKey(name)];
                RexTimers.addPersonToTTS(name);
                await Context.Channel.SendMessageAsync("```" + username + " decided to tts-annoy " + name + "!\n" + name + " better start sending messages for the next 3 minutes or i'm going to take all of your coins!```");

                break;

            case "annoy":
                name = words[1];
                if (AliasUtils.getAliasKey(name).Contains("None"))
                {
                    await Context.Channel.SendMessageAsync("Invalid user! What a waste of coins...");
                }
                name = DataUtils.aliases[AliasUtils.getAliasKey(name)];
                RexTimers.addPersonToAnnoy(name);
                await Context.Channel.SendMessageAsync("```" + username + " decided to super annoy " + name + "!\n" + name + " better start sending messages for the next 3 minutes or i'm going to take all of your coins!```");

                break;

            case "confuse":
                name = words[1];
                if (AliasUtils.getAliasKey(name).Contains("None"))
                {
                    await Context.Channel.SendMessageAsync("Invalid user! What a waste of coins...");
                }
                name = DataUtils.aliases[AliasUtils.getAliasKey(name)];
                RexTimers.addPersonToConfuse(name);
                await Context.Channel.SendMessageAsync("```" + username + " decided to confuse " + name + "!\n" + name + " better start sending messages for the next 3 minutes or i'm going to take all of your coins!```");

                break;

            case "bribe":
                await Context.Channel.SendMessageAsync("This function is not implemented yet! What a waste of coins...");

                break;

            default: await Context.Channel.SendMessageAsync("Item not added to switch statement"); break;
            }

            //show coins spent and coins remaining
            await Context.Channel.SendMessageAsync("`" + username + " paid " + cost + "coins and has " + DataUtils.getCoinCount(username) + " left!`");

            RexTimers.resetTimer(username, "buy");
            //Check if valid argument types..? -> Just force convert..
            //await Context.Channel.SendMessageAsync("Your requested item is at index :" + index + " which costs " + DataUtils.shop.ElementAt(index).Cost);
        }