public override void ExecuteCommand(EvtChatCommandArgs args) { string creditsName = DataHelper.GetCreditsName(); string userName = args.Command.ChatMessage.Username.ToLowerInvariant(); User user = DataHelper.GetOrAddUser(userName, out bool added); if (user == null) { QueueMessage("Huh? The user calling this doesn't exist in the database!"); return; } if (ConfirmClearedStatsUsers.Contains(userName) == false) { QueueMessage($"WARNING {userName}: this clears all miscellaneous user stats, such as {creditsName.Pluralize(false, 0)}, message/input counts, and recent inputs. If you're sure, retype this command with \"{CONFIRM_CLEAR_STR}\" as an argument to clear or \"{CONFIRM_STOP_STR}\" to decline."); ConfirmClearedStatsUsers.Add(userName); return; } //Check for an argument List <string> arguments = args.Command.ArgumentsAsList; //Only accept the exact argument if (arguments.Count != 1) { QueueMessage($"If you're sure you want to clear your stats, retype this command with \"{CONFIRM_CLEAR_STR}\" as an argument to clear or \"{CONFIRM_STOP_STR}\" to decline."); return; } string confirmation = arguments[0]; //Confirm - clear stats if (confirmation == CONFIRM_CLEAR_STR) { using (BotDBContext context = DatabaseManager.OpenContext()) { user = DataHelper.GetUserNoOpen(userName, context); //Clear stats and save user.RecentInputs.Clear(); user.Stats.Credits = 0L; user.Stats.TotalMessageCount = 0L; user.Stats.ValidInputCount = 0L; context.SaveChanges(); } ConfirmClearedStatsUsers.Remove(userName); QueueMessage("Successfully cleared stats!"); } //Ignore else if (confirmation == CONFIRM_STOP_STR) { ConfirmClearedStatsUsers.Remove(userName); QueueMessage("Cancelled clearing stats!"); } }
public override void ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; string creditsName = DataHelper.GetCreditsName(); string userName = args.Command.ChatMessage.Username; using (BotDBContext context = DatabaseManager.OpenContext()) { User bettingUser = DataHelper.GetUserNoOpen(args.Command.ChatMessage.Username, context); if (bettingUser.HasEnabledAbility(PermissionConstants.BET_ABILITY) == false) { QueueMessage("You do not have the ability to bet!"); return; } if (bettingUser.IsOptedOut == true) { QueueMessage("You cannot bet while opted out of stats."); return; } } if (arguments.Count != 1) { QueueMessage(UsageMessage); return; } if (long.TryParse(arguments[0], out long creditBet) == false) { QueueMessage("Please enter a valid bet amount!"); return; } if (creditBet <= 0) { QueueMessage("Bet amount must be greater than 0!"); return; } using (BotDBContext context = DatabaseManager.OpenContext()) { User bettingUser = DataHelper.GetUserNoOpen(args.Command.ChatMessage.Username, context); if (creditBet > bettingUser.Stats.Credits) { QueueMessage($"Bet amount is greater than {creditsName.Pluralize(false, 0)}!"); return; } } //Make it a 50/50 chance bool success = (Rand.Next(0, 2) == 0); string message = string.Empty; using (BotDBContext context = DatabaseManager.OpenContext()) { User bettingUser = DataHelper.GetUserNoOpen(args.Command.ChatMessage.Username, context); //Add or subtract credits based on the bet result if (success) { bettingUser.Stats.Credits += creditBet; message = $"{bettingUser.Name} won {creditBet} {creditsName.Pluralize(false, creditBet)} PogChamp"; } else { bettingUser.Stats.Credits -= creditBet; message = $"{bettingUser.Name} lost {creditBet} {creditsName.Pluralize(false, creditBet)} BibleThump"; } context.SaveChanges(); } QueueMessage(message); }
public override void ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; //Invalid number of arguments if (arguments.Count > 1) { QueueMessage(UsageMessage); return; } string name = args.Command.ChatMessage.Username; using (BotDBContext context = DatabaseManager.OpenContext()) { User user = DataHelper.GetUserNoOpen(name, context); if (user == null) { return; } //Display opt status if (arguments.Count == 0) { string message = "You are opted "; if (user.IsOptedOut == true) { message += "out of "; } else { message += "into "; } message += "bot stats. Enter \"true\" or \"false\" as an argument to change your opt status."; QueueMessage(message); return; } } string optStr = arguments[0]; if (bool.TryParse(optStr, out bool optStatus) == false) { QueueMessage("Invalid opt status argument."); return; } using (BotDBContext context = DatabaseManager.OpenContext()) { User user = DataHelper.GetUserNoOpen(name, context); //Opt back into stats if (optStatus == true) { if (user.IsOptedOut == false) { QueueMessage("You are already opted into bot stats!"); return; } QueueMessage("Opted back into bot stats!"); } else { if (user.IsOptedOut == true) { QueueMessage("You are already opted out of bot stats!"); return; } QueueMessage("Opted out of bot stats!"); } //Set status and save user.SetOptStatus(optStatus); context.SaveChanges(); } }
public override void ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; int defaultInputDur = (int)DataHelper.GetSettingInt(SettingsConstants.DEFAULT_INPUT_DURATION, 200L); if (arguments.Count == 0) { QueueMessage($"The default duration of an input is {defaultInputDur} milliseconds!"); return; } if (arguments.Count > 1) { QueueMessage(UsageMessage); return; } using (BotDBContext context = DatabaseManager.OpenContext()) { //Check if the user has this ability User user = DataHelper.GetUserNoOpen(args.Command.ChatMessage.Username, context); if (user == null) { QueueMessage("Somehow, the user calling this is not in the database."); return; } if (user.HasEnabledAbility(PermissionConstants.SET_DEFAULT_INPUT_DUR_ABILITY) == false) { QueueMessage("You do not have the ability to set the global default input duration!"); return; } } if (int.TryParse(arguments[0], out int newDefaultDur) == false) { QueueMessage("Please enter a valid number!"); return; } if (newDefaultDur <= 0) { QueueMessage("Cannot set a duration less than or equal to 0!"); return; } if (newDefaultDur == defaultInputDur) { QueueMessage("The duration is already this value!"); return; } //Change the setting using (BotDBContext context = DatabaseManager.OpenContext()) { Settings defaultDurSetting = DataHelper.GetSettingNoOpen(SettingsConstants.DEFAULT_INPUT_DURATION, context); defaultDurSetting.ValueInt = newDefaultDur; context.SaveChanges(); } QueueMessage($"Set the default input duration to {newDefaultDur} milliseconds!"); }
public override void ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; long curVoteTime = DataHelper.GetSettingInt(SettingsConstants.DEMOCRACY_VOTE_TIME, 10000L); //See the time if (arguments.Count == 0) { QueueMessage($"The current Democracy voting time is {curVoteTime}. To set the vote time, add it as an argument, in milliseconds."); 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 vote time User user = DataHelper.GetUserNoOpen(args.Command.ChatMessage.Username, context); if (user != null && user.HasEnabledAbility(PermissionConstants.SET_DEMOCRACY_VOTE_TIME_ABILITY) == false) { QueueMessage("You don't have the ability to set the Democracy voting time!"); return; } } string numStr = arguments[0]; //Parse if (long.TryParse(numStr, out long parsedTime) == false) { QueueMessage("Invalid number!"); return; } //Same time if (curVoteTime == parsedTime) { QueueMessage($"The current voting time is already {curVoteTime}!"); return; } //Check min value if (parsedTime < MIN_VOTING_TIME) { QueueMessage($"{parsedTime} is a very low voting time and may not be useful in the long run! Please set it to at least {MIN_VOTING_TIME} milliseconds."); return; } if (parsedTime > MAX_VOTING_TIME_WARNING) { QueueMessage($"{parsedTime} milliseconds is a long voting time that may slow down the stream. Consider setting the time lower than {MAX_VOTING_TIME_WARNING} milliseconds."); } using (BotDBContext context = DatabaseManager.OpenContext()) { //Set the value and save Settings resModeSetting = DataHelper.GetSettingNoOpen(SettingsConstants.DEMOCRACY_VOTE_TIME, context); resModeSetting.ValueInt = parsedTime; context.SaveChanges(); } QueueMessage($"Changed the Democracy voting time from {curVoteTime} to {parsedTime}!"); }
public override void ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; if (arguments.Count < 2) { QueueMessage(UsageMessage); return; } string macroName = arguments[0].ToLowerInvariant(); //Make sure the first argument has at least a minimum number of characters if (macroName.Length < MIN_MACRO_NAME_LENGTH) { QueueMessage($"Input macros need to be at least {MIN_MACRO_NAME_LENGTH} characters long."); return; } if (macroName.StartsWith(Parser.DEFAULT_PARSER_REGEX_MACRO_INPUT) == false) { QueueMessage($"Input macros must start with \"{Parser.DEFAULT_PARSER_REGEX_MACRO_INPUT}\"."); return; } //For simplicity with wait inputs, force the first character in the macro name to be alphanumeric if (char.IsLetterOrDigit(arguments[0][1]) == false) { QueueMessage("The first character in input macro names must be alphanumeric."); return; } //Check for max macro name if (macroName.Length > MAX_MACRO_NAME_LENGTH) { QueueMessage($"Input macros may have up to a max of {MAX_MACRO_NAME_LENGTH} characters in their name."); return; } int curConsoleID = (int)DataHelper.GetSettingInt(SettingsConstants.LAST_CONSOLE, 1L); GameConsole consoleInstance = null; using (BotDBContext context = DatabaseManager.OpenContext()) { GameConsole curConsole = context.Consoles.FirstOrDefault(c => c.ID == curConsoleID); if (curConsole == null) { QueueMessage("Cannot validate input macro, as the current console is invalid. Fix this by setting another console."); return; } consoleInstance = new GameConsole(curConsole.Name, curConsole.InputList); } Parser parser = new Parser(); //Trim the macro name from the input sequence string macroVal = args.Command.ArgumentsAsString.Remove(0, macroName.Length + 1).ToLowerInvariant(); //Console.WriteLine(macroVal); bool isDynamic = false; //Check for a dynamic macro int openParenIndex = macroName.IndexOf('(', 0); if (openParenIndex >= 0) { //If we found the open parenthesis, check for the asterisk //This is not comprehensive, but it should smooth out a few issues if (openParenIndex == (macroName.Length - 1) || macroName[openParenIndex + 1] != '*') { QueueMessage("Invalid input macro. Dynamic macro arguments must be specified with \"*\"."); return; } if (macroName[macroName.Length - 1] != ')') { QueueMessage("Invalid input macro. Dynamic macros must end with \")\"."); return; } isDynamic = true; } //Validate input if not dynamic if (isDynamic == false) { ParsedInputSequence inputSequence = default; try { string userName = args.Command.ChatMessage.Username; //Get default and max input durations //Use user overrides if they exist, otherwise use the global values int defaultDur = (int)DataHelper.GetUserOrGlobalDefaultInputDur(userName); int maxDur = (int)DataHelper.GetUserOrGlobalMaxInputDur(userName); string regexStr = consoleInstance.InputRegex; string readyMessage = string.Empty; using (BotDBContext context = DatabaseManager.OpenContext()) { IQueryable <InputSynonym> synonyms = context.InputSynonyms.Where(syn => syn.ConsoleID == curConsoleID); readyMessage = parser.PrepParse(macroVal, context.Macros, synonyms); } inputSequence = parser.ParseInputs(readyMessage, regexStr, new ParserOptions(0, defaultDur, true, maxDur)); TRBotLogger.Logger.Debug(inputSequence.ToString()); if (inputSequence.ParsedInputResult != ParsedInputResults.Valid) { if (string.IsNullOrEmpty(inputSequence.Error) == true) { QueueMessage("Invalid input macro."); } else { QueueMessage($"Invalid input macro: {inputSequence.Error}"); } return; } } catch (Exception e) { QueueMessage($"Invalid input macro: {e.Message}"); return; } } string message = string.Empty; using (BotDBContext context = DatabaseManager.OpenContext()) { InputMacro inputMacro = context.Macros.FirstOrDefault(m => m.MacroName == macroName); //Not an existing macro, so add it if (inputMacro == null) { InputMacro newMacro = new InputMacro(macroName, macroVal); context.Macros.Add(newMacro); if (isDynamic == false) { message = $"Added input macro \"{macroName}\"!"; } else { message = $"Added dynamic input macro \"{macroName}\"! Dynamic input macros can't be validated beforehand, so verify it works manually."; } } //Update the macro value else { inputMacro.MacroValue = macroVal; if (isDynamic == false) { message = $"Updated input macro \"{macroName}\"!"; } else { message = $"Updated dynamic input macro \"{macroName}\"! Dynamic input macros can't be validated beforehand, so verify it works manually."; } } context.SaveChanges(); } QueueMessage(message); }
public override void ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; long midDelayEnabled = DataHelper.GetSettingInt(SettingsConstants.GLOBAL_MID_INPUT_DELAY_ENABLED, 0L); long midDelayTime = DataHelper.GetSettingInt(SettingsConstants.GLOBAL_MID_INPUT_DELAY_TIME, 34L); if (arguments.Count == 0) { string enabledStateStr = (midDelayEnabled > 0L) ? "enabled" : "disabled"; QueueMessage($"The global mid input delay is {enabledStateStr} with a duration of {midDelayTime} milliseconds!"); return; } if (arguments.Count > 2) { QueueMessage(UsageMessage); return; } using (BotDBContext context = DatabaseManager.OpenContext()) { //Check if the user has this ability User user = DataHelper.GetUserNoOpen(args.Command.ChatMessage.Username, context); if (user == null) { QueueMessage("Somehow, the user calling this is not in the database."); return; } if (user.HasEnabledAbility(PermissionConstants.SET_MID_INPUT_DELAY_ABILITY) == false) { QueueMessage("You do not have the ability to set the global mid input delay!"); return; } } string enabledStr = arguments[0]; string durationStr = arguments[0]; bool parsedEnabled = false; bool parsedDuration = false; //Set the duration string to the second argument if we have more arguments if (arguments.Count == 2) { durationStr = arguments[1]; } //Parse enabled state parsedEnabled = bool.TryParse(enabledStr, out bool enabledState); //Parse duration parsedDuration = long.TryParse(durationStr, out long newMidInputDelay); //Failed to parse enabled state if (parsedEnabled == false) { //Return if we're expecting two valid arguments or one valid argument and the duration parse failed if (arguments.Count == 2 || (arguments.Count == 1 && parsedDuration == false)) { QueueMessage("Please enter \"true\" or \"false\" for the enabled state!"); return; } } if (parsedDuration == false) { //Return if we're expecting two valid arguments or one valid argument and the enabled parse failed if (arguments.Count == 2 || (arguments.Count == 1 && parsedEnabled == false)) { QueueMessage("Please enter a valid number greater than 0!"); return; } } if (parsedDuration == true && newMidInputDelay < MIN_MID_INPUT_DELAY_DURATION) { QueueMessage($"The global mid input delay cannot be less than {MIN_MID_INPUT_DELAY_DURATION}!"); return; } string message = "Set the global mid input delay"; using (BotDBContext context = DatabaseManager.OpenContext()) { Settings midDelayEnabledSetting = DataHelper.GetSettingNoOpen(SettingsConstants.GLOBAL_MID_INPUT_DELAY_ENABLED, context); Settings midDelayTimeSetting = DataHelper.GetSettingNoOpen(SettingsConstants.GLOBAL_MID_INPUT_DELAY_TIME, context); //Modify the message based on what was successfully parsed if (parsedEnabled == true) { midDelayEnabledSetting.ValueInt = (enabledState == true) ? 1L : 0L; message += " enabled state to " + enabledState; } if (parsedDuration == true) { midDelayTimeSetting.ValueInt = newMidInputDelay; //The enabled state was also parsed if (parsedEnabled == true) { message += " and duration to " + newMidInputDelay; } else { message += " duration to " + newMidInputDelay + " milliseconds"; } } context.SaveChanges(); } QueueMessage($"{message}!"); }