Esempio n. 1
0
 public bool TryAnalysisReslut()
 {
     // 还没发送
     if (!IsSent)
     {
         return(false);
     }
     if ((DateTime.Now - SendTime).TotalMilliseconds > (Timeout != 0 ? Timeout : 3000))
     {
         if (CmdActions.ContainsKey(CmdKey))
         {
             ReadTime = DateTime.Now;
             Log.debug("告知" + CmdKey + "处理函数超时!");
             CmdActions[CmdKey](this);
         }
         return(true);
     }
     // 正确获得结果
     if (ResultString.StartsWith("TS->"))
     {
         ResultStringList.Add(ResultString);
         Log.shell(ResultString.Replace("\r", ""));
         ResultByte.Clear();
         IsRead = true;
         if (CmdActions.ContainsKey(CmdKey))
         {
             Log.debug("执行" + CmdKey + "的结果分析");
             CmdActions[CmdKey](this);
         }
         return(true);
     }
     return(false);
 }
Esempio n. 2
0
        /// <summary>
        /// Tries to execute the CommandAction in the CommandAction dictionary that matches the current parameter.
        /// Returns the succesfulness of the execution attempt.
        /// </summary>
        protected CmdResult RunCommand(string command = "")
        {
            // If command wasn't given, run current command
            if (command == "")
            {
                command = Message.Command;
            }
            try
            {
                if (CmdActions.Execute(command, Message.IsAdmin))
                {
                    return(CmdResult.Success);
                }
                else
                {
                    return(CmdResult.InvalidCommand);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine(ex);
                Console.WriteLine();

                return(CmdResult.Error);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Check if command is apart of this executor's dictionary.
 /// </summary>
 public bool IsCommand(string command)
 {
     if (CmdActions.ContainsKey(command))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 4
0
        protected CommandAction Admin(Action invocation, params string[] keys)
        {
            var command = new CommandAction(invocation, true);

            foreach (string key in keys)
            {
                CmdActions.Add(key, command);
            }
            return(command);
        }
Esempio n. 5
0
        /// <summary>
        /// Report all valid commands to the admin.
        /// </summary>
        protected void LogCommands()
        {
            string sender = Message.From.Username;

            Bot.Say(sender, "_________________________________________________________________");
            Bot.Say(sender, className + " -komponentin komennot.");
            Bot.Say(sender, " - ");
            foreach (var entry in CmdActions.Loggables())
            {
                Bot.Say(sender, entry.Key + " ||| " + entry.Value.Description);
            }
            Bot.Say(sender, "_________________________________________________________________");
        }
Esempio n. 6
0
        protected CommandAction[] Add(string desc, Action invocation, params string[] keys)
        {
            List <CommandAction> CommandActions = new List <CommandAction>();

            // Only the first key is marked as loggable. Variations are not logged.
            bool isFirst = true;

            foreach (string key in keys)
            {
                if (isFirst)
                {
                    CmdActions.Add(key, new CommandAction(invocation, desc, false));
                    CommandActions.Add(CmdActions[key]);
                }
                else
                {
                    CmdActions.Add(key, new CommandAction(invocation, false));
                    CommandActions.Add(CmdActions[key]);
                }
                isFirst = false;
            }

            return(CommandActions.ToArray());
        }