Пример #1
0
 /// <summary>
 /// Is called when the command is triggered (case-insensitive).
 /// </summary>
 public abstract void Process(CmdTrigger <C> trigger);
Пример #2
0
 public string CreateInfo(CmdTrigger <C> trigger)
 {
     return(CreateUsage(trigger) + " (" + GetDescription(trigger) + ")");
     //return CreateUsage();
 }
Пример #3
0
 public string CreateUsage(CmdTrigger <C> trigger)
 {
     return(CreateUsage(GetParamInfo(trigger)));
 }
Пример #4
0
 public virtual string GetDescription(CmdTrigger <C> trigger)
 {
     return(EnglishDescription);
 }
Пример #5
0
 public virtual string GetParamInfo(CmdTrigger <C> trigger)
 {
     return(m_englishParamInfo);
 }
Пример #6
0
 public NestedCmdTrigger(CmdTrigger <C> trigger, C args)
     : this(trigger, args, trigger.Text)
 {
 }
Пример #7
0
 public override void Process(CmdTrigger <C> trigger)
 {
     m_Mgr.TriggerHelp(trigger, false);
 }
Пример #8
0
 public void DisplayCmd(CmdTrigger <C> trigger, BaseCommand <C> cmd)
 {
     DisplayCmd(trigger, cmd, false, true);
 }
Пример #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="filename"></param>
 /// <param name="trigger"></param>
 public virtual void ExecFile(string filename, CmdTrigger <C> trigger)
 {
     ExecFile(filename, trigger, null);
 }
Пример #10
0
 public bool MayDisplay(CmdTrigger <C> trigger, BaseCommand <C> cmd, bool ignoreRestrictions)
 {
     return(cmd.Enabled &&
            (ignoreRestrictions ||
             (cmd.RootCmd.MayTrigger(trigger, cmd, true) && TriggerValidator(trigger, cmd, true))));
 }
Пример #11
0
 /// <summary>
 /// Gives help
 /// TODO: Localization
 /// </summary>
 public void TriggerHelp(CmdTrigger <C> trigger)
 {
     TriggerHelp(trigger, false);
 }
Пример #12
0
 /// <summary>
 /// Lets the given CmdTrigger trigger the given Command.
 /// </summary>
 /// <param name="trigger"></param>
 /// <param name="cmd"></param>
 /// <param name="silentFail">Will not reply if it failed due to target restrictions or privileges etc</param>
 /// <returns></returns>
 public virtual object Eval(CmdTrigger <C> trigger, BaseCommand <C> cmd)
 {
     return(Eval(trigger, cmd, false));
 }
Пример #13
0
 public bool Trigger(CmdTrigger <C> trigger, BaseCommand <C> cmd)
 {
     return(Execute(trigger, cmd, false));
 }
Пример #14
0
 /// <summary>
 /// Determines whether the given command may ever be used in this Context, depending
 /// on the trigger's parameters that the triggerer cannot currently change and
 /// are not already checked globally by the TriggerValidator.
 /// </summary>
 public virtual bool MayTrigger(CmdTrigger <C> trigger, BaseCommand <C> cmd, bool silent)
 {
     return(true);
 }
Пример #15
0
 /// <summary>
 /// Processes a command that yields an object to return
 /// </summary>
 /// <param name="trigger"></param>
 /// <returns></returns>
 public virtual object Eval(CmdTrigger <C> trigger)
 {
     return(null);
 }
