public override void ExecuteCommand(EvtChatCommandArgs args) { string username = args.Command.ChatMessage.Username.ToLowerInvariant(); GroupBetRoutine groupBetRoutine = RoutineHandler.FindRoutine <GroupBetRoutine>(); if (groupBetRoutine == null || groupBetRoutine.TryGetParticipant(username, out GroupBetRoutine.ParticipantData participantData) == false) { QueueMessage("You're not in the group bet!"); return; } groupBetRoutine.RemoveParticipant(username); string creditsName = DataHelper.GetCreditsName(); QueueMessage($"{username} has backed out of the group bet and retained their {participantData.ParticipantBet} {creditsName.Pluralize(false, participantData.ParticipantBet)}!"); int participantCount = groupBetRoutine.ParticipantCount; int minParticipants = groupBetRoutine.MinParticipants; //Check for ending the group bet if there are no longer enough participants if (participantCount < minParticipants) { //If no one is in the group bet, end it entirely if (participantCount == 0) { RoutineHandler.RemoveRoutine(groupBetRoutine); } QueueMessage($"Oh no! The group bet has ended since there are no longer enough participants. {minParticipants - participantCount} more is/are required to start it up again!"); } }
public override void CleanUp() { //Remove the group bet routine if it's active RoutineHandler.RemoveRoutine(RoutineConstants.GROUP_BET_ROUTINE_ID); base.CleanUp(); }
public override void ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; long curInputMode = DataHelper.GetSettingInt(SettingsConstants.INPUT_MODE, 0L); InputModes inpMode = (InputModes)curInputMode; //See the input mode if (arguments.Count == 0) { QueueMessage($"The current input mode is {inpMode}. To set the input mode, add one as an argument: {CachedInputModesStr}"); return; } //Invalid number of arguments if (arguments.Count > 1) { QueueMessage(UsageMessage); return; } using (BotDBContext context = DatabaseManager.OpenContext()) { //Check if the user has the ability to set the mode User user = DataHelper.GetUserNoOpen(args.Command.ChatMessage.Username, context); if (user != null && user.HasEnabledAbility(PermissionConstants.SET_INPUT_MODE_ABILITY) == false) { QueueMessage("You don't have the ability to set the input mode!"); return; } } string inputModeStr = arguments[0]; //Parse if (EnumUtility.TryParseEnumValue(inputModeStr, out InputModes parsedInputMode) == false) { QueueMessage($"Please enter a valid input mode: {CachedInputModesStr}"); return; } //Same mode if (parsedInputMode == inpMode) { QueueMessage($"The current input mode is already {inpMode}!"); return; } using (BotDBContext context = DatabaseManager.OpenContext()) { //Set the value and save Settings inputModeSetting = DataHelper.GetSettingNoOpen(SettingsConstants.INPUT_MODE, context); inputModeSetting.ValueInt = (long)parsedInputMode; context.SaveChanges(); } QueueMessage($"Changed the input mode from {inpMode} to {parsedInputMode}!"); //If we set it to Anarchy, check if the Democracy routine is active and remove it if so if (parsedInputMode == InputModes.Anarchy) { BaseRoutine democracyRoutine = RoutineHandler.FindRoutine(RoutineConstants.DEMOCRACY_ROUTINE_ID, out int indexFound); if (democracyRoutine != null) { RoutineHandler.RemoveRoutine(indexFound); } } //If we set it to Democracy, add the routine if it's not already active else if (parsedInputMode == InputModes.Democracy) { DemocracyRoutine democracyRoutine = RoutineHandler.FindRoutine <DemocracyRoutine>(); if (democracyRoutine == null) { long votingTime = DataHelper.GetSettingInt(SettingsConstants.DEMOCRACY_VOTE_TIME, 10000L); democracyRoutine = new DemocracyRoutine(votingTime); RoutineHandler.AddRoutine(democracyRoutine); } } }
public override void ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; //Ignore with too few arguments if (arguments.Count > 1) { QueueMessage(UsageMessage); return; } if (arguments.Count == 0) { long periodicInputVal = DataHelper.GetSettingInt(SettingsConstants.PERIODIC_INPUT_ENABLED, 0L); string enabledStr = (periodicInputVal <= 0) ? "disabled" : "enabled"; QueueMessage($"The periodic input is currently {enabledStr}. To change the periodic input enabled state, pass either \"true\" or \"false\" as an argument."); return; } //Check for sufficient permissions using (BotDBContext context = DatabaseManager.OpenContext()) { User user = DataHelper.GetUserNoOpen(args.Command.ChatMessage.Username, context); if (user == null || user.HasEnabledAbility(PermissionConstants.SET_PERIODIC_INPUT_ABILITY) == false) { QueueMessage("You do not have the ability to change the periodic input state!"); return; } } string newStateStr = arguments[0].ToLowerInvariant(); if (bool.TryParse(newStateStr, out bool newState) == false) { QueueMessage("Invalid argument. To enable or disable the periodic input, pass either \"true\" or \"false\" as an argument."); return; } long newVal = (newState == true) ? 1L : 0L; bool oldState = false; using (BotDBContext context = DatabaseManager.OpenContext()) { Settings periodicInput = DataHelper.GetSettingNoOpen(SettingsConstants.PERIODIC_INPUT_ENABLED, context); if (periodicInput == null) { periodicInput = new Settings(SettingsConstants.PERIODIC_INPUT_ENABLED, string.Empty, 0L); context.SettingCollection.Add(periodicInput); context.SaveChanges(); } //Same value - don't make changes if ((periodicInput.ValueInt > 0 && newVal > 0) || (periodicInput.ValueInt <= 0 && newVal <= 0)) { QueueMessage("The periodic input state is already this value!"); return; } oldState = (periodicInput.ValueInt > 0) ? true : false; periodicInput.ValueInt = newVal; context.SaveChanges(); } //Now add or remove the routine if we should if (oldState == true && newState == false) { RoutineHandler.RemoveRoutine(RoutineConstants.PERIODIC_INPUT_ROUTINE_ID); } //Add the routine else if (oldState == false && newState == true) { BaseRoutine routine = RoutineHandler.FindRoutine(RoutineConstants.PERIODIC_INPUT_ROUTINE_ID, out int indexFound); if (routine == null) { RoutineHandler.AddRoutine(new PeriodicInputRoutine()); } else { QueueMessage("Huh? The periodic input routine is somehow already running even though it was just enabled."); } } if (newState == true) { QueueMessage("Enabled periodic inputs. Every now and then, an input sequence will be automatically performed."); } else { QueueMessage("Disabled periodic inputs."); } }