示例#1
0
        public async Task FilterExclude(CommandContext ctx, string word)
        {
            if (ctx.Member.GetRole().IsSeniorModOrHigher())
            {
                await ctx.TriggerTypingAsync();

                // Cancels:
                if (FilterSystem.IsWord(word))
                {
                    await ctx.Channel.SendMessageAsync(
                        ChatObjects.GetErrMessage(@"Cannot add that word. It's a filter word..."));

                    return;
                }
                if (Excludes.IsExcluded(word))
                {
                    await ctx.Channel.SendMessageAsync(
                        ChatObjects.GetErrMessage(@"Cannot add that word. It's already excluded..."));

                    return;
                }

                Excludes.AddWord(word);
                Excludes.Save();

                await ctx.Channel.SendMessageAsync(
                    ChatObjects.GetSuccessMessage(
                        String.Format("I excluded the word {0}!", word)));
            }
        }
示例#2
0
        public async Task ExcludeBase(CommandContext ctx,
                                      string action,
                                      [RemainingText]
                                      string exclude = @"")
        {
            // Check if they have the permissions to call this command.
            if (await Permissions.HandlePermissionsCheck(ctx))
            {
                switch (action)
                {
                case "new":
                case "add":
                    if (!(await FilterSystem.HasItem(exclude)))
                    {       // The exclude doesn't exist already.
                        await FilterSystem.AddExclude(ctx, exclude);
                    }
                    else
                    {       // The exclude does exist.
                        await GenericResponses.SendGenericCommandError(
                            ctx.Channel,
                            ctx.Member.Mention,
                            "Unable to add exclude",
                            $"the provided exclude `{exclude}` exists already as an exclude or mask...");
                    }
                    break;

                case "remove":
                case "delete":
                    if ((await FilterSystem.HasExclude(exclude)))
                    {       // The exclude  exists.
                        await FilterSystem.RemoveExclude(ctx, exclude);
                    }
                    else
                    {       // The exclude doesn't exist.
                        await GenericResponses.SendGenericCommandError(
                            ctx.Channel,
                            ctx.Member.Mention,
                            "Unable to remove exclude",
                            $"the provided exclude `{exclude}` exists already...");
                    }
                    break;

                case "list":
                    await FilterSystem.ListExcludes(ctx);

                    break;

                default:
                    await GenericResponses.HandleInvalidArguments(ctx);

                    break;
                }
            }
        }
示例#3
0
        public async Task FilterBase(CommandContext ctx,
                                     string action,
                                     [RemainingText]
                                     string mask = @"")
        {
            // Check if they have the permissions to call this command.
            if (await Permissions.HandlePermissionsCheck(ctx))
            {
                switch (action)
                {
                case "new":
                case "add":
                    if (!(await FilterSystem.HasItem(mask)))
                    {       // The mask doesn't exist already.
                        await FilterSystem.AddMask(ctx, mask);
                    }
                    else
                    {       // The mask does exist.
                        await GenericResponses.SendGenericCommandError(
                            ctx.Channel,
                            ctx.Member.Mention,
                            "Unable to add mask",
                            $"the provided mask `{mask}` exists already as an exclude or mask...");
                    }
                    break;

                case "remove":
                case "delete":
                    if ((await FilterSystem.HasMask(mask)))
                    {       // The mask exists.
                        await FilterSystem.RemoveMask(ctx, mask);
                    }
                    else
                    {       // The mask doesn't exist.
                        await GenericResponses.SendGenericCommandError(
                            ctx.Channel,
                            ctx.Member.Mention,
                            "Unable to remove mask",
                            $"the provided mask `{mask}` does not exist...");
                    }
                    break;

                case "list":
                    await FilterSystem.ListMasks(ctx);

                    break;

                default:     // Invalid arguments.
                    await GenericResponses.HandleInvalidArguments(ctx);

                    break;
                }
            }
        }
