Example #1
0
        /// <summary>
        /// Execute command
        /// </summary>
        /// <param name="commandArguments">Command arguments</param>
        /// <returns>Command result</returns>
        public ECommandResult Execute(ICommandArguments commandArguments)
        {
            ECommandResult ret = ECommandResult.Failed;

            IModules[] modules_services = commandArguments.Bot.GetServices <IModules>();
            IChat[]    chat_services    = commandArguments.Bot.GetServices <IChat>();
            if ((modules_services != null) && (chat_services != null))
            {
                List <Embed> embeds = new List <Embed>();
                foreach (IModules modules in modules_services)
                {
                    EmbedBuilder embed_builder = PrepareEmbedBuilder();
                    foreach (IModule module in modules.LoadedModules.Values)
                    {
                        embed_builder.AddField(module.Name, "Version: " + module.Version + Environment.NewLine + "Author: " + module.Author + Environment.NewLine + "URI: " + module.URI);
                    }
                    embeds.Add(embed_builder.Build());
                }
                foreach (IChat chat in chat_services)
                {
                    if (chat != null)
                    {
                        foreach (Embed embed in embeds)
                        {
                            chat.SendEmbed(embed, commandArguments.MessageChannel);
                        }
                    }
                }
                embeds.Clear();
                ret = ECommandResult.Successful;
            }
            return(ret);
        }
Example #2
0
        /// <summary>
        /// Execute command
        /// </summary>
        /// <param name="commandArguments">Command arguments</param>
        /// <returns></returns>
        public ECommandResult Execute(ICommandArguments commandArguments)
        {
            ECommandResult ret = ECommandResult.Failed;

            if (commandArguments.Arguments.Count > 0)
            {
                string name = commandArguments.RawArguments;
                if (commandArguments.Bot.LoadedModules.ContainsKey(commandArguments.RawArguments))
                {
                    commandArguments.Bot.UnloadModuleAsync(commandArguments.Bot.LoadedModules[commandArguments.RawArguments]).GetAwaiter().GetResult();
                    ret = ECommandResult.Successful;
                    IChat[] chat_services = commandArguments.Bot.GetServices <IChat>();
                    if (chat_services != null)
                    {
                        foreach (IChat chat in chat_services)
                        {
                            if (chat != null)
                            {
                                chat.SendMessage("Module \"" + commandArguments.RawArguments + "\" has been successfully unloaded.", commandArguments.MessageChannel);
                            }
                        }
                    }
                }
            }
            return(ret);
        }
Example #3
0
        public SessionService(ICommandArguments commandArguments, IFilterService filterService)
        {
            this.commandArguments = commandArguments;
            this.filterService    = filterService;

            if (!this.IsSessionOpen())
            {
                this.Open();
            }
        }
Example #4
0
        /// <summary>
        /// Execute command
        /// </summary>
        /// <param name="commandArguments">Command arguments</param>
        /// <returns></returns>
        public ECommandResult Execute(ICommandArguments commandArguments)
        {
            ECommandResult ret = ECommandResult.Failed;

            if (commandArguments.Arguments.Count == 1)
            {
                CommandsConfiguration commands_configuration = commandArguments.Bot.GetService <CommandsConfiguration>();
                if (commands_configuration != null)
                {
                    string message = null;
                    string command = commandArguments.Arguments[0].Trim().ToLower();
                    CommandConfigurationData command_configuration_data = null;
                    if (commands_configuration.Data.Commands.ContainsKey(command))
                    {
                        command_configuration_data = commands_configuration.Data.Commands[command];
                        if (command_configuration_data == null)
                        {
                            command_configuration_data = new CommandConfigurationData();
                            commands_configuration.Data.Commands[command] = command_configuration_data;
                        }
                    }
                    else
                    {
                        command_configuration_data = new CommandConfigurationData();
                        commands_configuration.Data.Commands.Add(command, command_configuration_data);
                    }
                    if (command_configuration_data.Enabled)
                    {
                        command_configuration_data.Enabled = false;
                        commands_configuration.Save();
                        message = "Command \"" + command + "\" has been successfully disabled.";
                        ret     = ECommandResult.Successful;
                    }
                    else
                    {
                        message = "Command \"" + command + "\" is already disabled.";
                    }
                    if (message != null)
                    {
                        IChat[] chat_services = commandArguments.Bot.GetServices <IChat>();
                        if (chat_services != null)
                        {
                            foreach (IChat chat in chat_services)
                            {
                                if (chat != null)
                                {
                                    chat.SendMessage(message, commandArguments.MessageChannel);
                                }
                            }
                        }
                    }
                }
            }
            return(ret);
        }
