private static void HandleFavorites(AccountActivityBody accountActivity, Dictionary <string, PrayerCount> tweetIdToPrayerCountMap) { if (accountActivity.favorite_events == null || accountActivity.favorite_events.Length == 0) { Console.WriteLine("No favorites events"); return; } foreach (Tweetinvi.Streams.Model.AccountActivity.AccountActivityFavouriteEventDTO favoriteEvent in accountActivity.favorite_events) { Tweetinvi.Models.ITweet favoritedTweet = Tweetinvi.Tweet.GenerateTweetFromDTO(favoriteEvent.FavouritedTweet); if (favoritedTweet == null || favoritedTweet.CreatedBy == null || favoritedTweet.CreatedBy.ScreenName != gridExplorerBotScreenName) { Console.WriteLine("Didn't favorite a Grid Explorer Bot tweet"); continue; } if (favoritedTweet.CreatedAt < Program.oldestSupportedData) { Console.WriteLine("Favorited tweet is too old."); continue; } string cleanedFavoritedTweetText = System.Net.WebUtility.HtmlDecode(favoritedTweet.Text); if (!Program.IsInLikeTemple(cleanedFavoritedTweetText, favoritedTweet.CreatedAt)) { Console.WriteLine("Isn't in Like Temple"); continue; } if (tweetIdToPrayerCountMap.ContainsKey(favoritedTweet.IdStr)) { tweetIdToPrayerCountMap[favoritedTweet.IdStr].mCurrent -= Program.prayersPerFavorite; } else { int currentPrayerCount = GetPrayerCount(favoritedTweet); tweetIdToPrayerCountMap[favoritedTweet.IdStr] = new PrayerCount() { mInitial = currentPrayerCount - Program.prayersPerFavorite, mCurrent = currentPrayerCount, }; } } }
private static void HandleCreatedTweets(AccountActivityBody accountActivity, Dictionary <string, PrayerCount> tweetIdToPrayerCountMap) { if (accountActivity.tweet_create_events == null || accountActivity.tweet_create_events.Length == 0) { Console.WriteLine("No tweet create events"); return; } IEnumerable <Tweetinvi.Models.ITweet> userTweets = Tweetinvi.Tweet.GenerateTweetsFromDTO(accountActivity.tweet_create_events); foreach (Tweetinvi.Models.ITweet userTweet in userTweets) { HandleUserReply(userTweet); HandleUserRetweet(userTweet, tweetIdToPrayerCountMap); } }
public static string HandleAccountActivityRequest(WebUtils.WebRequest request) { Console.WriteLine("Handling Account Activity Request"); Console.WriteLine(request.body); AccountActivityBody accountActivity = request.body.ConvertJsonTo <AccountActivityBody>(); Dictionary <string, PrayerCount> tweetIdToPrayerCountMap = new Dictionary <string, PrayerCount>(); HandleCreatedTweets(accountActivity, tweetIdToPrayerCountMap); HandleFavorites(accountActivity, tweetIdToPrayerCountMap); foreach (KeyValuePair <string, PrayerCount> pair in tweetIdToPrayerCountMap) { if (pair.Value.mInitial < Program.prayersRequiredForRewardInTemple && pair.Value.mCurrent >= Program.prayersRequiredForRewardInTemple) { GivePhoneAndTweetReply(pair.Key); } } return(WriteAccountActivityResponse()); }