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 ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; if (arguments.Count != 1) { QueueMessage("Please specify a bet amount!"); return; } string creditsName = DataHelper.GetCreditsName(); string userName = args.Command.ChatMessage.Username; //Check if we can parse the bet amount long betAmount = -1L; bool success = long.TryParse(arguments[0], out betAmount); if (success == false || betAmount <= 0) { QueueMessage($"Please specify a positive whole number of {creditsName.Pluralize(false, 0)} greater than 0!"); return; } using (BotDBContext context = DatabaseManager.OpenContext()) { //Check if the user exists User user = DataHelper.GetUserNoOpen(userName, context); if (user == null) { QueueMessage("The user calling this does not exist in the database!"); return; } //No ability to enter group bets if (user.HasEnabledAbility(PermissionConstants.GROUP_BET_ABILITY) == false) { QueueMessage("You do not have the ability to participate in a group bet!"); return; } //Validate credit amount if (user.Stats.Credits < betAmount) { QueueMessage($"You don't have enough {creditsName.Pluralize(false, 0)} to bet this much!"); return; } if (user.IsOptedOut == true) { QueueMessage("You can't participate in the group bet since you opted out of bot stats."); return; } } //Get total time and minimum participants required long groupBetTime = DataHelper.GetSettingInt(SettingsConstants.GROUP_BET_TOTAL_TIME, 120000L); int groupBetMinUsers = (int)DataHelper.GetSettingInt(SettingsConstants.GROUP_BET_MIN_PARTICIPANTS, 3L); //Get the routine GroupBetRoutine groupBetRoutine = RoutineHandler.FindRoutine <GroupBetRoutine>(); //We haven't started the group bet, so start it up if (groupBetRoutine == null) { groupBetRoutine = new GroupBetRoutine(groupBetTime, groupBetMinUsers); RoutineHandler.AddRoutine(groupBetRoutine); } //Note: From hereon, use the routine's total time and min participant values //The database values could have changed in between calls of this command //and thus wouldn't be applicable to the group bet created for the first participant //See if the user is already in the group bet bool prevParticipant = groupBetRoutine.TryGetParticipant(userName, out GroupBetRoutine.ParticipantData participantData); groupBetRoutine.AddOrUpdateParticipant(userName, betAmount); string message = string.Empty; //Newly added since they were not previously there if (prevParticipant == false) { message = $"{userName} entered the group bet with {betAmount} {creditsName.Pluralize(false, betAmount)}!"; int participantCount = groupBetRoutine.ParticipantCount; if (participantCount < groupBetRoutine.MinParticipants) { int diff = groupBetRoutine.MinParticipants - groupBetRoutine.ParticipantCount; message += $" {diff} more user(s) are required to start the group bet!"; } QueueMessage(message); //Check if we have enough participants now if (participantCount == groupBetRoutine.MinParticipants) { TimeSpan timeSpan = TimeSpan.FromMilliseconds(groupBetRoutine.MillisecondsForBet); QueueMessage($"The group bet has enough participants and will start in {timeSpan.Minutes} minute(s) and {timeSpan.Seconds} second(s), so join before then if you want in!"); } } else { QueueMessage($"{userName} adjusted their group bet from {participantData.ParticipantBet} to {betAmount} {creditsName.Pluralize(false, betAmount)}!"); } }