Example #5
0
        public void Execute(object parameter)
        {
            args = parameter as ICommandArguments;
            if (args == null)
            {
                NotifyError(new Exception("Invalid arguments")); // TODO: declare explicit exception class
                return;
            }

            RunRequest(args.Uri);
        }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Engine"/> class.
 /// </summary>
 /// <param name="commandHandler">IHandler object.</param>
 /// <param name="commandArguments">ICommandArguments object.</param>
 /// <param name="inputReader">IInputReader object.</param>
 /// <param name="turnUpdater">IUpdateable object.</param>
 public Engine(
     IHandler<ICommandArguments> commandHandler, 
     ICommandArguments commandArguments,
     IInputReader inputReader, 
     IUpdateable turnUpdater)
 {
     this.commandHandler = commandHandler;
     this.commandArguments = commandArguments;
     this.inputReader = inputReader;
     this.turnUpdater = turnUpdater;
     this.isRunning = false;
 }
Example #7
0
        public Task Invoke(ICommandArguments arguments)
        {
            if (!arguments.TryGetString(out var tableName))
            {
                return(Task.CompletedTask);
            }

            if (!arguments.TryGetUint(out var entry))
            {
                return(Task.CompletedTask);
            }

            eventAggregator.GetEvent <EventRequestOpenItem>().Publish(new DatabaseTableSolutionItem(entry, true, tableName));
            return(Task.CompletedTask);
        }
Example #8
0
 /// <summary>
 /// Execute command
 /// </summary>
 /// <param name="commandArguments">Command arguments</param>
 /// <returns></returns>
 public ECommandResult Execute(ICommandArguments commandArguments)
 {
     IChat[] chat_services = commandArguments.Bot.GetServices <IChat>();
     if (chat_services != null)
     {
         foreach (IChat chat in chat_services)
         {
             if (chat != null)
             {
                 chat.SendMessage("Goodbye!", commandArguments.MessageChannel);
             }
         }
     }
     commandArguments.Bot.Exit();
     return(ECommandResult.Successful);
 }
