/// <summary> /// Sends the message in the received tweet to the bot via Direct Line. /// If we get a valid response indicating that the message was received by the bot, /// we will store the Twitter user identifiers (to be able to reply back). /// </summary> /// <param name="sender"></param> /// <param name="messageEventArgs">Contains the Twitter message details.</param> protected virtual async void OnTweetReceivedAsync(object sender, Tweetinvi.Events.MatchedTweetReceivedEventArgs messageEventArgs) { var tweet = messageEventArgs.Tweet; var conversationId = string.IsNullOrEmpty(tweet.InReplyToStatusIdStr) ? null : _conversationCache.GetConversationOfTweet(new IdAndTimestamp(tweet.InReplyToStatusIdStr)); var sendResult = await _directLineManager.SendMessageAsync( conversationId, tweet.Text, tweet.CreatedBy.UserIdentifier.IdStr, tweet.CreatedBy.UserIdentifier.ScreenName); if (sendResult == null) { Debug.WriteLine( $"Failed to send the message from user '{tweet.CreatedBy.UserIdentifier.ScreenName}' to the bot - message text was '{tweet.Text}'"); } else { Debug.WriteLine( $"Message from user '{tweet.CreatedBy.UserIdentifier.ScreenName}' successfully sent to the bot - message ID is '{sendResult.MessageId}'"); _conversationCache.PutLatestTweetOfConversation(new IdAndTimestamp(sendResult.Conversation.ConversationId), tweet); _directLineManager.StartPolling(); } }
private void NewTweetFound(object sender, Tweetinvi.Events.MatchedTweetReceivedEventArgs e) { //Check if the tweet was done by Jarvis Account (To Stop For ever Loop) if (e.Tweet.CreatedBy.ScreenName == Jarvis.ScreenName) { return; } if (e.Tweet.Text.ToLower().Contains("#retweetjarvis")) { while (TweetSendedWithin15MinWindow >= 14) { Thread.Sleep(30000); } Tweet.PublishRetweet(e.Tweet.Id); TweetSendedWithin15MinWindow++; return; } var PatternReply = PatternChatbot.getReply(e.Tweet.Text); var TokenReply = TokenChatbot.getReply(e.Tweet.Text); string[] Replies = { "Wow ! Thanks for making me reply to this tweet", "Reply Reply Reply .... :)", "Im so fast", "Just stepped on a lucky charm, I'm officially a cereal killer.", "Cant catch me", "Dont ever make eye contact while eating a banana.", "I've decided that I'm going to treat people exactly how they treat me. Most people should be glad. Some should be very scared.", "I am what I am and that is all I am and I am it.", "We are all in the gutter, but some of us are looking at the stars" }; string Reply = "Wow"; if (string.IsNullOrEmpty(PatternReply?.reply)) { if (string.IsNullOrEmpty(TokenReply?.reply)) { Reply = Replies[RandomGenerator.Next(Replies.Length - 1)]; } else { Reply = TokenReply.reply; } } else { Reply = PatternReply.reply; } while (TweetSendedWithin15MinWindow >= 14) { Thread.Sleep(30000); } if (RandomGenerator.Next(100) > 50) { Tweet.FavoriteTweet(e.Tweet.Id); } Thread.Sleep(RandomGenerator.Next(5000, 30000)); var textToPublish = string.Format("@{0} {1}", e.Tweet.CreatedBy.ScreenName, Reply); var tweet = Tweet.PublishTweetInReplyTo(textToPublish, e.Tweet.Id); TweetSendedWithin15MinWindow++; }
private void OnMatchingTweetReceived(object sender, Tweetinvi.Events.MatchedTweetReceivedEventArgs e) { logger.LogInformation($"OnMatchingTweetReceived Twitter message received. {JsonConvert.SerializeObject(e)}"); if (e.Tweet.CreatedBy.Id == _botUser.Id) { logger.LogInformation("Skip. Tweet is created by bot."); return; } TweetReceived?.Invoke(this, e); }
private void Stream_MatchingTweetReceived(object sender, Tweetinvi.Events.MatchedTweetReceivedEventArgs e) { if (e.Tweet.CreatedBy.ScreenName != this.InParameters["user"].GetValue().ToString()) { return; } var instanciatedParameters = this.InstanciateParametersForCycle(); instanciatedParameters["message"].SetValue(e.Tweet.FullText); this.Graph.AddCycle(this, instanciatedParameters); }
private void OnMatchingTweetReceived(object sender, Tweetinvi.Events.MatchedTweetReceivedEventArgs e) { Debug.WriteLine("OnMatchingTweetReceived Twitter message received"); Debug.WriteLine(JsonConvert.SerializeObject(e)); if (e.Tweet.CreatedBy.Id == _botUser.Id) { Debug.WriteLine("Skip. Tweet is created by bot."); return; } TweetReceived?.Invoke(this, e); }
private void HandleTweet(object sender, Tweetinvi.Events.MatchedTweetReceivedEventArgs e) { if (this.IsHandleCreated) { Invoke(new Action(() => { int index = tweetList.Items.Add(e.Tweet.CreatedBy.Name + ": " + e.Tweet.Text); tweetDict.Add(index, e.Tweet); })); tweetList.Invalidate(); } }
private static void MatchingTweetReceived(object sender, Tweetinvi.Events.MatchedTweetReceivedEventArgs e) { var tweet = e.Tweet; if (tweet.InReplyToUserId == user.Id && tweet.Media.Any()) { string mediaType = GetMediaType(tweet); if ((mediaType == "photo" && blockPhotos) || (mediaType == "video" && blockVideos) || (mediaType == "gif" && blockGifs)) { Console.WriteLine($"Blocking @{tweet.CreatedBy.ScreenName} because they replied with a {mediaType} to https://www.twitter.com/i/status/{tweet.InReplyToStatusId}"); User.BlockUser(tweet.CreatedBy); } } }
private void _stream_MatchingTweetReceived(object sender, Tweetinvi.Events.MatchedTweetReceivedEventArgs e) { this.OnTweetReceived(TweetReceivedEventArgs.Create(ParseTweet(e.Tweet))); }
private static void OnTweetReceived(object sender, Tweetinvi.Events.MatchedTweetReceivedEventArgs e) { TweetCount++; Database.SaveTweet(new Tweet(e.Tweet.CreatedBy.ScreenName, e.Tweet.FullText, e.Tweet.FavoriteCount, e.Tweet.RetweetCount)); }
private void newTweet(Object sender, Tweetinvi.Events.MatchedTweetReceivedEventArgs args) { Debug.WriteLine("New tweet found: " + args.Tweet); }