/// <summary> /// Tell the user how long they have been following the broadcaster /// </summary> /// <param name="chatter">User that sent the message</param> /// <returns></returns> private async Task <DateTime> FollowSinceAsync(TwitchChatter chatter) { try { if (chatter.Username == _botConfig.Broadcaster.ToLower()) { _irc.SendPublicChatMessage($"Please don't tell me you're really following yourself...are you {_botConfig.Broadcaster.ToLower()}? WutFace"); return(DateTime.Now); } chatter.CreatedAt = _twitchChatterListInstance.TwitchFollowers.FirstOrDefault(c => c.Username == chatter.Username).CreatedAt; if (chatter.CreatedAt == null) { // get chatter info manually RootUserJSON rootUserJSON = await _twitchInfo.GetUsersByLoginNameAsync(chatter.Username); using (HttpResponseMessage message = await _twitchInfo.CheckFollowerStatusAsync(rootUserJSON.Users.First().Id)) { string body = await message.Content.ReadAsStringAsync(); FollowerJSON response = JsonConvert.DeserializeObject <FollowerJSON>(body); if (!string.IsNullOrEmpty(response.CreatedAt)) { chatter.CreatedAt = Convert.ToDateTime(response.CreatedAt); } } } // mainly used if chatter was originally null if (chatter.CreatedAt != null) { DateTime startedFollowing = Convert.ToDateTime(chatter.CreatedAt); _irc.SendPublicChatMessage($"@{chatter.DisplayName} has been following since {startedFollowing.ToLongDateString()}"); } else { _irc.SendPublicChatMessage($"{chatter.DisplayName} is not following {_botConfig.Broadcaster.ToLower()}"); } } catch (Exception ex) { await _errHndlrInstance.LogError(ex, "FollowerFeature", "FollowSince(TwitchChatter)", false, "!followsince"); } return(DateTime.Now); }
private async Task <TwitchChatter> GetTwitchFollowerInfo(string chatter, string userTwitchId) { TwitchChatter follower = null; try { using (HttpResponseMessage message = await _twitchInfo.CheckFollowerStatus(userTwitchId)) { // check if chatter is a follower if (!message.IsSuccessStatusCode) { // check if user was a follower but isn't anymore if (_twitchChatterListInstance.TwitchFollowers.Any(c => c.Username == chatter)) { _twitchChatterListInstance.TwitchFollowers.RemoveAll(c => c.Username == chatter); _twitchChatterListInstance.TwitchRegularFollowers.RemoveAll(c => c.Username == chatter); } return(null); } string body = await message.Content.ReadAsStringAsync(); FollowerJSON response = JsonConvert.DeserializeObject <FollowerJSON>(body); DateTime startedFollowing = Convert.ToDateTime(response.CreatedAt); follower = new TwitchChatter { Username = chatter, CreatedAt = startedFollowing, TwitchId = userTwitchId }; if (!_twitchChatterListInstance.TwitchFollowers.Any(c => c.Username == chatter)) { _twitchChatterListInstance.TwitchFollowers.Add(follower); } } } catch (Exception ex) { Console.WriteLine($"Error inside FollowerSubscriberListener.GetTwitchFollowerInfo(string, string): {ex.Message}"); if (ex.InnerException != null) { Console.WriteLine($"Inner Exception: {ex.InnerException.Message}"); } } return(follower); }
/// <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); }