Example #9
0
 /// <summary>
 /// Execute command
 /// </summary>
 /// <param name="commandArguments">Command arguments</param>
 /// <returns>Command result</returns>
 public ECommandResult Execute(ICommandArguments commandArguments)
 {
     // TODO
     IChat[] chat_services = commandArguments.Bot.GetServices <IChat>();
     if (chat_services != null)
     {
         foreach (IChat chat in chat_services)
         {
             if (chat != null)
             {
                 chat.SendMessage("This command has not been implemented yet.", commandArguments.MessageChannel);
             }
         }
     }
     return(ECommandResult.Successful);
 }
        public Task Invoke(ICommandArguments arguments)
        {
            if (!arguments.TryGetString(out var tableName))
            {
                return(Task.CompletedTask);
            }

            var definition = tableDefinitionProvider.GetDefinition(tableName);

            if (definition == null)
            {
                return(Task.CompletedTask);
            }

            if (definition.RecordMode == RecordMode.SingleRow)
            {
                eventAggregator.GetEvent <EventRequestOpenItem>().Publish(new DatabaseTableSolutionItem(definition.Id, definition.IgnoreEquality));

                if (!arguments.TryGetUint(out var entry_))
                {
                    return(Task.CompletedTask);
                }

                foreach (var doc in documentManager.Value.OpenedDocuments)
                {
                    if (doc is SingleRowDbTableEditorViewModel singleRow && singleRow.TableDefinition.Id == definition.Id)
                    {
                        var rest = arguments.TakeRestArguments;
                        return(singleRow.TryFind(new DatabaseKey(entry_), rest));
                    }
                }
                return(Task.CompletedTask);
            }

            if (!arguments.TryGetUint(out var entry))
            {
                return(Task.CompletedTask);
            }

            eventAggregator.GetEvent <EventRequestOpenItem>().Publish(new DatabaseTableSolutionItem(new DatabaseKey(entry), true, tableName, definition.IgnoreEquality));
            return(Task.CompletedTask);
        }
    public async Task Invoke(ICommandArguments arguments)
    {
        var query = arguments.TakeRestArguments;

        Console.WriteLine(query);

        var items = await queryParser.Value.GenerateItemsForQuery(query);

        foreach (var e in items.errors)
        {
            Console.WriteLine(e);
        }

        await mysqlExecutor.Value.ExecuteSql(query);

        foreach (var item in items.items)
        {
            await sessionService.Value.UpdateQuery(item);
        }
    }
Example #12
0
        /// <summary>
        /// Builds the container and register
        /// </summary>
        /// <param name="commandArguments">Command arguments.</param>
        public static void BuildContainer(ICommandArguments commandArguments)
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType <App>().As <IApp>().SingleInstance();
            containerBuilder.RegisterType <ResourceLoader>().As <IResourceLoader>();
            containerBuilder.RegisterType <SessionService>().As <ISessionService>().SingleInstance();
            containerBuilder.RegisterType <FilterService>().As <IFilterService>().SingleInstance();
            containerBuilder.RegisterInstance(commandArguments).As <ICommandArguments>().SingleInstance();
            containerBuilder.RegisterType <CommandDispatcher>().As <ICommandDispatcher>();
            containerBuilder.RegisterType <DomainCommand>().As <IDomainCommand>();
            containerBuilder.RegisterType <ParameterCommand>().As <IParameterCommand>();
            containerBuilder.RegisterType <StateCommand>().As <IStateCommand>();
            containerBuilder.RegisterType <SubscriptionCommand>().As <ISubscriptionCommand>();
            containerBuilder.RegisterType <ValueSetCommand>().As <IValueSetCommand>();
            containerBuilder.RegisterType <ScaleCommand>().As <IScaleCommand>();
            containerBuilder.RegisterType <OptionCommand>().As <IOptionCommand>();
            containerBuilder.RegisterType <ReportGenerator>().As <IReportGenerator>();
            Container = containerBuilder.Build();
        }