Пример #16
0
            public override void Process(CmdTrigger <C> trigger)
            {
                //var subAlias = trigger.Text.NextWord();

                //SubCommand subCmd;
                //if (m_subCommands.TryGetValue(subAlias, out subCmd))
                //{
                //    subCmd.Process(trigger);
                //}
                //else
                //{
                var txt = trigger.Text;

                if (!txt.HasNext)
                {
                    trigger.Reply("Invalid arguments - " + CreateInfo(trigger));
                }
                else
                {
                    IExecutable exec;
                    if (txt.ConsumeNext('-'))
                    {
                        if (!txt.HasNext)
                        {
                            trigger.Reply("Invalid arguments - " + CreateInfo(trigger));
                            return;
                        }

                        var c = txt.Remainder[0];
                        if (Char.ToLower(c) == 'l')
                        {
                            txt.Position++;
                            var matches = txt.Remainder.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            var toolMgr = ((CallCommand)RootCmd).ToolMgr;
                            trigger.Reply("Callable functions ({0}):", toolMgr.Executables.Count);
                            for (var i = 0; i < toolMgr.ExecutableList.Count; i++)
                            {
                                var executable = toolMgr.ExecutableList[i];
                                if (matches.Length != 0)
                                {
                                    var found = false;
                                    foreach (var match in matches)
                                    {
                                        if (executable.Name.IndexOf(match, StringComparison.InvariantCultureIgnoreCase) > -1)
                                        {
                                            // match
                                            found = true;
                                            break;
                                        }
                                    }
                                    if (!found)
                                    {
                                        continue;
                                    }
                                }
                                trigger.Reply(" {0}: {1}", i, executable);
                            }
                            return;
                        }

                        // specified index
                        var index = txt.NextUInt(uint.MaxValue);
                        if (index < ToolMgr.ExecutableList.Count)
                        {
                            exec = ToolMgr.ExecutableList[(int)index];
                        }
                        else
                        {
                            exec = null;
                        }
                    }
                    else
                    {
                        // name
                        var name = txt.NextWord();
                        exec = ToolMgr.Get(name);
                    }

                    if (exec == null)
                    {
                        trigger.Reply("Could not find specified Executable.");
                    }
                    else
                    {
                        var    len   = exec.ParameterTypes.Length;
                        var    args  = new object[len];
                        object value = null;
                        for (var i = 0; i < len; i++)
                        {
                            var paramType = exec.ParameterTypes[i];
                            var str       = (i == len - 1) ? txt.Remainder : txt.NextWord();                       // check for last argument
                            StringParser.Parse(str, paramType, ref value);
                            args[i] = value;
                        }
                        exec.Exec(args);
                    }

                    //base.Process(trigger);
                    //trigger.Reply("SubCommand not found: " + subAlias);
                    //trigger.Text.Skip(trigger.Text.Length);
                    //mgr.DisplayCmd(trigger, this, false);
                }
            }
Пример #17
0
 internal protected void FailNotify(CmdTrigger <C> trigger, Exception ex)
 {
     log.Warn(ex);
     OnFail(trigger, ex);
 }
Пример #18
0
            public override void Process(CmdTrigger <C> trigger)
            {
                StringStream text = trigger.Text;

                if (!text.HasNext)
                {
                    trigger.Reply("Invalid arguments - " + CreateInfo(trigger));
                }
                else
                {
                    IExecutable executable1;
                    if (text.ConsumeNext('-'))
                    {
                        if (!text.HasNext)
                        {
                            trigger.Reply("Invalid arguments - " + CreateInfo(trigger));
                            return;
                        }

                        if (char.ToLower(text.Remainder[0]) == 'l')
                        {
                            ++text.Position;
                            string[] strArray = text.Remainder.Split(new char[1]
                            {
                                ' '
                            }, StringSplitOptions.RemoveEmptyEntries);
                            ToolMgr toolMgr = ((CallCommand)RootCmd).ToolMgr;
                            trigger.Reply("Callable functions ({0}):", (object)toolMgr.Executables.Count);
                            for (int index = 0; index < toolMgr.ExecutableList.Count; ++index)
                            {
                                IExecutable executable2 = toolMgr.ExecutableList[index];
                                if (strArray.Length != 0)
                                {
                                    bool flag = false;
                                    foreach (string str in strArray)
                                    {
                                        if (executable2.Name.IndexOf(str, StringComparison.InvariantCultureIgnoreCase) >
                                            -1)
                                        {
                                            flag = true;
                                            break;
                                        }
                                    }

                                    if (!flag)
                                    {
                                        continue;
                                    }
                                }

                                trigger.Reply(" {0}: {1}", (object)index, (object)executable2);
                            }

                            return;
                        }

                        uint num = text.NextUInt(uint.MaxValue);
                        executable1 = (long)num >= (long)ToolMgr.ExecutableList.Count
              ? null
              : ToolMgr.ExecutableList[(int)num];
                    }
                    else
                    {
                        executable1 = ToolMgr.Get(text.NextWord());
                    }

                    if (executable1 == null)
                    {
                        trigger.Reply("Could not find specified Executable.");
                    }
                    else
                    {
                        int      length   = executable1.ParameterTypes.Length;
                        object[] objArray = new object[length];
                        object   obj      = null;
                        for (int index = 0; index < length; ++index)
                        {
                            Type parameterType = executable1.ParameterTypes[index];
                            StringParser.Parse(index == length - 1 ? text.Remainder : text.NextWord(), parameterType,
                                               ref obj);
                            objArray[index] = obj;
                        }

                        executable1.Exec(objArray);
                    }
                }
            }