public async Task <string> ProcessMessageAsync(ChatMessage chatMessage) { string message = chatMessage.Message; if (!string.IsNullOrEmpty(message)) { string[] splitMessage = message.Split(null); BasicChatCommand command = basicCommands.FirstOrDefault(w => w.Command.ToLower().Equals(splitMessage[0].ToLower())); if (command != null) { if (chatMessage.IsModerator || chatMessage.IsBroadcaster) { if (splitMessage.Length > 1 && !command.IsLocked) { command.Value = string.Join(" ", splitMessage.Skip(1).Take(splitMessage.Length - 1)); } } string responseMessage = command.Value; SendMessage(responseMessage); return(responseMessage); } } return(string.Empty); }
public async Task <string> ProcessMessageAsync(ChatMessage chatMessage) { string message = chatMessage.Message; if (!string.IsNullOrEmpty(message)) { string[] splitMessage = message.Split(null); BasicChatCommand command = basicCommands.FirstOrDefault(w => w.Command.ToLower().Equals(splitMessage[0].ToLower())); if (command != null) { // Identify if there is a command cooldown and check its cooldown before proceeding. KeyValuePair <string, DateTime> commandCooldown = _commandCooldowns.FirstOrDefault(f => f.Key.Equals(command.Command, StringComparison.InvariantCultureIgnoreCase)); if (commandCooldown.Key != null && commandCooldown.Value.AddSeconds(command.ThrottleInSeconds) >= DateTime.Now) { return(string.Empty); } if (chatMessage.IsModerator || chatMessage.IsBroadcaster) { if (splitMessage.Length > 1 && !command.IsLocked) { command.Value = string.Join(" ", splitMessage.Skip(1).Take(splitMessage.Length - 1)); } } string responseMessage = command.Value; if (commandCooldown.Key != null) { _commandCooldowns[command.Command] = DateTime.Now; } else { _commandCooldowns.Add(command.Command, DateTime.Now); } SendMessage(responseMessage); return(responseMessage); } } return(string.Empty); }