Exemplo n.º 1
0
        private async Task SendViewMessage(CommandEventArgs e, Func <IComponent, long, bool> predicate)
        {
            try
            {
                CommandsManager manager = new CommandsManager((long)e.Server.Id, predicate);

                string name = e.GetArg(CommandsConstants.ParameterModuleName);
                string view = String.IsNullOrEmpty(name) ? manager.CreateComponentsView(mBotModulesObserver.Modules) :
                              manager.CreateComponentsView(CommandsManager.FindModule(name, mBotModulesObserver.Modules));

                await SendStyleMessage(e.Channel, view, SettingsModuleResource.Css);
            }
            catch (ArgumentException exp)
            {
                await SendExceptonMessage(e.Channel, exp);
            }
        }
Exemplo n.º 2
0
        public async Task DeactivateModule(CommandEventArgs e)
        {
            try
            {
                IModule module = CommandsManager.FindModule(e.GetArg(CommandsConstants.ParameterModuleName), mBotModulesObserver.Modules);

                if (module.IsBlocked((long)e.Server.Id))
                {
                    await SendStyleMessage(e.Channel, SettingsModuleResource.ModuleAlreadyBlocked, SettingsModuleResource.Markdown);
                }
                else
                {
                    BlockedModuleService.Instance.Repository.Add(new BlockedModule {
                        ModuleName = module.Name, GuildId = (long)e.Server.Id
                    });
                    await SendStyleMessage(e.Channel, String.Format(SettingsModuleResource.ModuleBlocked, module.Name), SettingsModuleResource.Markdown);
                }
            }
            catch (ArgumentException exp)
            {
                await SendStyleMessage(e.Channel, exp.Message, SettingsModuleResource.Markdown);
            }
        }
Exemplo n.º 3
0
        public async Task ActivateModule(CommandEventArgs e)
        {
            try
            {
                IModule module = CommandsManager.FindModule(e.GetArg(CommandsConstants.ParameterModuleName), mBotModulesObserver.Modules);

                if (!module.IsBlocked((long)e.Server.Id))
                {
                    await SendStyleMessage(e.Channel, SettingsModuleResource.ModuleAlreadyUnblocked, SettingsModuleResource.Markdown);
                }
                else
                {
                    var blockedModuleId = BlockedModuleService.Instance.Repository.GetByName(module.Name, (long)e.Server.Id).Id;
                    BlockedModuleService.Instance.Repository.RemoveById(blockedModuleId);

                    await SendStyleMessage(e.Channel, String.Format(SettingsModuleResource.ModuleUnblocked, module.Name), SettingsModuleResource.Markdown);
                }
            }
            catch (ArgumentException exp)
            {
                await SendStyleMessage(e.Channel, exp.Message, SettingsModuleResource.Markdown);
            }
        }