示例#4
0
        public async Task RemoveFilterWords(CommandContext ctx, params string[] words)
        {
            // Check if the user can use commands.
            if (ctx.Member.GetRole().IsSeniorModOrHigher())
            {
                await ctx.TriggerTypingAsync();

                StringBuilder       sb_fail    = new StringBuilder(); // A list of words we haven't been able to add.
                StringBuilder       sb_success = new StringBuilder(); // A list of words we were able to add.
                DiscordEmbedBuilder deb;

                foreach (string word in words)
                {
                    // Check if this is already in the filter list. If it is not, we were unsuccessful at adding it to the list.
                    bool success = FilterSystem.IsWord(word);

                    if (success)
                    {
                        FilterSystem.RemoveWord(word);
                        sb_success.Append(word + @", ");
                    }
                    else
                    {
                        sb_fail.Append(word + @", ");
                    }
                }

                // DEB!
                deb = new DiscordEmbedBuilder()
                {
                    Description = ChatObjects.GetNeutralMessage(@"I attempted to remove those words you gave me."),
                    Color       = DiscordColor.LightGray
                };

                deb.WithThumbnailUrl(ChatObjects.URL_FILTER_SUB);

                // For each of these lists, we want to remove the last two characters, because every string will have an ", " at the end of it.
                if (sb_success.Length > 0)
                {
                    deb.AddField("Successfully removed:", sb_success.Remove(sb_success.Length - 2, 2).ToString());
                }
                if (sb_fail.Length > 0)
                {
                    deb.AddField("Not removed:", sb_fail.Remove(sb_fail.Length - 2, 2).ToString());
                }

                FilterSystem.Save();

                await ctx.Channel.SendMessageAsync(embed : deb.Build());
            }
        }
示例#5
0
        public async Task ListFilterWords(CommandContext ctx)
        {
            if (ctx.Member.GetRole().IsModOrHigher())
            {
                StringBuilder sb = new StringBuilder();

                foreach (string word in FilterSystem.GetWords())
                {
                    sb.AppendLine(word);
                }

                DiscordEmbedBuilder deb = new DiscordEmbedBuilder()
                {
                    Color        = DiscordColor.LightGray,
                    Description  = sb.ToString(),
                    Title        = "FILTER WORD LIST",
                    ThumbnailUrl = ChatObjects.URL_FILTER_GENERIC
                };

                await ctx.Channel.SendMessageAsync(embed : deb.Build());
            }
        }
示例#6
0
        private string LoadConfig()
        {
            string authKey = String.Empty;

            // Authkey
            Console.WriteLine(@"Loading bot config:");

            Console.Write("\tAuthkey");
            using (var fs = File.OpenRead(@"authkey"))
            {
                using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
                {
                    authKey = sr.ReadToEnd();
                }
            }

            if (authKey != String.Empty)
            {
                Console.WriteLine(@"... Loaded.");
            }

            // Bot settings

            Console.Write("\tSettings");

            if (BotSettings.CanLoad())
            {
                BotSettings.Load();
                Console.WriteLine("... Loaded!");
            }
            else
            {
                BotSettings.Default();
                Console.WriteLine("... Not found. Loading default values.");
            }

            Console.Write("\tReminders");

            if (ReminderSystem.CanLoad())
            {
                ReminderSystem.Load();
                Console.WriteLine("... Loaded!");
            }
            else
            {
                ReminderSystem.Default();
                Console.WriteLine("... Not found. Instantiating default values.");
            }

            Console.Write("\tBadwords");

            if (FilterSystem.CanLoad())
            {
                FilterSystem.Load();
                Console.WriteLine("... Loaded!");
            }
            else
            {
                FilterSystem.Default();
                Console.WriteLine("... Not found. Instantiating default values.");
            }

            Console.Write("\tExcludes");

            if (Excludes.CanLoad())
            {
                Excludes.Load();
                Console.WriteLine("... Loaded!");
            }
            else
            {
                Excludes.Default();
                Console.WriteLine("... Not found. Instantiating default values.");
            }

            return(authKey);
        }