private async Task NewSubDieRollAsync(string displayName, string userId) { var msg = $"{displayName} just subscribed! "; var roll = _rng.Next(1, 21); if (roll == 1) { msg += "You rolled a 1! Have a consolation slothy."; await _slothySvc.AddSlothiesAsync(userId, 1); } else if (roll == 20) { msg += "You rolled a 20!!! Enjoy your 20 bonus slothies."; await _slothySvc.AddSlothiesAsync(userId, 20); } else if (roll == 8 || roll == 11 || roll == 18) { msg += $"You rolled an {roll}!"; } else { msg += $"You rolled a {roll}!"; } _client.SendMessage(_config.TwitchChannel, msg); }
private async Task ProcessBetsAsync(OnChatCommandReceivedArgs e, SlothyBetType type) { if (!_canProcessBets) { _client.SendMessage(e, $"@{e.Command.ChatMessage.DisplayName}: Bets cannot be processed right now. " + "If betting is open, close it first."); return; } _canProcessBets = false; _canProcessCorrection = false; _client.SendMessage(e, "Processing bets..."); var currentBets = _betSvc.GetAllCurrentBets(); foreach (var bet in currentBets) { if (bet.BetType == type) { await _slothySvc.AddSlothiesAsync(bet.UserId, bet.Amount); } else { await _slothySvc.AddSlothiesAsync(bet.UserId, 0 - bet.Amount); } } var stats = CalculateStats(); _previousSlothyBetRecords = currentBets; _previousBetWinType = type; await _betSvc.ClearBetsAsync(); await KeyValueService.CreateOrUpdateAsync(nameof(SlothyBetStatus), nameof(SlothyBetStatus.Closed)); _canProcessCorrection = true; _client.SendMessage(e, $"Bets processed. | {stats}"); }
private async Task UpdateSlothiesAsync(OnChatCommandReceivedArgs e) { var origUsername = e.Command.ArgumentsAsList[0].TrimStart('@'); var username = origUsername.ToLower(); if (username.Length >= 200) { _client.SendMessage(e, "That's not a valid user, you nerd."); return; } var users = await _api.Helix.Users.GetUsersAsync(logins : new List <string> { username }); if (users.Users.Length != 1) { _client.SendMessage(e, "That's not a valid user, you nerd."); return; } var userId = users.Users[0].Id; if (userId == e.Command.ChatMessage.UserId) { _client.SendMessage(e, "You can't change your own slothies, you nerd."); return; } if (userId == _vaindilId) { _client.SendMessage(e, "vaindil's slothies can't be edited, you nerd."); return; } decimal count; bool validDecimal; try { // use try/catch to prevent overflow exception validDecimal = decimal.TryParse(e.Command.ArgumentsAsList[1], out count); } catch { _client.SendMessage(e, "You can't overflow me, you nerd."); return; } if (!validDecimal) { _client.SendMessage(e, "That's not a valid number, you nerd."); return; } count = Math.Round(count, 2); count = await _slothySvc.AddSlothiesAsync(userId, count); _client.SendMessage(e, $"{origUsername} now has {count.ToDisplayString()}."); }