Example #1
0
        public static async Task MassMentionCheck(SocketCommandContext context)
        {
            try
            {
                if (context.Message.MentionedUsers.Count > 8)
                {
                    SocketUser target = context.Message.Author;
                    await context.Message.DeleteAsync();

                    await DiscordContextSeymour.AddRole(DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted), target.Id);

                    await DiscordContextOverseer.LogModerationAction(target.Id, "Muted", "excessive pinging", Utilities.ShortTimeSpanFormatting(new TimeSpan(3, 0, 0, 0)));

                    await TimedEventManager.CreateEvent(DisciplinaryEventEnum.MuteEvent,
                                                        context.Client.CurrentUser.Id,
                                                        "excessive pinging",
                                                        target.Id,
                                                        target.Username,
                                                        (DateTimeOffset.UtcNow + new TimeSpan(0, 30, 0)).DateTime);

                    await TimedEventManager.CreateEvent(DisciplinaryEventEnum.WarnEvent, context.Client.CurrentUser.Id, "AutoWarn : excessive pinging", target.Id, target.Username, DateTime.UtcNow.AddDays(ConfigManager.GetIntegerProperty(PropertyItem.WarnDuration)));

                    if (context.Channel != null)
                    {
                        await DiscordContextOverseer.GetChannel(context.Channel.Id).SendMessageAsync($"{context.Message.Author.Mention}, Thou shall not say thy noble's names in vain. {DiscordContextSeymour.GetEmoteAyySeymour()}");
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException($"{typeof(AutoModeratorManager).GetType().FullName}: {ExceptionManager.GetAsyncMethodName()}", ex);
            }
        }
Example #2
0
        public static async Task CheckForWarnThreshold(SocketGuildUser target, SocketCommandContext context, int warnCount, ITextChannel chnl = null)
        {
            try
            {
                if (warnCount >= (ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns))) //more or equal the warn thresold
                {
                    await DiscordContextSeymour.AddRole(DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted), target.Id);

                    await DiscordContextOverseer.LogModerationAction(target.Id, "Muted", $"User has been warned {warnCount} times, exceeding the {ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns)} warn threshold", Utilities.ShortTimeSpanFormatting(new TimeSpan(1, 0, 0, 0)));

                    await TimedEventManager.CreateEvent(DisciplinaryEventEnum.MuteEvent,
                                                        context.Client.CurrentUser.Id,
                                                        $"User has been warned {warnCount} times, exceeding the {ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns)} warn threshold",
                                                        target.Id,
                                                        target.Username,
                                                        (DateTimeOffset.UtcNow + new TimeSpan(1, 0, 0, 0)).DateTime);

                    if (chnl == null)
                    {
                        await DiscordContextOverseer.GetChannel(context.Channel.Id).SendMessageAsync($"Silence. {target.Mention}");
                    }
                    else
                    {
                        await DiscordContextOverseer.GetChannel(chnl.Id).SendMessageAsync($"Silence. {target.Mention}");
                    }
                }
                else if (warnCount > (ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns) / 2)) //more than half the warn thresold
                {
                    await DiscordContextSeymour.AddRole(DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted), target.Id);

                    await DiscordContextOverseer.LogModerationAction(target.Id, "Muted", $"User has been warned {warnCount} times, exceeding half of the {ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns)} warn threshold", Utilities.ShortTimeSpanFormatting(new TimeSpan(0, 30, 0)));

                    await TimedEventManager.CreateEvent(DisciplinaryEventEnum.MuteEvent,
                                                        context.Client.CurrentUser.Id,
                                                        $"User has been warned {warnCount} times, exceeding half of the {ConfigManager.GetIntegerProperty(PropertyItem.MaxWarns)} warn threshold",
                                                        target.Id,
                                                        target.Username,
                                                        (DateTimeOffset.UtcNow + new TimeSpan(0, 30, 0)).DateTime);


                    if (chnl == null) //channel specified check
                    {
                        await DiscordContextOverseer.GetChannel(context.Channel.Id).SendMessageAsync($"{target.Mention}, enough.");
                    }
                    else
                    {
                        await DiscordContextOverseer.GetChannel(chnl.Id).SendMessageAsync($"{target.Mention}, enough.");
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.CheckForWarnThresholdException, ex);
            }
        }
