Created
May 22, 2022 09:56
-
-
Save tajuszk/e8854e7bcf5f0a39743fb571b00ffa21 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ③最新のツイートをリツイートする | |
*/ | |
function retweetLatest () { | |
// 最新のツイートのツイートIDを取得する | |
const accountName = 'belltreeszk' // 対象のアカウントの @~~~~ の部分を記入 | |
const includeRT = false // RTを含むか(他のユーザーのツイートのRTも再度RTします) | |
const retweetCount = 3 // 直近何件のツイートをRTするか | |
const tweetIds = client.pickupTweetsLatest(accountName, includeRT, retweetCount); | |
// 特定のURLが含まれているものを除く | |
const tweetShowUrl = 'https://api.twitter.com/1.1/statuses/show.json'; | |
const ignoreUrls = ['bit.ly'] | |
for (let i = tweetIds.length - 1; i >= 0; i--) { | |
const tweetShowParam = { | |
id: tweetIds[i], | |
tweet_mode: 'extended' // URLが省略されていることがあるので | |
} | |
const tweetShowResult = client.getRequest(tweetShowUrl, tweetShowParam); | |
const urls = tweetShowResult.entities.urls; | |
const includedTweets = urls.filter((url) => { | |
for (let i in ignoreUrls) { | |
const ignoreUrl = ignoreUrls[i]; | |
if (url.expanded_url.indexOf(ignoreUrl) !== -1) { | |
return true; | |
} | |
} | |
return false; | |
}) | |
// ここでURLの有無をチェック | |
if (includedTweets.length > 0) { | |
tweetIds.splice(i, 1); | |
} | |
} | |
// 受け取ったツイートIDのツイートをすべてリツイートする | |
client.retweet(tweetIds) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment