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 void AttemptToStartGame(IChatClient chatClient, ChatUser chatUser) { if (_isRunningGame) { SendGameAlreadyStartedMessage(chatClient, chatUser); return; } if (!chatUser.CanUserRunCommand(ROLE_REQUIRE_TO_START)) { chatClient.SendMessage($"You must be at least a {ROLE_REQUIRE_TO_START} to start a game, {chatUser.DisplayName}"); return; } _isRunningGame = true; chatClient.SendMessage($"Totally starting this game. You word to guess is {MaskedPassword}"); }
private void AddNewStreamer(IChatClient chatClient, string channelName, ChatUser chatUser) { if (chatUser.CanUserRunCommand(UserRole.Mod)) { if (string.IsNullOrWhiteSpace(channelName)) { chatClient.SendMessage($"Please specify a valid channel name, @{chatUser.DisplayName}"); return; } // TODO: Prevent inserting same channel _repository.Create(new StreamerEntity { ChannelName = channelName }); chatClient.SendMessage($"Added {channelName} to our list of streams! Thanks, {chatUser.DisplayName} !"); } else { chatClient.SendMessage($"You aren't allowed to add new streams, @{chatUser.DisplayName}."); } }
private void AddNewQuote(IChatClient chatClient, string quoteText, string author, ChatUser chatUser) { if (!chatUser.CanUserRunCommand(UserRole.Mod)) { chatClient.SendMessage($"Please ask a moderator to add this quote, {chatUser.DisplayName}."); return; } int count = _repository.List(QuoteEntityPolicy.All).Count; var quoteEntity = new QuoteEntity { AddedBy = chatUser.DisplayName, Text = quoteText, Author = author, QuoteId = count + 1 }; QuoteEntity updatedEntity = _repository.Create(quoteEntity); chatClient.SendMessage($"Created quote # {updatedEntity.QuoteId}."); }
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(""); } }