コード例 #1
0
        /// <summary>
        /// executes a stream command received by a channel
        /// </summary>
        /// <param name="channel">channel the command was received from</param>
        /// <param name="command">received command</param>
        public void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            IStreamCommandHandler handler = commandmanager.GetCommandHandlerOrDefault(command.Command);

            if (handler == null)
            {
                channel.SendMessage($"Unknown command '{command.Command}', try '!commands' for a list of commands.");
            }
            else
            {
                if ((channel.Flags & handler.RequiredFlags) != handler.RequiredFlags)
                {
                    return;
                }

                try {
                    handler.ExecuteCommand(channel, command);
                }
                catch (StreamCommandException e) {
                    channel.SendMessage(e.Message);
                    if (e.ProvideHelp)
                    {
                        channel.SendMessage($"Try '!help {command.Command}' to get an idea how to use the command.");
                    }
                }
                catch (Exception e) {
                    Logger.Error(this, $"Error processing command '{command}'", e);
                    channel.SendMessage("Error processing command. You should probably inform the streamer that this tool is crap (also he can take a look at the logs what went wrong).");
                }
            }

            Command?.Invoke(command);
        }
コード例 #2
0
 /// <summary>
 /// adds a command handler to management
 /// </summary>
 /// <param name="command">command under which handler is to be added</param>
 /// <param name="handler">handler to be added</param>
 public void AddCommandHandler(string command, IStreamCommandHandler handler)
 {
     lock (commandhandlerlock)
     {
         if (commandhandlers.ContainsKey(command))
         {
             Logger.Warning(this, $"'{command}' already registered to '{commandhandlers[command].GetType().Name}'. Handler will be replaced by '{handler.GetType().Name}'");
         }
         commandhandlers[command] = handler;
     }
 }
コード例 #3
0
        public void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            string helpcommand = "help";

            if (command.Arguments.Length > 0)
            {
                helpcommand = command.Arguments[0];
            }

            IStreamCommandHandler handler = manager[helpcommand];

            if (handler == null)
            {
                channel.SendMessage($"@{command.User}: Unknown command '{helpcommand}', try !commands for a list of commands.");
            }
            else
            {
                handler.ProvideHelp(channel, command.User);
            }
        }
コード例 #4
0
 /// <summary>
 /// registers a command handler for a command
 /// </summary>
 /// <param name="command">command for which to register handler</param>
 /// <param name="handler">handler used to process commands</param>
 public void RegisterCommandHandler(string command, IStreamCommandHandler handler)
 {
     commandmanager.AddCommandHandler(command, handler);
 }