Пример #1
0
        // 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.");
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        public async Task Warn([Summary("The user to warn.")] SocketGuildUser mention, [Summary("The reason for the warn."), Remainder] string reason = "No reason given.")
        {
            if (Xml.CommandAllowed("warn", Context))
            {
                await Context.Message.DeleteAsync();

                if (Moderation.IsModerator((IGuildUser)Context.Message.Author))
                {
                    Moderation.Warn(Context.User.Username, (ITextChannel)Context.Channel, mention, reason);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", Context.Guild.Id));
                }
            }
        }
Пример #3
0
        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();
        }
Пример #4
0
        //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);
                    }
                }
            }
        }