Example #1
0
        private async Task ManageModule(IMessageChannel chan, string[] args, int enable)
        {
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Settings);

            if (!CanModify(Context.User, Context.Guild.OwnerId))
            {
                await ReplyAsync(Base.Sentences.OnlyOwnerStr(Context.Guild.Id, Context.Guild.OwnerId));

                return;
            }
            if (args.Length == 0)
            {
                await chan.SendMessageAsync(Sentences.ModuleManagementHelp(Context.Guild.Id) + " " + GetModuleList(Context.Guild.Id));

                return;
            }
            Program.Module?module = null;
            string         name   = Utilities.AddArgs(args).Replace(" ", "");

            if (name == "all") // Enable/Disable all modules at once
            {
                if (enable == 1 && Program.p.db.AreAllAvailable(Context.Guild.Id))
                {
                    await chan.SendMessageAsync(Sentences.AllModulesAlreadyEnabled(Context.Guild.Id));
                }
                else if (enable == 0 && Program.p.db.AreNoneAvailable(Context.Guild.Id))
                {
                    await chan.SendMessageAsync(Sentences.AllModulesAlreadyDisabled(Context.Guild.Id));
                }
                else
                {
                    for (Program.Module i = 0; i <= Program.Module.Youtube; i++)
                    {
                        // We can't disable Settings and Information module
                        // We however can enable them, just in case
                        if (enable == 0 && (i == Program.Module.Settings || i == Program.Module.Information))
                        {
                            continue;
                        }
                        await Program.p.db.SetAvailability(Context.Guild.Id, i, enable);
                    }
                    if (enable == 1)
                    {
                        await chan.SendMessageAsync(Sentences.AllModulesEnabled(Context.Guild.Id));
                    }
                    else
                    {
                        await chan.SendMessageAsync(Sentences.AllModulesDisabled(Context.Guild.Id));
                    }
                }
                return;
            }
            for (Program.Module i = 0; i <= Program.Module.Youtube; i++)
            {
                if (i == Program.Module.Settings || i == Program.Module.Information)
                {
                    continue;
                }
                if (i.ToString().ToLower() == name.ToLower())
                {
                    module = i;
                    break;
                }
            }
            if (module == null)
            {
                await chan.SendMessageAsync(Sentences.ModuleManagementInvalid(Context.Guild.Id) + " " + GetModuleList(Context.Guild.Id));

                return;
            }
            bool availability = Program.p.db.IsAvailable(Context.Guild.Id, module.Value);

            if (availability && enable == 1)
            {
                await chan.SendMessageAsync(Sentences.ModuleAlreadyEnabled(Context.Guild.Id, module.ToString()));
            }
            else if (!availability && enable == 0)
            {
                await chan.SendMessageAsync(Sentences.ModuleAlreadyDisabled(Context.Guild.Id, module.ToString()));
            }
            else
            {
                await Program.p.db.SetAvailability(Context.Guild.Id, module.Value, enable);

                if (enable == 1)
                {
                    await chan.SendMessageAsync(Sentences.ModuleEnabled(Context.Guild.Id, module.ToString()));
                }
                else
                {
                    await chan.SendMessageAsync(Sentences.ModuleDisabled(Context.Guild.Id, module.ToString()));
                }
            }
        }