public override string TryToExecute(CommandReceivedEventArgs eventArgs) { string commandWord = eventArgs?.Arguments?.ElementAtOrDefault(1); ChatUser chatUser = eventArgs.ChatUser; try { if (!chatUser.CanUserRunCommand(UserRole.Mod)) { return("You need to be a moderator to delete a command."); } SimpleCommand command = _repository.Single(CommandPolicy.ByCommandText(commandWord)); if (command == null) { return($"I didn't find a !{commandWord} command."); } IBotCommand botCommand = _allCommands.SingleOrDefault(x => x.ShouldExecute(commandWord)); if (botCommand != null) { _allCommands.Remove(botCommand); } _repository.Remove(command); return($"Removing the !{commandWord} command."); } catch (Exception e) { Console.WriteLine(e); return(""); } }
public override void Process(IChatClient chatClient, CommandReceivedEventArgs eventArgs) { try { // !RemoveCommand Twitter string commandText = eventArgs.Arguments?[0]; SimpleCommand command = _repository.Single(CommandPolicy.ByCommandText(commandText)); if (command == null) { chatClient.SendMessage($"I didn't find a !{commandText} command."); } chatClient.SendMessage($"Removing the !{commandText} command."); _repository.Remove(command); IBotCommand botCommand = _allCommands.SingleOrDefault(x => x.CommandText.Equals(commandText)); if (botCommand != null) { _allCommands.Remove(botCommand); } } catch (Exception e) { Console.WriteLine(e); } }
public override void Process(IChatClient chatClient, CommandReceivedEventArgs eventArgs) { try { // !AddCommand Twitter "https://twitter.com/DevChatter_" Everyone SimpleCommand command = eventArgs.Arguments.ToSimpleCommand(); if (command == null) { chatClient.SendMessage("Failed to create command."); chatClient.SendMessage(HelpText); return; } if (_repository.Single(CommandPolicy.ByCommandText(command.CommandText)) != null) { chatClient.SendMessage($"There's already a command using !{command.CommandText}"); return; } chatClient.SendMessage($"Adding a !{command.CommandText} command for {command.RoleRequired}. It will respond with {command.StaticResponse}."); _repository.Create(command); _allCommands.Add(command); } catch (Exception e) { Console.WriteLine(e); } }
public override string TryToExecute(CommandReceivedEventArgs eventArgs) { string commandWord = eventArgs?.Arguments?.ElementAtOrDefault(1); string staticResponse = eventArgs?.Arguments?.ElementAtOrDefault(2); string roleText = eventArgs?.Arguments?.ElementAtOrDefault(3); ChatUser chatUser = eventArgs.ChatUser; try { if (!chatUser.CanUserRunCommand(UserRole.Mod)) { return("You need to be a moderator to add a command."); } if (!Enum.TryParse(roleText, true, out UserRole role)) { role = UserRole.Everyone; } SimpleCommand command = new SimpleCommand(commandWord, staticResponse, role); if (_repository.Single(CommandPolicy.ByCommandText(command.CommandText)) != null) { return($"There's already a command using !{command.CommandText}"); } _repository.Create(command); _allCommands.Add(command); return($"Adding a !{command.CommandText} command for {command.RoleRequired}. It will respond with {command.StaticResponse}."); } catch (Exception e) { Console.WriteLine(e); return(""); } }