Beispiel #1
0
        public Shop(bool bm = false)
        {
            isBM = bm;
            int[] nItems;
            if (isBM)
            {
                nItems = DBFunctions.GetBMItemIDList();
            }
            else
            {
                nItems = DBFunctions.GetItemIDList(shoppable: true, includeBM: false);
            }
            List <int> items = new List <int>();
            List <int> stock = new List <int>();

            for (int i = 0; i < 5; i++)
            {
                int itemIndex = rdm.Next(nItems.Length);
                if (!items.Contains(nItems[itemIndex]))
                {
                    items.Add(nItems[itemIndex]);
                    if (!isBM)
                    {
                        stock.Add(rdm.Next(5, 16));
                    }
                    else
                    {
                        stock.Add(rdm.Next(1, 5));
                    }
                }
                else
                {
                    i--;
                }
            }

            this.items = items;
            this.stock = stock;

            openDate = Var.CurrentDate();
        }
Beispiel #2
0
        public async Task HandleCommand(SocketMessage messageParam)
        {
            SocketUserMessage message = messageParam as SocketUserMessage;
            bool isDM = await Functions.isDM(message as IMessage);

            if (isDM && Var.LockDM)
            {
                Console.WriteLine(message.Author.Username + " [" + message.Author.Id + "] attempted to use a command in DM's:\n'" + message.Content + "'"); return;
            }
            if (message == null)
            {
                return;
            }
            if (message.Author.Id == client.CurrentUser.Id)
            {
                return;                                             //doesn't allow the bot to respond to itself
            }
            if (Var.DebugMode && message.Author.Id != Constants.Users.BRADY && Var.DebugUsers.Where(x => x.Id == message.Author.Id).Count() <= 0)
            {
                return;
            }

            if (!Var.DebugMode && message.Channel.Id == Constants.Channels.DEBUG)
            {
                return;
            }
            var user = Functions.GetUser(message.Author);

            #region Pre-Command Functions

            if (lastDay.DayOfYear < Var.CurrentDate().DayOfYear)
            {
                int strikeCount = (Var.CurrentDate() - Constants.Dates.STRIKE_END).Days;
                await client.SetGameAsync(strikeCount + " days since last strike", type : ActivityType.Watching);
            }

            //checks if message contains any blocked words
            if (!isDM && (message.Channel as IGuildChannel).Guild.Id == Constants.Guilds.YORK_UNIVERSITY && Functions.Filter(message.Content))
            {
                await message.DeleteAsync();

                return;
            }

            if (Var.blockedUsers.Where(x => x.Id == message.Author.Id).Count() > 0)
            {
                return;                                                                   //prevents "blocked" users from using the bot
            }
            ulong[] blockedChannels = { Constants.Channels.GENERAL_SLOW, Constants.Channels.GENERAL_TRUSTED, Constants.Channels.NEWS_DEBATE, Constants.Channels.LIFESTYLE };
            if (!isDM && (message.Channel as IGuildChannel).Guild.Id == Constants.Guilds.YORK_UNIVERSITY && (blockedChannels.Contains(message.Channel.Id)) && !(message.Author as IGuildUser).RoleIds.Contains(Constants.Roles.MOD) && !(message.Author as IGuildUser).RoleIds.Contains(Constants.Roles.BOOSTER))
            {
                return;
            }

            if (message.Author.IsBot && message.Author.Id != Constants.Users.FORKPY)
            {
                return;
            }

            //present stuff
            if (Var.presentWaiting && message.Content == Convert.ToString(Var.presentNum))
            {
                Var.presentWaiting = false;
                var presents = DBFunctions.GetItemIDList();
                int presID;
                do
                {
                    var presIndex = rdm.Next(presents.Count());
                    presID = presents[presIndex];
                } while (!DBFunctions.ItemIsPresentable(presID));
                Var.present  = DBFunctions.GetItemName(presID);
                Var.rPresent = Var.present;
                var presentName = Var.present;
                var pMessage    = DBFunctions.GetItemDescription(presID);
                var msg         = $"{message.Author.Username}! You got...\nA {Func.ToTitleCase(presentName.Replace('_', ' '))}! {DBFunctions.GetItemEmote(presID)} {pMessage}";
                user.GiveItem(Var.present);

                if (Var.replaceable)
                {
                    msg                += $"\nDon't like this gift? Press {Var.presentNum} again to replace it once!";
                    Var.replacing       = true;
                    Var.presentReplacer = message.Author;
                }
                await message.Channel.SendMessageAsync(msg);
            }
            else if (Var.replaceable && Var.replacing && message.Content == Convert.ToString(Var.presentNum) && message.Author == Var.presentReplacer)
            {
                if (user.HasItem(Var.present))
                {
                    user.RemoveItem(Var.present);
                    await message.Channel.SendMessageAsync($":convenience_store: {DBFunctions.GetItemEmote(Var.present)} :runner: \nA **new** present appears! :gift: Press {Var.presentNum} to open it!");

                    Var.presentWaiting = true;
                    Var.replacing      = false;
                    Var.replaceable    = false;
                }
                else
                {
                    await message.Channel.SendMessageAsync("You no longer have the present, so you cannot replace it!");

                    Var.replacing   = false;
                    Var.replaceable = false;
                }
            }

            //detects invites for unwanted servers (in yorku server) and deletes them
            if (!isDM && (message.Channel as IGuildChannel).Guild.Id == Constants.Guilds.YORK_UNIVERSITY && message.Content.ToLower().Contains("discord.gg") || message.Content.ToLower().Contains("discordapp.com/invite"))
            {
                var words = message.Content.Split(' ');
                foreach (string word in words)
                {
                    if (word.Contains("discord"))
                    {
                        string  id  = word.Split('/')[word.Split('/').Count() - 1];
                        IInvite inv = await client.GetInviteAsync(id);

                        if (inv.GuildId == Constants.Guilds.FORKU)
                        {
                            await messageParam.DeleteAsync();
                        }
                        return;
                    }
                }
            }

            #endregion

            int argPos = 0;
            //detect and execute commands
            if (message.HasCharPrefix(';', ref argPos))
            {
                // new user prevention
                var userCreationDate = message.Author.CreatedAt;
                var existenceTime    = DateTime.UtcNow.Subtract(userCreationDate.DateTime);
                var week             = new TimeSpan(7, 0, 0, 0);
                if (existenceTime < week)
                {
                    if (!newUsers.Contains(message.Author.Id))
                    {
                        newUsers.Add(message.Author.Id);
                        await message.Author.SendMessageAsync("Hi there! Welcome to Discord. In order to avoid bot abuse, your account must be older than a few days.\n" +
                                                              "If you don't understand, just message <@108312797162541056> about it.\nThanks!");
                    }
                    return;
                }

                var context = new CommandContext(client, message);
                var result  = await commands.ExecuteAsync(context, argPos, services : null);

                if (!result.IsSuccess)
                {
                    if (result.Error != CommandError.UnknownCommand)
                    {
                        Console.WriteLine(result.ErrorReason);
                        var emb = new InfoEmbed("ERROR:", result.ErrorReason).Build();
                        await message.Channel.SendMessageAsync("", embed : emb);
                    }
                    else
                    {
                        if (user.HasItem(message.Content.Replace(";", "")))
                        {
                            await message.Channel.SendMessageAsync("Nothing happens... *Use `;suggest [suggestion]` if you have an idea for this item!*");
                        }
                    }
                }
                else
                {
                    //give user a chance at a lootbox
                    bool inLM = false;
                    //go through users last command time
                    foreach (var u in Var.lastMessage)
                    {
                        //ensure user is in dictionary
                        if (u.Key == context.User.Id)
                        {
                            inLM = true; break;
                        }
                    }
                    if (inLM == false)
                    {
                        Var.lastMessage.Add(context.User.Id, Var.CurrentDate() - new TimeSpan(1, 0, 1));
                    }
                    //if chance of lootbox
                    if (Var.lastMessage[context.User.Id] <= Var.CurrentDate() - new TimeSpan(1, 0, 0))
                    {
                        //10% chance at lootbox
                        if (rdm.Next(100) + 1 < 10)
                        {
                            await context.Channel.SendMessageAsync(":package: `A lootbox appears in your inventory! (package)`");

                            Functions.GetUser(context.User).GiveItem("package");
                        }
                    }
                    //set last message time to now
                    Var.lastMessage[context.User.Id] = Var.CurrentDate();
                }
            }
            else if (message.MentionedUsers.First().Id == client.CurrentUser.Id && message.Author.Id != client.CurrentUser.Id && Var.responding && ((message.Channel as IGuildChannel).Guild.Id != Constants.Guilds.YORK_UNIVERSITY || message.Channel.Id == Constants.Channels.COMMANDS || message.Channel.Id == 265998661606047744))
            {
                Functions.Respond(message);
            }
            else if ((message.Channel as IGuildChannel).Guild.Id != Constants.Guilds.YORK_UNIVERSITY && !Var.responding)
            {
                Functions.Respond(message);
            }
            else
            {
                return;
            }
        }