Beispiel #1
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);
        }
        /// <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);
        }