private async Task CheckFollower(string chatter, string userTwitchId) { try { TwitchChatter follower = await GetTwitchFollowerInfo(chatter, userTwitchId); if (follower == null) { return; } // check if follower has experience int currentExp = await _follower.CurrentExp(chatter, _broadcasterId); decimal hoursWatched = 0.0m; if (currentExp > -1) { await _follower.UpdateExp(chatter, _broadcasterId, ++currentExp); // check if user has been promoted Rank capRank = _rankList.FirstOrDefault(r => r.ExpCap == currentExp); hoursWatched = _follower.GetHoursWatched(currentExp); if (hoursWatched == _botConfig.RegularFollowerHours) { Rank currentRank = _follower.GetCurrentRank(_rankList, currentExp); _irc.SendPublicChatMessage($"{currentRank.Name} {chatter} has achieved the salty equlibrium " + "needed to become a regular soldier in the salt army"); } else if (capRank != null) { Rank currentRank = _follower.GetCurrentRank(_rankList, currentExp); _irc.SendPublicChatMessage($"@{chatter} has been promoted to \"{currentRank.Name}\" " + $"with {currentExp}/{currentRank.ExpCap} EXP ({hoursWatched} hours watched)"); } } else { // add new user to the ranks await _follower.EnlistRecruit(chatter, _broadcasterId); } // check if follower has a stream currency account int funds = await _bank.CheckBalance(chatter, _broadcasterId); if (funds > -1) { if (hoursWatched >= _botConfig.RegularFollowerHours) { funds += 15; if (!_twitchChatterListInstance.TwitchRegularFollowers.Any(c => c.Username.Equals(chatter))) { _twitchChatterListInstance.TwitchRegularFollowers.Add(follower); } } else { funds += 10; } await _bank.UpdateFunds(chatter, _broadcasterId, funds); } else // ToDo: Make currency auto-increment setting { await _bank.CreateAccount(chatter, _broadcasterId, 10); } } catch (Exception ex) { Console.WriteLine($"Error inside FollowerSubscriberListener.CheckFollower(string, string): {ex.Message}"); if (ex.InnerException != null) { Console.WriteLine($"Inner Exception: {ex.InnerException.Message}"); } } }
/// <summary> /// Display the follower's stream rank /// </summary> /// <param name="chatter">User that sent the message</param> /// <returns></returns> private async Task <DateTime> ViewRankAsync(TwitchChatter chatter) { try { if (chatter.Username == _botConfig.Broadcaster.ToLower()) { _irc.SendPublicChatMessage($"Here goes {_botConfig.Broadcaster.ToLower()} flexing his rank...oh wait OpieOP"); return(DateTime.Now); } DateTime?createdAt = _twitchChatterListInstance.TwitchFollowers.FirstOrDefault(c => c.Username == chatter.Username)?.CreatedAt ?? null; if (createdAt == null) { using (HttpResponseMessage message = await _twitchInfo.CheckFollowerStatusAsync(chatter.TwitchId)) { string body = await message.Content.ReadAsStringAsync(); FollowerJSON response = JsonConvert.DeserializeObject <FollowerJSON>(body); if (!string.IsNullOrEmpty(response.CreatedAt)) { createdAt = Convert.ToDateTime(response.CreatedAt); } } } if (createdAt != null) { int currExp = await _follower.CurrentExpAsync(chatter.Username, _broadcasterInstance.DatabaseId); // Grab the follower's associated rank if (currExp > -1) { IEnumerable <Rank> rankList = await _follower.GetRankListAsync(_broadcasterInstance.DatabaseId); Rank currFollowerRank = _follower.GetCurrentRank(rankList, currExp); decimal hoursWatched = _follower.GetHoursWatched(currExp); _irc.SendPublicChatMessage($"@{chatter.DisplayName}: \"{currFollowerRank.Name}\" " + $"{currExp}/{currFollowerRank.ExpCap} EXP ({hoursWatched} hours watched)"); } else { await _follower.EnlistRecruitAsync(chatter.Username, _broadcasterInstance.DatabaseId); _irc.SendPublicChatMessage($"Welcome to the army @{chatter.DisplayName}. View your new rank using !rank"); } } else { _irc.SendPublicChatMessage($"{chatter.DisplayName} is not following {_botConfig.Broadcaster.ToLower()}"); } } catch (Exception ex) { await _errHndlrInstance.LogError(ex, "FollowerFeature", "ViewRank(TwitchChatter)", false, "!rank"); } return(DateTime.Now); }