Esempio n. 1
0
        public async Task Ban(IGuildUser u, int minutes = 0, [Remainder] string reason = null)
        {
            string rText = ".";

            if (reason != null)
            {
                rText = $" for: \"{reason}\".";
            }

            string tText = "";

            if (minutes != 0)
            {
                TimeSpan tSpan     = new TimeSpan(0, minutes, 0);
                var      unbanTime = DateTime.Now + tSpan;
                Var.leaveBanned.Add(u);
                Var.unbanTime.Add(unbanTime);
                tText = $"\nThey have been banned until {unbanTime}.";
            }

            InfoEmbed banEmb = new InfoEmbed("USER BAN", $"User: {u} has been banned{rText}.{tText}", Constants.Images.Ban);
            await Context.Guild.AddBanAsync(u, reason : reason);

            await Context.Channel.SendMessageAsync("", embed : banEmb.Build());
        }
Esempio n. 2
0
        public async Task Purge(int amount)
        {
            Var.purging = true;
            var messages = await Context.Channel.GetMessagesAsync(amount + 1).Flatten();

            await Context.Channel.DeleteMessagesAsync(messages);

            InfoEmbed ie = new InfoEmbed("PURGE", $"{amount} messages deleted by {Context.User.Username}.");

            Var.purgeMessage = await Context.Channel.SendMessageAsync("", embed : ie.Build());

            Timers.unpurge = new Timer(new TimerCallback(Timers.UnPurge), null, 5000, Timeout.Infinite);
        }
Esempio n. 3
0
        public async Task Kick(IUser u, [Remainder] string reason = null)
        {
            string rText = ".";

            if (reason != null)
            {
                rText = $" for: \"{reason}\".";
            }
            InfoEmbed kickEmb = new InfoEmbed("USER KICK", $"User: {u} has been kicked{rText}", Constants.Images.Kick);

            await(u as IGuildUser).KickAsync(reason);
            await Context.Channel.SendMessageAsync("", embed : kickEmb.Build());
        }
Esempio n. 4
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;
            }
        }
Esempio n. 5
0
        public async Task HandleCommand(SocketMessage messageParam)
        {
            var message = messageParam as SocketUserMessage;

            if (message == null)
            {
                return;
            }
            int argPos = 0;

            if (Var.blockedUsers.Contains(message.Author))
            {
                return;
            }

            var user = Functions.GetUser(message.Author);

            if (Var.recieving)
            {
                if (message.Channel == Var.recievingChannel)
                {
                    var bBunch = client.GetGuild(371695008157532160).GetChannel(381656424247197697) as IMessageChannel;

                    JEmbed emb = new JEmbed();
                    emb.Title        = message.Author.Username + "#" + message.Author.Discriminator;
                    emb.Author.Name  = "MESSAGE RECIEVED";
                    emb.ThumbnailUrl = message.Author.GetAvatarUrl();
                    emb.Description  = message.Content;

                    string attachURL = null;
                    if (message.Attachments.Count > 0)
                    {
                        attachURL = message.Attachments.FirstOrDefault().ProxyUrl;
                    }
                    if (attachURL != null)
                    {
                        emb.ImageUrl = attachURL;
                    }

                    await bBunch.SendMessageAsync("", embed : emb.Build());
                }
            }

            if (message.HasCharPrefix(';', ref argPos))
            {
                var context = new CommandContext(client, message);
                var result  = await commands.ExecuteAsync(context, argPos);

                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
            {
                return;
            }
        }