示例#1
0
        private async Task AddCustomFilterAsync([Remainder] string words)
        {
            try
            {
                if (!words.Contains('|'))
                {
                    string cmdPrefix = ConfigManager.GetProperty(PropertyItem.CommandPrefix);
                    await Context.Channel.SendMessageAsync($"Invalid syntax - must be {cmdPrefix}addcustomfilter word | custom message when automoderated");
                }
                string pattern  = words.Substring(0, words.IndexOf('|')).Trim().ToLower();
                string message  = words.Substring(words.IndexOf('|') + 2).Trim();
                bool   existing = await AutoModeratorManager.AddBannedWordAsync(new ModeratedElement()
                {
                    Dialog = message, Pattern = pattern
                });

                if (existing)
                {
                    await Context.Channel.SendMessageAsync($"Succesfully added \"{pattern}\" as a banned word");
                }
                else
                {
                    await Context.Channel.SendMessageAsync($"\"{pattern}\" is an already existing banned word");
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.FilterException, ex);
            }
        }
示例#2
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);
            }
        }
示例#3
0
        private async Task AddMultipleFiltersAsync([Remainder] string words)
        {
            try
            {
                if (words.Contains(' '))
                {
                    string[] splitWords = words.Split(' ');
                    var      list       = new List <string>();
                    bool     existing;
                    string   wordsToAdd = "";

                    foreach (string splitword in splitWords)
                    {
                        wordsToAdd = splitword.ToLower().Trim();
                        existing   = await AutoModeratorManager.AddBannedWordAsync(new ModeratedElement()
                        {
                            Dialog = "", Pattern = wordsToAdd
                        });

                        if (existing)
                        {
                            list.Add(wordsToAdd);
                        }
                    }

                    if (list.Count > 0)
                    {
                        var succesfullyAddedWords = string.Join(", ", list.ToArray());
                        await Context.Channel.SendMessageAsync($"Succesfully added \"{succesfullyAddedWords}\" as a banned word");
                    }
                    else
                    {
                        await Context.Channel.SendMessageAsync($"Filters already exist for those words");
                    }
                }
                else
                {
                    await Context.Channel.SendMessageAsync($"Use {ConfigManager.GetProperty(PropertyItem.CommandPrefix)}addfilter for single filters.");
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.FilterException, ex);
            }
        }
示例#4
0
        private async Task RemoveFilterAsync(string name)
        {
            try
            {
                bool existing = await AutoModeratorManager.RemoveBannedWordAsync(name);

                if (existing)
                {
                    await Context.Channel.SendMessageAsync($"Succesfully removed \"{name}\" as a banned word");
                }
                else
                {
                    await Context.Channel.SendMessageAsync($"Was unable to locate \"{name}\" as a banned word");
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.FilterException, ex);
            }
        }
示例#5
0
        private async Task AddFilterAsync(string word)
        {
            try
            {
                bool existing = await AutoModeratorManager.AddBannedWordAsync(new ModeratedElement()
                {
                    Dialog = "", Pattern = word.ToLower().Trim()
                });

                if (existing)
                {
                    await Context.Channel.SendMessageAsync($"Succesfully added \"{word}\" as a banned word");
                }
                else
                {
                    await Context.Channel.SendMessageAsync($"\"{word}\" is an already existing banned word");
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.FilterException, ex);
            }
        }