Commit
·
c7cf68e
1
Parent(s):
1706ad4
server.ts
CHANGED
@@ -53,11 +53,14 @@ async function ff(url: string) {
|
|
53 |
return await resp.json();
|
54 |
}
|
55 |
|
56 |
-
let
|
|
|
57 |
|
58 |
async function lookupTweets() {
|
59 |
const data: TweetMentions = await ff(
|
60 |
-
`users/${BOT_ID}/mentions?${
|
|
|
|
|
61 |
);
|
62 |
|
63 |
let lookups: TweetLookups = await ff(
|
@@ -68,15 +71,21 @@ async function lookupTweets() {
|
|
68 |
)}&tweet.fields=created_at&expansions=attachments.media_keys&media.fields=duration_ms,height,media_key,preview_image_url,public_metrics,type,url,width,alt_text`
|
69 |
);
|
70 |
|
71 |
-
if (!
|
72 |
-
console.log("added mention", lookups.data[0].created_at);
|
73 |
-
|
|
|
74 |
return lookupTweets();
|
75 |
}
|
76 |
-
lastMention = lookups.data[0].created_at;
|
77 |
|
78 |
-
const tweets = lookups.data.filter(
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
for (const tweet of tweets) {
|
82 |
const imageUrl = lookups.includes.media.find((media) => media.media_key === tweet?.attachments!.media_keys[0])
|
|
|
53 |
return await resp.json();
|
54 |
}
|
55 |
|
56 |
+
let lastCreatedAt = "";
|
57 |
+
let lastMentionedTweet = "";
|
58 |
|
59 |
async function lookupTweets() {
|
60 |
const data: TweetMentions = await ff(
|
61 |
+
`users/${BOT_ID}/mentions?${
|
62 |
+
lastCreatedAt && `start_time=${new Date(new Date(lastCreatedAt).getTime() + 1).toJSON()}`
|
63 |
+
}`
|
64 |
);
|
65 |
|
66 |
let lookups: TweetLookups = await ff(
|
|
|
71 |
)}&tweet.fields=created_at&expansions=attachments.media_keys&media.fields=duration_ms,height,media_key,preview_image_url,public_metrics,type,url,width,alt_text`
|
72 |
);
|
73 |
|
74 |
+
if (!lastCreatedAt) {
|
75 |
+
console.log("added mention", lookups.data[0].created_at, lookups.data[0].id);
|
76 |
+
lastCreatedAt = lookups.data[0].created_at;
|
77 |
+
lastMentionedTweet = lookups.data[0].id;
|
78 |
return lookupTweets();
|
79 |
}
|
|
|
80 |
|
81 |
+
const tweets = lookups.data.filter(
|
82 |
+
(tweet) => tweet.attachments?.media_keys.length === 1 && tweet.id > lastMentionedTweet
|
83 |
+
);
|
84 |
+
if (tweets.length) {
|
85 |
+
lastCreatedAt = lookups.data[0].created_at;
|
86 |
+
lastMentionedTweet = lookups.data[0].id;
|
87 |
+
}
|
88 |
+
console.log(lastCreatedAt);
|
89 |
|
90 |
for (const tweet of tweets) {
|
91 |
const imageUrl = lookups.includes.media.find((media) => media.media_key === tweet?.attachments!.media_keys[0])
|