示例#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
        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);
            }
        }
示例#3
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);
            }
        }