MCPcopy Index your code
hub / github.com/Philipinho/GetVideoBot / onTweetStreamed

Method onTweetStreamed

src/main/java/Stream.java:56–123  ·  view source on GitHub ↗
(Tweet tweet)

Source from the content-addressed store, hash-verified

54 }
55
56 @Override
57 public void onTweetStreamed(Tweet tweet) {
58 try {
59 String tweetReferencedId = "";
60 String mentionTweetId = tweet.getId();
61
62 if (tweet.getTweetType().equals(TweetType.QUOTED)) {
63 tweetReferencedId = tweet.getInReplyToStatusId();
64
65 } else if (tweet.getInReplyToStatusId() != null) {
66 tweetReferencedId = tweet.getInReplyToStatusId();
67 }
68
69 if (tweetReferencedId != null) {
70
71
72 Tweet mediaTweet = twitter.getTweet(tweetReferencedId);
73
74 if (mediaTweet.getMedia() != null && !mediaTweet.getMedia().isEmpty() && mediaTweet.getMedia().get(0).getType().equals("video")) {
75
76 TweetV2.MediaEntityV2 mediaEntity = (TweetV2.MediaEntityV2) mediaTweet.getMedia().get(0);
77 String thumbnail = mediaEntity.getPreviewImageUrl();
78 String mediaTweetUser = mediaTweet.getUser().getName();
79 String mediaTweetText = mediaTweet.getText();
80 String isSensitive = ""; // temporary
81 String videoUrl = ""; // don't really need it
82
83 boolean shouldReply = true;
84
85 // fix reply bug - a case were the bot replies where it is not intentionally called
86 // on its own video post or retweeted video posts
87
88 if (mediaTweetUser.equalsIgnoreCase(botUsername.split("@")[1]) // get username without @ symbol
89 || mediaTweetUser.equalsIgnoreCase("crazyvideoclips")) {
90 // get number of times the bot appears in a tweet
91 if (getMentionCount(tweet.getText(), botUsername.toLowerCase()) == 1) {
92 shouldReply = false;
93 }
94 }
95
96 if (shouldReply) {
97 DBHelper.saveTweet(tweet.getUser().getName(), tweet.getId(), mediaTweet.getId(), videoUrl, thumbnail, mediaTweetUser, mediaTweetText, isSensitive);
98
99 String userToReply = tweet.getUser().getName();
100 String responseText = tweetMessage(userToReply);
101
102 try {
103 replyTweet(responseText, tweet.getId(), userToReply);
104 } catch (Exception e) {
105
106 if (e.getMessage().contains("User is over daily status update limit")) {
107 System.out.println("limit reached");
108
109 } else {
110 System.out.println(e.getMessage());
111 }
112 }
113 }

Callers

nothing calls this directly

Calls 4

getMentionCountMethod · 0.95
saveTweetMethod · 0.95
tweetMessageMethod · 0.95
replyTweetMethod · 0.95

Tested by

no test coverage detected