/// <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); }
void OnChannelCommandReceived(IBotChatChannel channel, StreamCommand command) { if (!ValidUser(command.Service, command.User)) { return; } string whispered = command.IsWhispered ? "(Whispered)" : ""; Logger.Info(this, $"{command.Service} - {whispered}{command.User}: !{command.Command} {string.Join(" ", command.Arguments)}"); ExecuteCommand(channel, command); }