public Task <Result> Execute(SocketUserMessage e, string name, object variable)
 {
     try {
         CommandVariables.Set(0, name, variable, false);
     } catch (ArgumentException exc) {
         return(TaskResult(exc.Message, exc.Message));
     }
     return(TaskResult(null, ""));
 }
Example #2
0
            public async Task <Result> Execute(SocketUserMessage e, params object[] arguments)
            {
                for (int i = 0; i < arguments.Length; i++)
                {
                    CommandVariables.Set(e.Id, "arg" + i, arguments [i], true);
                }
                Program.FoundCommandResult result = await Program.FindAndExecuteCommand(e, chain, Program.commands, 0, false, true);

                return(result.result);
            }
Example #3
0
            private async Task <System.Tuple <int, bool> > CalcY(SocketUserMessage e, string cmd, List <string> args, double x, double xscale, double yscale)
            {
                CommandVariables.Set(e.Id, "x", x, true);

                Program.FoundCommandResult result = await Program.FindAndExecuteCommand(e, cmd, args, Program.commands, 1, false, true);

                double y = (double)Convert.ChangeType(result.result.value, typeof(double));

                int ycur = (int)Math.Round(y / yscale) + Y_RES / 2;

                return(new System.Tuple <int, bool> (ycur, !double.IsNaN(y)));
            }
Example #4
0
 public async Task <Result> Execute(SocketUserMessage e, string varName, int amount, string command)
 {
     if (command.Length > 1 && command [1].IsTrigger())
     {
         string        cmd;
         List <string> args = Utility.ConstructArguments(GetParenthesesArgs(command), out cmd);
         for (int i = 0; i < amount; i++)
         {
             CommandVariables.Set(e.Id, varName, i, true);
             await Program.FindAndExecuteCommand(e, cmd.Substring(1), args, Program.commands, 1, false, true);
         }
     }
     return(new Result(null, ""));
 }
Example #5
0
            public async Task <Result> Execute(SocketUserMessage e, params string[] arguments)
            {
                for (int i = 0; i < arguments.Length; i++)
                {
                    CommandVariables.Set(e.Id, "arg" + i, arguments [i], true);
                }

                var result = await Program.FindAndExecuteCommand(e, chain, Program.commands, 0, true, true);

                if (result != null)
                {
                    return(result.result);
                }
                return(new Result("", null));
            }
Example #6
0
            public async Task <Result> Execute(SocketUserMessage e, string varName, string command, params object [] array)
            {
                string        outCmd;
                List <string> outArgs;

                if (TryIsolateWrappedCommand(command, out outCmd, out outArgs))
                {
                    foreach (object obj in array)
                    {
                        CommandVariables.Set(e.Id, varName, obj, true);
                        await Program.FindAndExecuteCommand(e, outCmd, outArgs, Program.commands, 1, false, false);
                    }
                }
                return(new Result(null, ""));
            }
Example #7
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);
        }
Example #8
0
        public async Task <List <object> > ConvertChainCommandsToObjects(SocketUserMessage e, List <object> input, int depth)
        {
            List <object> converted = new List <object> ();

            foreach (object obj in input)
            {
                object result    = obj;
                string stringObj = obj.ToString();

                if (stringObj.Length > 0)
                {
                    if (stringObj [0].IsTrigger())
                    {
                        Program.FoundCommandResult foundCommandResult = await Program.FindAndExecuteCommand(e, stringObj, Program.commands, depth + 1, false, true);

                        if (foundCommandResult.result != null)
                        {
                            result = foundCommandResult.result.value;
                        }
                    }
                    else if (stringObj [0] == '{')
                    {
                        int endIndex = stringObj.IndexOf('}');
                        if (endIndex != -1)
                        {
                            string varName = stringObj.Substring(1, endIndex - 1);
                            result = CommandVariables.Get(e.Id, varName);
                        }
                    }
                    else if (stringObj [0] == '<')
                    {
                        IMentionable mentionable = Utility.ConvertMentionToObject(stringObj);
                        result = mentionable;
                    }
                }

                converted.Add(result);
            }

            return(converted);
        }
 public Task <Result> Execute(SocketUserMessage e, string name)
 {
     return(TaskResult(CommandVariables.Delete(0, name), ""));
 }
 public Task <Result> Execute(SocketUserMessage e, string name)
 {
     return(TaskResult(CommandVariables.Get(e.Author.Id, name), ""));
 }