Example #1
0
        public static async Task <FoundCommandResult> FindAndExecuteCommand(SocketMessage e, string commandName, List <string> arguements, Command [] commandList, int depth, bool printMessage, bool allowQuickCommands)
        {
            for (int i = 0; i < commandList.Length; i++)
            {
                if (commandList [i].command == commandName)
                {
                    if (arguements.Count > 0 && arguements [0] == "?")
                    {
                        Command command = commandList [i];
                        if (command is CommandSet)
                        {
                            messageControl.SendMessage(e, command.GetHelp(e), command.allowInMain);
                        }
                        else
                        {
                            messageControl.SendEmbed(e.Channel, command.GetHelpEmbed(e, UserConfiguration.GetSetting <bool> (e.Author.Id, "AdvancedCommandsMode")));
                        }
                        return(null);
                    }
                    else
                    {
                        FoundCommandResult result = new FoundCommandResult(await commandList [i].TryExecute(e as SocketUserMessage, depth, arguements.ToArray()), commandList [i]);
                        if (result != null)
                        {
                            if (printMessage)
                            {
                                messageControl.SendMessage(e, result.result.message, result.command.allowInMain);
                            }

                            if (depth == 0)
                            {
                                CommandVariables.Clear(e.Id);
                            }

                            return(result);
                        }
                    }
                }
            }

            if (allowQuickCommands)
            {
                return(await FindAndExecuteCommand(e, commandName, arguements, quickCommands.ToArray(), depth, printMessage, false));
            }

            return(null);
        }