コード例 #1
0
ファイル: InfoModule.cs プロジェクト: jpmac26/JackFrost-Bot
        public async Task Award([Summary("The user to award.")] SocketGuildUser mention, [Summary("The amount to award."), Remainder] int amount = 1)
        {
            var botlog = await Context.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(Context.Guild.Id));

            if (Xml.CommandAllowed("award", Context))
            {
                await Context.Message.DeleteAsync();

                if (amount > 10)
                {
                    await Context.Channel.SendMessageAsync("That's too much to award! Try a smaller amount.");
                }
                else if (Moderation.IsModerator((IGuildUser)Context.Message.Author))
                {
                    UserSettings.Currency.Add(Context.Guild.Id, mention.Id, amount);
                    var embed = Embeds.LogAward((SocketGuildUser)Context.Message.Author, mention.Username, amount);
                    await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);

                    embed = Embeds.Award((SocketGuildUser)Context.Message.Author, mention.Username, amount);
                    await Context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", Context.Guild.Id));
                }
            }
        }
コード例 #2
0
ファイル: Processing.cs プロジェクト: jpmac26/JackFrost-Bot
        // Check if a message is a duplicate and if so, delete it
        public static async Task DuplicateMsgCheck(SocketMessage message, SocketGuildChannel channel)
        {
            var user  = (IGuildUser)message.Author;
            var guild = user.Guild;

            if ((channel.Id != UserSettings.Channels.BotChannelId(guild.Id)) && (Moderation.IsModerator((IGuildUser)message.Author) == false) && (message.Author.IsBot == false))
            {
                int matches = 0;

                foreach (IMessage msg in (await message.Channel.GetMessagesAsync(10).FlattenAsync()))
                {
                    if ((msg.Content.ToString() == message.Content.ToString()) && (msg.Author == message.Author) && (message.Attachments.Count == 0))
                    {
                        // Be sure to verify that the tested message's timestamp is NOT greater or equal to the current one we're iterating over,
                        // because async methods can cause the current message to be pushed backwards into the "previous message" list before we can process it,
                        // resulting in us checking the current message against itself or future messages, which will result in a false-positive duplicate.
                        // Additionally, verify that the previously found message was sent within the "spam" threshold.
                        if (((message.Timestamp - msg.Timestamp).TotalSeconds < UserSettings.BotOptions.DuplicateFrequencyThreshold(channel.Guild.Id)) && (msg.Timestamp < message.Timestamp))
                        {
                            matches++;
                            if (matches >= UserSettings.BotOptions.MaximumDuplicates(channel.Guild.Id))
                            {
                                await LogDeletedMessage(message, "Duplicate message");

                                if (UserSettings.BotOptions.AutoWarnDuplicates(channel.Guild.Id))
                                {
                                    Moderation.Warn(channel.Guild.CurrentUser.Username, (ITextChannel)channel, (SocketGuildUser)message.Author, "Stop posting the same thing over and over.");
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: InfoModule.cs プロジェクト: jpmac26/JackFrost-Bot
 public async Task GetHelp()
 {
     if (Xml.CommandAllowed("help", Context))
     {
         var embed = Embeds.Help(Context.Guild.Id, Moderation.IsModerator((IGuildUser)Context.Message.Author));
         await Context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
     }
 }
コード例 #4
0
ファイル: InfoModule.cs プロジェクト: jpmac26/JackFrost-Bot
 public async Task Markov([Remainder, Summary("The rest of your message.")] string msg = "")
 {
     if (Xml.CommandAllowed("markov", Context))
     {
         if (!Context.Message.Author.IsBot && Moderation.IsPublicChannel((SocketGuildChannel)Context.Message.Channel))
         {
             await Processing.Markov(Context.Message.Content, (SocketGuildChannel)Context.Channel, 100);
         }
     }
 }
コード例 #5
0
ファイル: FrostForm.cs プロジェクト: Tupelov/JackFrost-Bot
        private void Btn_ClearSelectedWarns_Click(object sender, EventArgs e)
        {
            var guild   = guilds[selectedServer];
            var channel = (ITextChannel)guild.TextChannels.ToList()[selectedChannel];

            foreach (var item in listBox_Warns.SelectedItems)
            {
                Moderation.ClearWarn(guild.CurrentUser, channel, listBox_Warns.Items.IndexOf(item), null);
            }
            listBox_Warns.Update();
        }
コード例 #6
0
ファイル: FrostForm.cs プロジェクト: Tupelov/JackFrost-Bot
        private void btn_PurgeMsgs_Click(object sender, EventArgs e)
        {
            SocketGuild  guild   = guilds[selectedServer];
            ITextChannel channel = guild.TextChannels.ToList()[selectedChannel];
            var          amount  = (int)numericUpDown_Purge.Value;

            DialogResult dialogResult = MessageBox.Show($"Are you sure you want to delete the last {amount} messages in #{channel.Name}?", "Delete Messages?", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                Moderation.DeleteMessages(channel, amount);
            }
        }
コード例 #7
0
ファイル: InfoModule.cs プロジェクト: jpmac26/JackFrost-Bot
 public async Task ResetMarkov()
 {
     if (Xml.CommandAllowed("reset markov", Context))
     {
         if (Moderation.IsModerator((IGuildUser)Context.Message.Author))
         {
             File.Delete($"Servers\\{Context.Guild.Id.ToString()}\\{Context.Guild.Id.ToString()}.bin");
             await Context.Channel.SendMessageAsync("Markov dictionary successfully reset!");
         }
         else
         {
             await Context.Channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", Context.Guild.Id));
         }
     }
 }
コード例 #8
0
ファイル: Processing.cs プロジェクト: jpmac26/JackFrost-Bot
        //Log replies and respond with a random reply
        public static async Task Markov(string message, SocketGuildChannel channel, int frequency)
        {
            string binFilePath = $"Servers\\{channel.Guild.Id.ToString()}\\{channel.Guild.Id.ToString()}";
            Markov mkv         = new Markov();

            try { mkv.LoadChainState(binFilePath); }
            catch { }
            //Sanitize message content
            string newMessage = message;
            var    links      = newMessage.Split("\t\n ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Where(s => s.StartsWith("http://") || s.StartsWith("www.") || s.StartsWith("https://") || s.StartsWith("@"));

            foreach (var link in links)
            {
                newMessage = newMessage.Replace(link, "");
            }

            if (newMessage != "" && Moderation.IsPublicChannel(channel))
            {
                mkv.Feed(newMessage);
            }

            mkv.SaveChainState(binFilePath);

            var    socketChannel = (ISocketMessageChannel)channel;
            Random rnd           = new Random();
            string markov        = MarkovGenerator.Create(mkv);
            int    runs          = 0;

            while (markov.Length < UserSettings.BotOptions.MarkovMinimumLength(channel.Guild.Id) && runs < 20)
            {
                markov = MarkovGenerator.Create(mkv);
                runs++;
            }

            if (rnd.Next(1, 100) <= frequency)
            {
                if (!UserSettings.BotOptions.MarkovBotChannelOnly(channel.Guild.Id))
                {
                    await socketChannel.SendMessageAsync(markov);
                }
                else if (channel.Id == UserSettings.Channels.BotChannelId(channel.Guild.Id))
                {
                    await socketChannel.SendMessageAsync(markov);
                }
            }

            return;
        }
コード例 #9
0
ファイル: InfoModule.cs プロジェクト: jpmac26/JackFrost-Bot
        public async Task Unmute([Summary("The user to unmute.")] SocketGuildUser mention)
        {
            if (Xml.CommandAllowed("unmute", Context))
            {
                await Context.Message.DeleteAsync();

                if (Moderation.IsModerator((IGuildUser)Context.Message.Author))
                {
                    Moderation.Unmute(Context.User.Username, (ITextChannel)Context.Channel, mention);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", Context.Guild.Id));
                }
            }
        }
コード例 #10
0
ファイル: InfoModule.cs プロジェクト: jpmac26/JackFrost-Bot
        public async Task Unlock()
        {
            if (Xml.CommandAllowed("unlock", Context))
            {
                await Context.Message.DeleteAsync();

                if (Moderation.IsModerator((IGuildUser)Context.Message.Author))
                {
                    Moderation.Unlock((SocketGuildUser)Context.User, (ITextChannel)Context.Channel);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", Context.Guild.Id));
                }
            }
        }
コード例 #11
0
ファイル: InfoModule.cs プロジェクト: jpmac26/JackFrost-Bot
        public async Task ClearWarn([Summary("The index of the warn to clear.")] int index, [Summary("The user whose warn to clear.")] SocketGuildUser mention = null)
        {
            if (Xml.CommandAllowed("clear warn", Context))
            {
                await Context.Message.DeleteAsync();

                if (Moderation.IsModerator((SocketGuildUser)Context.User))
                {
                    Moderation.ClearWarn((SocketGuildUser)Context.User, (ITextChannel)Context.Channel, Convert.ToInt32(index), mention);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", Context.Guild.Id));
                }
            }
        }
コード例 #12
0
ファイル: InfoModule.cs プロジェクト: jpmac26/JackFrost-Bot
        public async Task Redirect([Summary("The channel to move discussion to.")] ITextChannel channel)
        {
            if (Xml.CommandAllowed("redirect", Context))
            {
                await Context.Message.DeleteAsync();

                if (Moderation.IsModerator((IGuildUser)Context.Message.Author))
                {
                    await Context.Channel.SendMessageAsync($"Move this discussion to <#{channel.Id}>!");
                }
                else
                {
                    await Context.Channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", Context.Guild.Id));
                }
            }
        }
コード例 #13
0
ファイル: InfoModule.cs プロジェクト: jpmac26/JackFrost-Bot
        public async Task Kick([Summary("The user to kick.")] SocketGuildUser mention, [Summary("The reason for the kick."), Remainder] string reason = "No reason given.")
        {
            if (Xml.CommandAllowed("kick", Context))
            {
                await Context.Message.DeleteAsync();

                if (Moderation.IsModerator((IGuildUser)Context.Message.Author))
                {
                    Moderation.Kick(Context.User.Username, (ITextChannel)Context.Channel, mention, reason);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", Context.Guild.Id));
                }
            }
        }
コード例 #14
0
ファイル: InfoModule.cs プロジェクト: jpmac26/JackFrost-Bot
        public async Task PruneNonmembers()
        {
            if (Xml.CommandAllowed("prune nonmembers", Context))
            {
                await Context.Message.DeleteAsync();

                if (Moderation.IsModerator((IGuildUser)Context.Message.Author))
                {
                    var users = await Context.Guild.GetUsersAsync();

                    Moderation.PruneNonmembers((SocketGuildUser)Context.User, (ITextChannel)Context.Channel, users);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", Context.Guild.Id));
                }
            }
        }
コード例 #15
0
ファイル: Xml.cs プロジェクト: Tupelov/JackFrost-Bot
        public static bool CommandAllowed(string commandName, ICommandContext context)
        {
            ulong botChannelId  = UserSettings.Channels.BotChannelId(context.Guild.Id);
            bool  moderatorRole = Moderation.IsModerator((IGuildUser)context.Message.Author);

            UserSettings.Commands.Get(commandName, context.Guild.Id);

            if (UserSettings.Commands.enabled && !context.User.IsBot)
            {
                if ((UserSettings.Commands.botChannelOnly && (context.Channel.Id == botChannelId)) || !UserSettings.Commands.botChannelOnly)
                {
                    if (!UserSettings.Commands.moderatorsOnly || (UserSettings.Commands.moderatorsOnly && moderatorRole))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #16
0
ファイル: FrostForm.cs プロジェクト: Tupelov/JackFrost-Bot
        private void Btn_Go_Click(object sender, EventArgs e)
        {
            try
            {
                SocketGuild     guild   = guilds[selectedServer];
                ITextChannel    channel = guild.TextChannels.ToList()[selectedChannel];
                SocketGuildUser user    = guild.Users.ToList()[selectedMember];

                DialogResult dialogResult = MessageBox.Show($"Are you sure you want to {comboBox_Action.Items[comboBox_Action.SelectedIndex].ToString()} {user.Username}#{user.Discriminator} ({user.Nickname}) in #{channel.Name}?", "Verify Moderation Action", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    switch (comboBox_Action.SelectedIndex)
                    {
                    case 0:
                        Moderation.Warn(client.CurrentUser.Username, channel, user, txtBox_Reason.Text);
                        break;

                    case 1:
                        Moderation.Mute(client.CurrentUser.Username, channel, user);
                        break;

                    case 2:
                        Moderation.Kick(client.CurrentUser.Username, channel, user, txtBox_Reason.Text);
                        selectedMember = 0;
                        break;

                    case 3:
                        Moderation.Ban(client.CurrentUser.Username, channel, user, txtBox_Reason.Text);
                        selectedMember = 0;
                        break;

                    case 4:
                        Moderation.Unmute(client.CurrentUser.Username, channel, user);
                        break;
                    }
                    txtBox_Reason.Text = "";
                }
            }
            catch
            {
            }
            RefreshForm();
        }
コード例 #17
0
ファイル: InfoModule.cs プロジェクト: jpmac26/JackFrost-Bot
        public async Task Ban([Summary("The user to ban.")] SocketGuildUser mention, [Summary("The reason for the ban."), Remainder] string reason = "No reason given.")
        {
            if (Xml.CommandAllowed("ban", Context))
            {
                SocketGuildUser author = (SocketGuildUser)Context.Message.Author;

                //Check if a user is a moderator, then if the user has a role that enables them to ban other users using the bot
                await Context.Message.DeleteAsync();

                if (Moderation.IsModerator((IGuildUser)author))
                {
                    Moderation.Ban(Context.User.Username, (ITextChannel)Context.Channel, mention, reason);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", Context.Guild.Id));
                }
            }
        }
コード例 #18
0
ファイル: Processing.cs プロジェクト: jpmac26/JackFrost-Bot
        //Check if a message is filtered
        public static async Task FilterCheck(SocketMessage message, SocketGuildChannel channel)
        {
            if (Convert.ToBoolean(UserSettings.Filters.Enabled(channel.Guild.Id)))
            {
                foreach (string term in UserSettings.Filters.List(channel.Guild.Id))
                {
                    if (Regex.IsMatch(message.Content, string.Format(@"\b{0}\b|\b{0}d\b|\b{0}s\b|\b{0}ing\b|\b{0}ed\b|\b{0}er\b|\b{0}ers\b", Regex.Escape(term))))
                    {
                        string deleteReason = $"Message included a filtered term: {term}";

                        //Check if a message is clearly bypassing the filter, if so then warn
                        if (UserSettings.Filters.TermCausesWarn(term, channel.Guild.Id))
                        {
                            Moderation.Warn(channel.Guild.CurrentUser.Username, (ITextChannel)channel, (SocketGuildUser)message.Author, deleteReason);
                        }
                        await LogDeletedMessage(message, deleteReason);
                    }
                }
            }
        }
コード例 #19
0
ファイル: Processing.cs プロジェクト: jpmac26/JackFrost-Bot
        public static async Task MsgLengthCheck(SocketMessage message, SocketGuildChannel channel)
        {
            var user  = (IGuildUser)message.Author;
            var guild = user.Guild;

            if ((Moderation.IsModerator((IGuildUser)message.Author) == false) && (message.Author.IsBot == false))
            {
                //Delete Messages that are too short
                int minimum   = UserSettings.BotOptions.MinimumLength(channel.Guild.Id);
                int msgLength = message.Content.ToString().Trim(new char[] { ' ', '.' }).Length;
                if (message.Content.Length < minimum && message.Attachments.Count == 0)
                {
                    await LogDeletedMessage(message, $"Message was too short (minimum is {minimum})");
                }
                int minletters = UserSettings.BotOptions.MinimumLetters(channel.Guild.Id);
                //Delete messages that don't have enough alphanumeric characters
                if (message.Content.Count(char.IsLetterOrDigit) < minletters && message.Tags.Count <= 0 && !Regex.IsMatch(message.Content, @"\p{Cs}") && message.Attachments.Count <= 0)
                {
                    await LogDeletedMessage(message, $"Message didn't have enough letters (minimum is {minletters})");
                }
            }
        }
コード例 #20
0
ファイル: InfoModule.cs プロジェクト: jpmac26/JackFrost-Bot
        public async Task Redeem([Summary("The user to take from.")] SocketGuildUser mention, [Summary("The amount to take."), Remainder] int amount = 1)
        {
            var botlog = await Context.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(Context.Guild.Id));

            if (Xml.CommandAllowed("redeem", Context))
            {
                await Context.Message.DeleteAsync();

                if (Moderation.IsModerator((IGuildUser)Context.Message.Author))
                {
                    UserSettings.Currency.Remove(Context.Guild.Id, mention.Id, amount);
                    var embed = Embeds.LogRedeem((SocketGuildUser)Context.Message.Author, mention.Username, amount);
                    await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);

                    embed = Embeds.Redeem((SocketGuildUser)Context.Message.Author, mention.Username, amount);
                    await Context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", Context.Guild.Id));
                }
            }
        }
コード例 #21
0
ファイル: FrostForm.cs プロジェクト: Tupelov/JackFrost-Bot
        private void RadioButton_Unlocked_Click(object sender, EventArgs e)
        {
            SocketTextChannel channel = guilds[selectedServer].TextChannels.ToList()[selectedChannel];

            Moderation.Unlock(channel.Guild.CurrentUser, channel);
        }