Example #13
0
        /// <summary>
        /// Execute command
        /// </summary>
        /// <param name="commandArguments">Command arguments</param>
        /// <returns>Command result</returns>
        public ECommandResult Execute(ICommandArguments commandArguments)
        {
            ECommandResult ret = ECommandResult.Failed;

            IChat[] chat_services = commandArguments.Bot.GetServices <IChat>();
            if (chat_services != null)
            {
                EmbedBuilder  embed_builder   = new EmbedBuilder();
                StringBuilder loaded_services = new StringBuilder();
                bool          first           = true;
                embed_builder.WithTitle(":tickets: Services");
                embed_builder.WithColor(Color.Red);
                foreach (object service in commandArguments.Bot.LoadedServices)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        loaded_services.Append(", ");
                    }
                    loaded_services.Append(service.GetType().FullName);
                }
                if (first)
                {
                    loaded_services.Append("No services found.");
                }
                embed_builder.AddField("Loaded services", loaded_services.ToString());
                Embed embed = embed_builder.Build();
                foreach (IChat chat in chat_services)
                {
                    if (chat != null)
                    {
                        chat.SendEmbed(embed, commandArguments.MessageChannel);
                    }
                }
                ret = ECommandResult.Successful;
            }
            return(ret);
        }
 /// <summary>
 /// Initialize a new CommandDispatcher
 /// </summary>
 /// <param name="commandArguments">the command line options</param>
 /// <param name="parameterCommand">the parameter command</param>
 /// <param name="subscriptionCommand">the subscription command</param>
 /// <param name="optionCommand">the option command</param>
 /// <param name="scaleCommand">the scale command</param>
 /// <param name="stateCommand">the state command</param>
 /// <param name="domainCommand">the domain command</param>
 /// <param name="valueSetCommand">the value set command</param>
 /// <param name="reportGenerator">the reportgernerator command</param>
 public CommandDispatcher(
     ICommandArguments commandArguments,
     IParameterCommand parameterCommand,
     ISubscriptionCommand subscriptionCommand,
     IOptionCommand optionCommand,
     IScaleCommand scaleCommand,
     IStateCommand stateCommand,
     IDomainCommand domainCommand,
     IValueSetCommand valueSetCommand,
     IReportGenerator reportGenerator)
 {
     this.commandArguments    = commandArguments;
     this.parameterCommand    = parameterCommand;
     this.subscriptionCommand = subscriptionCommand;
     this.optionCommand       = optionCommand;
     this.scaleCommand        = scaleCommand;
     this.stateCommand        = stateCommand;
     this.domainCommand       = domainCommand;
     this.valueSetCommand     = valueSetCommand;
     this.reportGenerator     = reportGenerator;
 }