Example #3
0
        public async Task WarnUserAsync(ulong userID, SocketGuildChannel chnl, [Remainder] string reason = "")
        {
            try
            {
                SocketGuildUser user    = Context.Guild.GetUser(userID);
                var             channel = chnl as ITextChannel;
                if (user == null)
                {
                    await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}");

                    return;
                }
                if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser))
                {
                    return;
                }

                UserDisciplinaryEventStorage obj = new UserDisciplinaryEventStorage()
                {
                    DateInserted         = DateTime.UtcNow,
                    DateToRemove         = DateTime.UtcNow.AddDays(ConfigManager.GetIntegerProperty(PropertyItem.WarnDuration)),
                    DiscipinaryEventType = DisciplinaryEventEnum.WarnEvent,
                    ModeratorID          = Context.Message.Author.Id,
                    Reason = reason,
                    UserID = user.Id
                };
                UserStorage newUser = new UserStorage()
                {
                    UserID   = user.Id,
                    UserName = user.Username
                };
                await TimedEventManager.CreateEvent(obj, newUser);

                int warnCount = await StorageManager.GetRecentWarningsAsync(user.Id);

                string maxWarns = ConfigManager.GetProperty(PropertyItem.MaxWarns);
                if (string.IsNullOrEmpty(reason))
                {
                    await channel.SendMessageAsync($"{user.Mention} {BotDialogs.WarnMessageNoReason}🚫\n{warnCount}/{maxWarns} warnings.");
                }
                else
                {
                    await channel.SendMessageAsync($"{user.Mention} {BotDialogs.WarnMessageReason} 🚫\n{warnCount}/{maxWarns} warnings.\n{reason}");
                }
                await AutoModeratorManager.CheckForWarnThreshold(user, Context, warnCount, channel);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.WarnException, ex);
            }
        }
Example #4
0
        private async Task MuteUserAsync(ulong userID, TimeSpan timeSpan, [Remainder] string reason = "no reason specified")
        {
            try
            {
                SocketGuildUser user = Context.Guild.GetUser(userID);
                if (user == null)
                {
                    await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}");

                    return;
                }

                if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser))
                {
                    return;
                }

                var mutedRole = DiscordContextSeymour.GrabRole(MordhauRoleEnum.Muted);
                await user.AddRoleAsync(mutedRole);

                UserDisciplinaryEventStorage newEvent = new UserDisciplinaryEventStorage()
                {
                    DateInserted         = DateTime.UtcNow,
                    DateToRemove         = (DateTimeOffset.UtcNow + timeSpan).DateTime,
                    DiscipinaryEventType = DisciplinaryEventEnum.MuteEvent,
                    ModeratorID          = Context.Message.Author.Id,
                    Reason = reason,
                    UserID = user.Id
                };
                UserStorage newUser = new UserStorage()
                {
                    UserID   = user.Id,
                    UserName = user.Username
                };

                bool existing = await TimedEventManager.CreateEvent(newEvent, newUser);

                await DiscordContextOverseer.LogModerationAction(userID, "Muted", Context.Message.Author.Id, reason, Utilities.ShortTimeSpanFormatting(timeSpan));

                var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.MuteEvent, timeSpan, reason, user.Username, existing);
                await DiscordContextSeymour.GetMainChannel().SendMessageAsync("", false, embed);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.MuteException, ex);
            }
        }
Example #5
0
        private async Task BanUserAsync(ulong userID, TimeSpan timeSpan, [Remainder] string reason = "no reason specified")
        {
            try
            {
                SocketGuildUser user = Context.Guild.GetUser(userID);
                if (user == null)
                {
                    await Context.Channel.SendMessageAsync($"Unable to locate user {DiscordContextSeymour.GetEmoteAyySeymour()}");

                    return;
                }
                string kickTargetName = user.Username;
                if (!await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser))
                {
                    await user.BanAsync(reason : reason);
                }
                else
                {
                    return;
                }

                var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.BanEvent, timeSpan, reason, kickTargetName, false);
                await Context.Channel.SendMessageAsync("", false, embed);

                UserDisciplinaryEventStorage obj = new UserDisciplinaryEventStorage()
                {
                    DateInserted         = DateTime.UtcNow,
                    DateToRemove         = (DateTimeOffset.UtcNow + timeSpan).DateTime,
                    DiscipinaryEventType = DisciplinaryEventEnum.BanEvent,
                    ModeratorID          = Context.Message.Author.Id,
                    Reason = reason,
                    UserID = Context.Message.Author.Id
                };
                UserStorage newUser = new UserStorage()
                {
                    UserID   = Context.Message.Author.Id,
                    UserName = Context.Message.Author.Username
                };

                await TimedEventManager.CreateEvent(obj, newUser);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.BanException, ex);
            }
        }
