Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tajuszk/cebfff2a05c6a74906b5f072661ed2bd to your computer and use it in GitHub Desktop.
Save tajuszk/cebfff2a05c6a74906b5f072661ed2bd to your computer and use it in GitHub Desktop.
/**
* ③最新のツイートをリツイートする
*/
function retweetLatest () {
// 最新のツイートのツイートIDを取得する
const accountName = 'belltreeszk'; // 対象のアカウントの @~~~~ の部分を記入
const includeRT = false; // RTを含むか(他のユーザーのツイートのRTも再度RTします)
const retweetCount = 3; // 直近何件のツイートをRTするか
const ignoreWords = ['#駆け出しエンジニアと繋がりたい', '#今日の積み上げ']; // 無視したい単語を入力する。カンマ(,)区切りで複数指定OK
const tweetIds = client.pickupTweetsLatest(accountName, includeRT, retweetCount);
// 既にRTされているものは外す
const tweetShowUrl = 'https://api.twitter.com/1.1/statuses/show.json';
for (let i = tweetIds.length - 1; i >= 0; i--) {
const tweetShowParam = {
id: tweetIds[i],
}
const tweetShowResult = client.getRequest(tweetShowUrl, tweetShowParam);
// 単語をチェックして含まれたものを集める
const includedWords = ignoreWords.filter((word) => {
return tweetShowResult.text.indexOf(word) !== -1;
})
// 1つ以上あったら除外する(応用すれば含まれているものだけをRTすることもOK)
if (includedWords.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