Example #15
0
        /// <summary>
        /// Execute command
        /// </summary>
        /// <param name="commandArguments">Command arguments</param>
        /// <returns></returns>
        public ECommandResult Execute(ICommandArguments commandArguments)
        {
            ECommandResult ret = ECommandResult.Failed;

            if (commandArguments.Arguments.Count > 0)
            {
                string path = commandArguments.RawArguments;
                if (File.Exists(path))
                {
                    try
                    {
                        path = Path.GetFullPath(path);
                        IModule module = commandArguments.Bot.LoadModuleAsync(path).GetAwaiter().GetResult();
                        if (module != null)
                        {
                            module.InitAsync(commandArguments.Bot);
                            ret = ECommandResult.Successful;
                            IChat[] chat_services = commandArguments.Bot.GetServices <IChat>();
                            if (chat_services != null)
                            {
                                foreach (IChat chat in chat_services)
                                {
                                    if (chat != null)
                                    {
                                        chat.SendMessage("Module \"" + module.Name + "\" has been successfully loaded.", commandArguments.MessageChannel);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine(e);
                    }
                }
            }
            return(ret);
        }
 public Task <int> Execute(ICommandArguments arguments)
 {
     return(Task.FromResult(0));
 }
Example #17
0
        /// <summary>
        /// Execute command
        /// </summary>
        /// <param name="commandArguments">Command arguments</param>
        /// <returns>Command result</returns>
        public ECommandResult Execute(ICommandArguments commandArguments)
        {
            ECommandResult ret = ECommandResult.Failed;

            if (commandArguments.Arguments.Count == 5)
            {
                string global_guild_specifier = commandArguments.Arguments[0];
                string role_user_specifier    = commandArguments.Arguments[1];
                string role_user_id_string    = commandArguments.Arguments[2];
                string privilege    = commandArguments.Arguments[3];
                string level_string = commandArguments.Arguments[4];
                ulong  role_user_id;
                uint   level;
                if (ulong.TryParse(role_user_id_string, out role_user_id) && uint.TryParse(level_string, out level))
                {
                    IPrivileges[] privileges_services = commandArguments.Bot.GetServices <IPrivileges>();
                    IChat[]       chat_services       = commandArguments.Bot.GetServices <IChat>();
                    if (privileges_services != null)
                    {
                        switch (global_guild_specifier.ToLower())
                        {
                        case "global":
                            if (role_user_specifier.ToLower() == "user")
                            {
                                foreach (IPrivileges privileges in privileges_services)
                                {
                                    privileges.SetGlobalUserPrivilege(role_user_id, privilege, level);
                                    privileges.Save();
                                    foreach (IChat chat in chat_services)
                                    {
                                        if (chat != null)
                                        {
                                            if (level == 0U)
                                            {
                                                chat.SendMessage("Global privilege \"" + privilege + "\" has been removed from user \"" + role_user_id + "\".", commandArguments.MessageChannel);
                                            }
                                            else
                                            {
                                                chat.SendMessage("Global privilege \"" + privilege + "\" has been set to level \"" + level + "\" for user \"" + role_user_id + "\".", commandArguments.MessageChannel);
                                            }
                                        }
                                    }
                                    ret = ECommandResult.Successful;
                                }
                            }
                            break;

                        case "guild":
                            switch (role_user_specifier.ToLower())
                            {
                            case "role":
                                foreach (IPrivileges privileges in privileges_services)
                                {
                                    privileges.SetGuildRolePrivilege(((SocketGuildChannel)(commandArguments.MessageChannel)).Guild.Id, role_user_id, privilege, level);
                                    privileges.Save();
                                    foreach (IChat chat in chat_services)
                                    {
                                        if (chat != null)
                                        {
                                            if (level == 0U)
                                            {
                                                chat.SendMessage("Guild privilege \"" + privilege + "\" has been removed from role \"" + role_user_id + "\".", commandArguments.MessageChannel);
                                            }
                                            else
                                            {
                                                chat.SendMessage("Guild privilege \"" + privilege + "\" has been set to level \"" + level + "\" for role \"" + role_user_id + "\".", commandArguments.MessageChannel);
                                            }
                                        }
                                    }
                                }
                                break;

                            case "user":
                                foreach (IPrivileges privileges in privileges_services)
                                {
                                    privileges.SetGuildUserPrivilege(((SocketGuildChannel)(commandArguments.MessageChannel)).Guild.Id, role_user_id, privilege, level);
                                    privileges.Save();
                                    foreach (IChat chat in chat_services)
                                    {
                                        if (chat != null)
                                        {
                                            if (level == 0U)
                                            {
                                                chat.SendMessage("Guild privilege \"" + privilege + "\" has been removed from user \"" + role_user_id + "\".", commandArguments.MessageChannel);
                                            }
                                            else
                                            {
                                                chat.SendMessage("Guild privilege \"" + privilege + "\" has been set to level \"" + level + "\" for user \"" + role_user_id + "\".", commandArguments.MessageChannel);
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                            break;
                        }
                    }
                }
            }
            return(ret);
        }
Example #18
0
 /// <summary>
 /// Empty constructor used for test purpose
 /// </summary>
 public SessionService(ICommandArguments commandArguments, IFilterService filterService, ISession session)
 {
     this.commandArguments = commandArguments;
     this.filterService    = filterService;
     this.Session          = session;
 }
 /// <summary>
 /// Initialise a new <see cref="ParameterCommand" />
 /// </summary>
 /// <param name="commandArguments">the <see cref="ICommandArguments" /> arguments instance</param>
 /// <param name="sessionService">
 /// the <see cref="ISessionService" /> providing the <see cref="ISession" /> for the
 /// application
 /// </param>
 /// <param name="filterService">the <see cref="IFilterService" /></param>
 public ParameterCommand(ICommandArguments commandArguments, ISessionService sessionService, IFilterService filterService)
 {
     this.commandArguments = commandArguments;
     this.sessionService   = sessionService;
     this.filterService    = filterService;
 }
Example #20
0
 public Task <int> Execute(ICommandArguments arguments)
 => Execute((T)arguments);
Example #21
0
 public Command(Command source)
 {
     binder = source.binder;
     rest = source.rest;
     args = source.args;
 }
Example #22
0
        /// <summary>
        /// Execute command
        /// </summary>
        /// <param name="commandArguments">Command arguments</param>
        /// <returns>Command result</returns>
        public ECommandResult Execute(ICommandArguments commandArguments)
        {
            ECommandResult ret = ECommandResult.Failed;

            ICommands[]       commands_services  = commandArguments.Bot.GetServices <ICommands>();
            IChat[]           chat_services      = commandArguments.Bot.GetServices <IChat>();
            HelpConfiguration help_configuration = commandArguments.Bot.GetService <HelpConfiguration>();

            if ((commands_services != null) && (chat_services != null) && (help_configuration != null))
            {
                List <Embed> embeds = new List <Embed>();
                if (commandArguments.Arguments.Count > 0)
                {
                    string command_string = commandArguments.Arguments[0];
                    List <KeyValuePair <ICommands, ICommand> > command_list = new List <KeyValuePair <ICommands, ICommand> >();
                    foreach (ICommands commands in commands_services)
                    {
                        ICommand command = commands.FindCommand(command_string);
                        if (command != null)
                        {
                            command_list.Add(new KeyValuePair <ICommands, ICommand>(commands, command));
                        }
                    }
                    if (command_list.Count > 0)
                    {
                        foreach (KeyValuePair <ICommands, ICommand> command in command_list)
                        {
                            EmbedBuilder embed_builder = PrepareEmbedBuilder("Help topic for command \"" + command.Value.Name + "\"");
                            embed_builder.AddField("Command", command.Value.Name, true);
                            embed_builder.AddField("Description", command.Value.Description, true);
                            embed_builder.AddField("Full description", command.Value.FullDescription);
                            StringBuilder required_privileges = new StringBuilder();
                            foreach (KeyValuePair <string, uint> privilege in command.Value.ForceRequiredPrivileges)
                            {
                                required_privileges.Append("\"");
                                required_privileges.Append(privilege.Key);
                                required_privileges.Append("\" : ");
                                required_privileges.Append(privilege.Value.ToString());
                            }
                            if (required_privileges.Length > 0)
                            {
                                embed_builder.AddField("Required privileges", required_privileges);
                            }
                            ICommandGroup command_group = command.Key.GetCommandGroup(command.Value.CommandGroup);
                            if (command_group != null)
                            {
                                StringBuilder more_commands = new StringBuilder();
                                bool          first         = true;
                                foreach (ICommand command_group_command in command.Key.FromCommandGroup(command_group))
                                {
                                    if (first)
                                    {
                                        first = false;
                                    }
                                    else
                                    {
                                        more_commands.Append(", ");
                                    }
                                    more_commands.Append(command_group_command.Name);
                                }
                                if (first)
                                {
                                    more_commands.Append("No commands?");
                                }
                                embed_builder.AddField("More commands " + command_group.Icon, more_commands.ToString());
                            }
                            embeds.Add(embed_builder.Build());
                        }
                    }
                    else
                    {
                        List <KeyValuePair <ICommands, ICommandGroup> > command_group_list = new List <KeyValuePair <ICommands, ICommandGroup> >();
                        string command_group_name_key = commandArguments.Arguments[0].Trim().ToLower();
                        foreach (ICommands commands in commands_services)
                        {
                            ICommandGroup command_group = commands.GetCommandGroup(command_string);
                            if (command_group != null)
                            {
                                if (command_group.Name.Trim().ToLower() == command_group_name_key)
                                {
                                    command_group_list.Add(new KeyValuePair <ICommands, ICommandGroup>(commands, command_group));
                                }
                            }
                        }
                        if (command_group_list.Count > 0)
                        {
                            foreach (KeyValuePair <ICommands, ICommandGroup> command_group in command_group_list)
                            {
                                EmbedBuilder  embed_builder          = PrepareEmbedBuilder("Help topic for command group \"" + command_group.Value.Icon + " " + command_group.Value.Name + "\"");
                                StringBuilder command_group_commands = new StringBuilder();
                                bool          first = true;
                                foreach (ICommand command_group_command in command_group.Key.FromCommandGroup(command_group.Value))
                                {
                                    if (first)
                                    {
                                        first = false;
                                    }
                                    else
                                    {
                                        command_group_commands.Append(", ");
                                    }
                                    command_group_commands.Append(command_group_command.Name);
                                }
                                if (first)
                                {
                                    command_group_commands.Append("No commands?");
                                }
                                embed_builder.AddField("Commands", command_group_commands.ToString());
                                command_group_commands.Clear();
                                embeds.Add(embed_builder.Build());
                            }
                        }
                        else
                        {
                            foreach (ICommands commands in commands_services)
                            {
                                EmbedBuilder embed_builder = PrepareEmbedBuilder();
                                embed_builder.WithTitle("Help topics similar to \"" + command_string + "\"");
                                StringBuilder all_commands_groups = new StringBuilder();
                                bool          first = true;
                                foreach (ICommand command in commands.AvailableCommands)
                                {
                                    if (Levenshtein.GetDistance(command_string, command.Name) <= help_configuration.Data.MaximumLevenshteinDistance)
                                    {
                                        if (first)
                                        {
                                            first = false;
                                        }
                                        else
                                        {
                                            all_commands_groups.Append(", ");
                                        }
                                        all_commands_groups.Append(command.Name);
                                    }
                                }
                                if (first)
                                {
                                    all_commands_groups.Append("No similar commands found");
                                }
                                embed_builder.AddField("Commands", all_commands_groups.ToString());
                                all_commands_groups.Clear();
                                first = true;
                                foreach (ICommandGroup command_group in commands.AvailableCommandGroups)
                                {
                                    if (Levenshtein.GetDistance(command_string, command_group.Name) <= help_configuration.Data.MaximumLevenshteinDistance)
                                    {
                                        if (first)
                                        {
                                            first = false;
                                        }
                                        else
                                        {
                                            all_commands_groups.Append(", ");
                                        }
                                        all_commands_groups.Append(command_group.Icon);
                                        all_commands_groups.Append(" ");
                                        all_commands_groups.Append(command_group.Name);
                                    }
                                }
                                if (first)
                                {
                                    all_commands_groups.Append("No similar command groups found");
                                }
                                embed_builder.AddField("Command groups", all_commands_groups.ToString());
                                embeds.Add(embed_builder.Build());
                            }
                        }
                        command_group_list.Clear();
                    }
                    command_list.Clear();
                }
                else
                {
                    foreach (ICommands commands in commands_services)
                    {
                        EmbedBuilder  embed_builder          = PrepareEmbedBuilder("Help topics");
                        StringBuilder command_group_commands = new StringBuilder();
                        foreach (ICommandGroup command_group in commands.AvailableCommandGroups)
                        {
                            bool first = true;
                            command_group_commands.Clear();
                            foreach (ICommand command_group_command in commands.FromCommandGroup(command_group))
                            {
                                if (first)
                                {
                                    first = false;
                                }
                                else
                                {
                                    command_group_commands.Append(", ");
                                }
                                command_group_commands.Append(command_group_command.Name);
                            }
                            if (first)
                            {
                                command_group_commands.Append("No commands specified yet.");
                            }
                            embed_builder.AddField(command_group.Icon + " " + command_group.Name, command_group_commands.ToString());
                        }
                        embeds.Add(embed_builder.Build());
                    }
                }
                foreach (IChat chat in chat_services)
                {
                    foreach (Embed embed in embeds)
                    {
                        chat.SendEmbedAsync(embed, commandArguments.MessageChannel);
                    }
                }
                embeds.Clear();
                ret = ECommandResult.Successful;
            }
            return(ret);
        }
Example #23
0
 public void SetArguments(ICommandArguments arguments)
 {
     Arguments = (TArgs)arguments;
 }
Example #24
0
 /// <summary>
 /// Initialise a new <see cref="SubscriptionCommand" />
 /// </summary>
 /// <param name="commandArguments">the <see cref="ICommandArguments" /> arguments instance</param>
 /// <param name="sessionService">
 /// the <see cref="ISessionService" /> providing the <see cref="CDP4Dal.ISession" /> for the
 /// application
 /// </param>
 /// <param name="filterService">the <see cref="IFilterService" /></param>
 public SubscriptionCommand(ICommandArguments commandArguments, ISessionService sessionService, IFilterService filterService)
 {
     this.commandArguments = commandArguments;
     this.sessionService   = sessionService;
     this.filterService    = filterService;
 }
Example #25
0
 public PretzelCommandHandler(IConfiguration configuration, ICommandArguments commandParameters, ExportFactory <ICommand, CommandInfoAttribute> command)
 {
     Configuration    = configuration;
     CommandArguments = commandParameters;
     Command          = command;
 }
Example #26
0
 /// <summary>
 /// Initialises a new instance of the <see cref="FilterService" /> class.
 /// </summary>
 /// <param name="commandArguments">The command arguments</param>
 public FilterService(ICommandArguments commandArguments)
 {
     this.commandArguments = commandArguments;
 }
Example #27
0
        /// <summary>
        /// Execute command
        /// </summary>
        /// <param name="commandArguments">Command arguments</param>
        /// <returns>Command result</returns>
        public ECommandResult Execute(ICommandArguments commandArguments)
        {
            ECommandResult ret = ECommandResult.Failed;

            if (commandArguments.Arguments.Count == 3)
            {
                string command   = commandArguments.Arguments[0].Trim().ToLower();
                string privilege = commandArguments.Arguments[1];
                uint   level;
                if (uint.TryParse(commandArguments.Arguments[2], out level))
                {
                    CommandsConfiguration commands_configuration = commandArguments.Bot.GetService <CommandsConfiguration>();
                    if (commands_configuration != null)
                    {
                        string message = null;
                        CommandConfigurationData command_configuration_data = null;
                        if (commands_configuration.Data.Commands.ContainsKey(command))
                        {
                            command_configuration_data = commands_configuration.Data.Commands[command];
                            if (command_configuration_data == null)
                            {
                                command_configuration_data = new CommandConfigurationData();
                                commands_configuration.Data.Commands[command] = command_configuration_data;
                            }
                        }
                        else
                        {
                            command_configuration_data = new CommandConfigurationData();
                            commands_configuration.Data.Commands.Add(command, command_configuration_data);
                        }
                        if (level == 0U)
                        {
                            if (command_configuration_data.Privileges.ContainsKey(privilege))
                            {
                                command_configuration_data.Privileges.Remove(privilege);
                                commands_configuration.Save();
                                message = "Privilege requirement \"" + privilege + "\" for \"" + command + "\" has been successfully removed.";
                                ret     = ECommandResult.Successful;
                            }
                            else
                            {
                                message = "Privilege requirement \"" + privilege + "\" doesn't exist for \"" + command + "\".";
                            }
                        }
                        else
                        {
                            if (command_configuration_data.Privileges.ContainsKey(privilege))
                            {
                                command_configuration_data.Privileges[privilege] = level;
                                commands_configuration.Save();
                                message = "Privilege requirement \"" + privilege + "\" for \"" + command + "\" has been successfully updated to level " + level + ".";
                            }
                            else
                            {
                                command_configuration_data.Privileges.Add(privilege, level);
                                commands_configuration.Save();
                                message = "Privilege requirement \"" + privilege + "\" for \"" + command + "\" has been successfully set to level " + level + ".";
                            }
                            ret = ECommandResult.Successful;
                        }
                        if (message != null)
                        {
                            IChat[] chat_services = commandArguments.Bot.GetServices <IChat>();
                            if (chat_services != null)
                            {
                                foreach (IChat chat in chat_services)
                                {
                                    if (chat != null)
                                    {
                                        chat.SendMessage(message, commandArguments.MessageChannel);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(ret);
        }