Example #6
0
        private async Task RestrictUserAsync(SocketGuildUser user, TimeSpan timeSpan, [Remainder] string reason = "no reason specified")
        {
            try
            {
                if (await DiscordContextSeymour.IsUserDevOrAdminAsync(user as SocketGuildUser))
                {
                    return;
                }

                var limitedRole = DiscordContextSeymour.GrabRole(MordhauRoleEnum.Restricted);
                await user.AddRoleAsync(limitedRole);

                UserDisciplinaryEventStorage newEvent = new UserDisciplinaryEventStorage()
                {
                    DateInserted         = DateTime.UtcNow,
                    DateToRemove         = (DateTimeOffset.UtcNow + timeSpan).DateTime,
                    DiscipinaryEventType = DisciplinaryEventEnum.RestrictedUserEvent,
                    ModeratorID          = Context.Message.Author.Id,
                    Reason = reason,
                    UserID = user.Id
                };
                UserStorage newUser = new UserStorage()
                {
                    UserID   = user.Id,
                    UserName = user.Username
                };

                bool existing = await TimedEventManager.CreateEvent(newEvent, newUser);

                var embed = Utilities.BuildDefaultEmbed(DisciplinaryEventEnum.RestrictedUserEvent, timeSpan, reason, user.Username, existing, Context.Message.Author.Username);
                await Context.Channel.SendMessageAsync("", false, embed);

                await DiscordContextOverseer.LogModerationAction(user.Id, "Restricted", Context.Message.Author.Id, reason, Utilities.ShortTimeSpanFormatting(timeSpan));
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.LimitException, ex);
            }
        }
Example #7
0
        public static async Task FilterMessage(SocketCommandContext context)
        {
            var splitContent = context.Message.Content.ToLower().Split();

            if (bannedRegex.Count > 0)
            {
                foreach (ModeratedElement element in bannedRegex)
                {
                    if (new Regex(element.Pattern).Match(context.Message.Content).Success)
                    {
                        await context.Message.DeleteAsync();

                        string reason;
                        if (element.Dialog.Length == 0)
                        {
                            reason = BotDialogs.DefaultRegexFilterMessage;
                        }
                        else
                        {
                            reason = element.Dialog;
                        }
                        await context.Channel.SendMessageAsync(context.User.Mention + ", " + reason);

                        await TimedEventManager.CreateEvent(DisciplinaryEventEnum.WarnEvent, context.Client.CurrentUser.Id, "AutoWarn : " + reason, context.Message.Author.Id, context.Message.Author.Username, DateTime.UtcNow.AddDays(ConfigManager.GetIntegerProperty(PropertyItem.WarnDuration)));
                        await CheckForWarnThreshold(context.Message.Author as SocketGuildUser, context, await StorageManager.GetRecentWarningsAsync(context.Message.Author.Id));

                        break;
                    }
                }
            }
            foreach (ModeratedElement element in bannedWords)
            {
                if (splitContent.Contains(element.Pattern.Trim()))
                {
                    string reason;
                    if (element.Dialog.Length == 0)
                    {
                        reason = "Do not use such disgusting language in my presence";
                    }
                    else
                    {
                        reason = element.Dialog;
                    }
                    await context.Channel.SendMessageAsync(context.User.Mention + ", " + reason);

                    await TimedEventManager.CreateEvent(DisciplinaryEventEnum.WarnEvent, context.Client.CurrentUser.Id, "AutoWarn : " + reason, context.Message.Author.Id, context.Message.Author.Username, DateTime.UtcNow.AddDays(ConfigManager.GetIntegerProperty(PropertyItem.WarnDuration)));
                    await CheckForWarnThreshold(context.Message.Author as SocketGuildUser, context, await StorageManager.GetRecentWarningsAsync(context.Message.Author.Id));


                    try
                    {
                        await context.Message.DeleteAsync();
                    }
                    catch (Exception ex)
                    {
                        await ExceptionManager.LogExceptionAsync(ex.Message);
                    }
                    break;
                }
            }
        }