public override string TryToExecute(CommandReceivedEventArgs eventArgs) { string commandWord = eventArgs?.Arguments?.ElementAtOrDefault(1); ChatUser chatUser = eventArgs.ChatUser; try { if (!chatUser.IsInThisRoleOrHigher(UserRole.Mod)) { return("You need to be a moderator to delete a command."); } SimpleCommand command = _repository.Single(SimpleCommandPolicy.ByCommandText(commandWord)); if (command == null) { return($"I didn't find a !{commandWord} command."); } IBotCommand botCommand = _allCommands.SingleOrDefault(x => x.ShouldExecute(commandWord, out _)); if (botCommand != null) { _allCommands.Remove(botCommand); } _repository.Remove(command); return($"Removing the !{commandWord} command."); } catch (Exception e) { Console.WriteLine(e); return(""); } }
public void PerformDefaultTask(ChatUser chatUser, IChatClient chatClient) { if (_quizGame.IsRunning) { chatClient.SendMessage("A QuizGame is already being played."); } else if (chatUser.IsInThisRoleOrHigher(UserRole.Subscriber)) { _quizGame.StartGame(chatClient); chatClient.SendMessage($"{chatUser.DisplayName} is starting a new QuizGame!"); } else { chatClient.SendMessage($"Sorry, {chatUser.DisplayName}, you must be a subscriber to start a new QuizGame."); } }
public void AttemptToStartGame(IChatClient chatClient, ChatUser chatUser) { if (IsRunning) { SendGameAlreadyStartedMessage(chatClient, chatUser); return; } if (!chatUser.IsInThisRoleOrHigher(_hangmanSettings.RoleRequiredToStartGame)) { chatClient.SendMessage( $"You must be at least a {_hangmanSettings.RoleRequiredToStartGame} to start a game, {chatUser.DisplayName}"); return; } if (ALL_LETTERS == null) { chatClient.SendMessage("Couldn't start a new game, there are no allowed letters"); return; } var wordList = _repository.List <HangmanWord>().OrderBy(x => Guid.NewGuid()); foreach (var w in wordList) { char[] letters = w.Word.ToLowerInvariant().ToCharArray(); if (letters.All(l => ALL_LETTERS.ToLowerInvariant().Contains(l))) { Password = w.Word.ToLowerInvariant(); break; } } if (Password == null) { chatClient.SendMessage( "No words in the Hangman dictionary are compatible with the supported words"); } else { _hangmanDisplayNotification.HangmanStart(); chatClient.SendMessage($"Totally starting this game. Your word to guess is {MaskedPassword}"); IsRunning = true; } }
public Cooldown GetActiveCooldown(ChatUser chatUser, IBotCommand botCommand) { if (chatUser.IsInThisRoleOrHigher(UserRole.Mod) || botCommand.IsActiveGame()) { return(new NoCooldown()); } try { PurgeExpiredUserCommandCooldowns(DateTimeOffset.UtcNow); } catch (Exception e) { _loggerAdapter.LogError(e, "Failed to Purge Expried User Command Cooldowns"); } List <CommandUsage> global = GetUsagesByUserSubjectToCooldown(chatUser.DisplayName, DateTimeOffset.UtcNow); if (global != null && global.Any()) { if (!global.Any(x => x.WasUserWarned)) { global.ForEach(x => x.WasUserWarned = true); } return(new UserCooldown { Message = $"Whoa {chatUser.DisplayName}! Slow down there cowboy!" }); } List <CommandUsage> commandCooldown = GetByCommand(botCommand); if (commandCooldown != null && commandCooldown.Any()) { string timeRemaining = botCommand.GetCooldownTimeRemaining().ToExpandingString(); return(new CommandCooldown { Message = $"\"{botCommand.PrimaryCommandText}\" is currently on cooldown - Remaining time: {timeRemaining}" }); } // TODO: Check for UserCommandCooldown needed. return(new NoCooldown()); }
public override string TryToExecute(CommandReceivedEventArgs eventArgs) { if (_votingSystem.IsVoteActive) { return("There is already an active vote."); } ChatUser chatUser = eventArgs.ChatUser; if (chatUser.IsInThisRoleOrHigher(UserRole.Mod)) { List <string> newVoteArguments = eventArgs.Arguments.Skip(1).ToList(); return(_votingSystem.StartVote(newVoteArguments)); } else { return("You don't have permission to start a vote."); } }
public void AttemptToStartGame(IChatClient chatClient, ChatUser chatUser) { if (IsRunning) { SendGameAlreadyStartedMessage(chatClient, chatUser); return; } if (!chatUser.IsInThisRoleOrHigher(ROLE_REQUIRE_TO_START)) { chatClient.SendMessage( $"You must be at least a {ROLE_REQUIRE_TO_START} to start a game, {chatUser.DisplayName}"); return; } IsRunning = true; chatClient.SendMessage($"Totally starting this game. You word to guess is {MaskedPassword}"); }
public void AttemptToStartGame(IChatClient chatClient, ChatUser chatUser) { if (IsRunning) { SendGameAlreadyStartedMessage(chatClient, chatUser); return; } if (!chatUser.IsInThisRoleOrHigher(_hangmanSettings.RoleRequiredToStartGame)) { chatClient.SendMessage( $"You must be at least a {_hangmanSettings.RoleRequiredToStartGame} to start a game, {chatUser.DisplayName}"); return; } IsRunning = true; _hangmanDisplayNotification.HangmanStart(); chatClient.SendMessage($"Totally starting this game. You word to guess is {MaskedPassword}"); }
public void AttemptToCreateGame(IChatClient chatClient, ChatUser chatUser) { if (IsGameRunning) { return; } // role check here if (!chatUser.IsInThisRoleOrHigher(ROLE_REQUIRED_TO_START)) { chatClient.SendMessage($"Sorry, {chatUser.DisplayName}, but you're not experience enough (sub only) to organize a heist like this one..."); return; } // start the game IsGameRunning = true; SelectRandomHeist(); chatClient.SendMessage($"{chatUser.DisplayName} is organizing a {_selectedHeist.Name}. Type !heist or !heist [role] to join the team!"); ScheduleAutomatedActions(chatClient); }