From 0b43b5d193381fe0a4c2844e370d3dd7d456b74a Mon Sep 17 00:00:00 2001 From: grant Date: Fri, 15 Dec 2023 13:29:19 -0600 Subject: [PATCH 1/2] fixing twitter bot error --- src/Classes/TwitterBot.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Classes/TwitterBot.ts b/src/Classes/TwitterBot.ts index e6b35b7..fe3483b 100644 --- a/src/Classes/TwitterBot.ts +++ b/src/Classes/TwitterBot.ts @@ -90,10 +90,12 @@ export class TwitterBot { const query = `(to:${ARTBOT_TWITTER_HANDLE} OR @${ARTBOT_TWITTER_HANDLE}) -is:retweet -has:links has:mentions -from:${STATUS_TWITTER_HANDLE} -from:${ARTBOT_TWITTER_HANDLE}` const devQuery = `to:ArtbotTesting from:ArtbotTesting` + console.log(this.lastTweetId) artbotTweets = await this.twitterClient.v2.search({ query: prod ? query : devQuery, since_id: this.lastTweetId, }) + console.log(artbotTweets) } catch (error) { if ( error instanceof ApiResponseError && @@ -103,6 +105,16 @@ export class TwitterBot { console.log( `Search rate limit hit! Limit will reset at timestamp ${error.rateLimit.reset}` ) + } else if ( + error?.code === 400 && + error.errors[0] && + error.errors[0]?.message && + error.errors[0]?.message.includes('since_id') + ) { + const messageSplit = error.errors[0]?.message.split(' ') + const lastId = messageSplit[messageSplit.length - 1] + console.log('TwitterBot since_id is invalid - setting to', lastId) + this.lastTweetId = lastId } else { console.error('Error searching Twitter:', error) } From 4f61d618ce4678859dfebacefed6e6883575344c Mon Sep 17 00:00:00 2001 From: grant Date: Fri, 15 Dec 2023 13:30:27 -0600 Subject: [PATCH 2/2] fixing --- src/Classes/TwitterBot.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Classes/TwitterBot.ts b/src/Classes/TwitterBot.ts index fe3483b..93ecd09 100644 --- a/src/Classes/TwitterBot.ts +++ b/src/Classes/TwitterBot.ts @@ -90,12 +90,10 @@ export class TwitterBot { const query = `(to:${ARTBOT_TWITTER_HANDLE} OR @${ARTBOT_TWITTER_HANDLE}) -is:retweet -has:links has:mentions -from:${STATUS_TWITTER_HANDLE} -from:${ARTBOT_TWITTER_HANDLE}` const devQuery = `to:ArtbotTesting from:ArtbotTesting` - console.log(this.lastTweetId) artbotTweets = await this.twitterClient.v2.search({ query: prod ? query : devQuery, since_id: this.lastTweetId, }) - console.log(artbotTweets) } catch (error) { if ( error instanceof ApiResponseError &&