private void TwitterCheckTimer() { foreach (var vtuber in Config.DefaultConfig.Vtubers.ToArray().Where(v => v.TwitterProfileId != null)) { var timeline = TwitterApi.GetTimelineByUser(vtuber.TwitterProfileId, 10); if (!LastCheckTweets.ContainsKey(vtuber)) { LastCheckTweets.Add(vtuber, timeline); } LastCheckTweets[vtuber] = timeline; var lastRetweeted = timeline.FirstOrDefault(v => v.RetweetedTweet != null); var lastPublish = timeline.FirstOrDefault(v => v.RetweetedTweet == null && !v.IsReply && !v.IsQuote); var lastReply = timeline.FirstOrDefault(v => v.IsReply); //Update cache if (lastPublish != null) { if (!LastTweetTime.ContainsKey(vtuber)) { LastTweetTime.Add(vtuber, lastPublish.CreateTime); } if (LastTweetTime[vtuber] != lastPublish.CreateTime) { LastTweetTime[vtuber] = lastPublish.CreateTime; VtuberPublishTweetEvent?.Invoke(vtuber, lastPublish); } } if (lastReply != null) { if (!LastReplyTime.ContainsKey(vtuber)) { LastReplyTime.Add(vtuber, lastReply.CreateTime); } if (LastReplyTime[vtuber] != lastReply.CreateTime) { LastReplyTime[vtuber] = lastReply.CreateTime; VtuberReplyTweetEvent?.Invoke(vtuber, lastReply); } } if (lastRetweeted != null) { if (!LastRetweetedTime.ContainsKey(vtuber)) { LastRetweetedTime.Add(vtuber, lastRetweeted.CreateTime); } if (LastRetweetedTime[vtuber] != lastRetweeted.CreateTime) { LastRetweetedTime[vtuber] = lastRetweeted.CreateTime; VtuberRetweetedEvent?.Invoke(vtuber, lastRetweeted); } } } }
private async Task TwitterCheckTimer(IEnumerable <VtuberEntity> vtubers) { foreach (var vtuber in vtubers.Where(v => !string.IsNullOrEmpty(v.TwitterProfileId))) { var timeline = await TwitterApi.GetTimelineByUserAsync(vtuber.TwitterProfileId, 10); if (timeline == null) { continue; } if (!LastCheckTweets.ContainsKey(vtuber)) { LastCheckTweets.Add(vtuber, timeline); } LastCheckTweets[vtuber] = timeline; var lastRetweeted = timeline.FirstOrDefault(v => v.RetweetedTweet != null); var lastPublish = timeline.FirstOrDefault(v => v.RetweetedTweet == null && !v.IsReply && !v.IsQuote); var lastReply = timeline.FirstOrDefault(v => v.IsReply); //Update cache if (lastPublish != null) { if (!LastTweetTime.ContainsKey(vtuber)) { LastTweetTime.Add(vtuber, lastPublish.CreateTime); } if (LastTweetTime[vtuber] != lastPublish.CreateTime) { LastTweetTime[vtuber] = lastPublish.CreateTime; await _tweetCollection.InsertOneAsync(lastPublish); VtuberPublishTweetEvent?.Invoke(vtuber, lastPublish); } } if (lastReply != null) { if (!LastReplyTime.ContainsKey(vtuber)) { LastReplyTime.Add(vtuber, lastReply.CreateTime); } if (LastReplyTime[vtuber] != lastReply.CreateTime) { LastReplyTime[vtuber] = lastReply.CreateTime; await _tweetCollection.InsertOneAsync(lastReply); VtuberReplyTweetEvent?.Invoke(vtuber, lastReply); } } if (lastRetweeted != null) { if (!LastRetweetedTime.ContainsKey(vtuber)) { LastRetweetedTime.Add(vtuber, lastRetweeted.CreateTime); } if (LastRetweetedTime[vtuber] != lastRetweeted.CreateTime) { LastRetweetedTime[vtuber] = lastRetweeted.CreateTime; await _tweetCollection.InsertOneAsync(lastRetweeted); VtuberRetweetedEvent?.Invoke(vtuber, lastRetweeted); } } } }