public DoTrickle() { TwitchAPI api = new TwitchAPI(); api.Settings.ClientId = ConfigurationManager.AppSettings["ClientId"]; string channel = ConfigurationManager.AppSettings["Channel"]; var users = api.Undocumented.GetChattersAsync(channelName: channel).Result; using var db = new TwitchContext(); StringBuilder trickledUsers = new StringBuilder(); int trickleAmount = int.Parse(ConfigurationManager.AppSettings["TrickleAmount"]); string currencyName = ConfigurationManager.AppSettings["CurrencyName"]; foreach (var user in users) { string username = user.Username.ToLower(); var dbUser = db.Scores .Where(u => u.Username == username) .FirstOrDefault(); if (null == dbUser) { continue; } trickledUsers.Append($"{username}, "); dbUser.Score += trickleAmount; db.SaveChanges(); } Log.Debug($"Trickled {trickleAmount} {currencyName} to {trickledUsers.ToString()}."); }
// Create a user account if one doesn't exist. private void CheckUserAccount(string username) { using var db = new TwitchContext(); if (!db.Scores.Any(s => s.Username == username)) { string currencyName = ConfigurationManager.AppSettings["CurrencyName"]; int startingCurrency = int.Parse(ConfigurationManager.AppSettings["StartingCurrency"]); Log.Debug($"Creating account for {username} with {startingCurrency} {currencyName}."); db.Add(new Scores { Username = username, Score = startingCurrency }); db.SaveChanges(); } }