├── Procfile ├── .gitignore ├── config ├── tempConfig.env └── ImportEnv.js ├── .eslintrc.json ├── README.md ├── package.json └── bot.js /Procfile: -------------------------------------------------------------------------------- 1 | worker: node bot.js -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | /config/config.env -------------------------------------------------------------------------------- /config/tempConfig.env: -------------------------------------------------------------------------------- 1 | consumer_key= 2 | consumer_secret= 3 | access_token= 4 | access_token_secret= -------------------------------------------------------------------------------- /config/ImportEnv.js: -------------------------------------------------------------------------------- 1 | const dotenv = require('dotenv'); 2 | 3 | dotenv.config({ path: './config/config.env' }); 4 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es2021": true 5 | }, 6 | "extends": [ 7 | "airbnb-base" 8 | ], 9 | "parserOptions": { 10 | "ecmaVersion": 12, 11 | "sourceType": "module" 12 | }, 13 | "rules": { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | My first Twitter bot(nodejs-bot [@morolswediu](https://twitter.com/morolswediu)) that can retweet and like your tweet, 6 | if you use hashtags 7 | - `#nodejs` 8 | - `#javascript` 9 | - `#100DaysOfCode` 10 | 11 | ### My main purpose is to motivated 👨‍💻 developer 👨‍💻 12 | 13 | If you like, Give a star ⭐ 14 | 15 |

🧡 Support:

16 |

Morol

17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "twitter-bot", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "bot.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node bot.js", 9 | "dev": "nodemon bot.js" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/jinnatul/twitter-bot.git" 14 | }, 15 | "author": "Morol", 16 | "license": "ISC", 17 | "bugs": { 18 | "url": "https://github.com/jinnatul/twitter-bot/issues" 19 | }, 20 | "homepage": "https://github.com/jinnatul/twitter-bot#readme", 21 | "dependencies": { 22 | "dotenv": "^8.2.0", 23 | "twit": "^2.2.11", 24 | "twitter-lite": "^0.14.0" 25 | }, 26 | "devDependencies": { 27 | "eslint": "^7.14.0", 28 | "eslint-config-airbnb-base": "^14.2.1", 29 | "eslint-plugin-import": "^2.22.1", 30 | "nodemon": "^2.0.6" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /bot.js: -------------------------------------------------------------------------------- 1 | require('./config/ImportEnv'); 2 | const Twit = require('twit'); 3 | 4 | const config = { 5 | consumer_key: process.env.consumer_key, 6 | consumer_secret: process.env.consumer_secret, 7 | access_token: process.env.access_token, 8 | access_token_secret: process.env.access_token_secret, 9 | }; 10 | 11 | const Twitter = new Twit(config); 12 | 13 | const retweet = (searchTag) => { 14 | const params = { 15 | q: searchTag, 16 | result_type: 'mixed', 17 | count: 200, 18 | }; 19 | 20 | Twitter.get('search/tweets', params, (srcErr, srcData, srcRes) => { 21 | const tweets = srcData.statuses; 22 | if (!srcErr) { 23 | let tweetIDList = []; 24 | 25 | tweets.forEach((tweet) => { 26 | if (tweet.text.startsWith('RT @')) { 27 | if (tweet.retweeted_status) { 28 | tweetIDList.push(tweet.retweeted_status.id_str); 29 | } else { 30 | tweetIDList.push(tweet.id_str); 31 | } 32 | } else { 33 | tweetIDList.push(tweet.id_str); 34 | } 35 | }); 36 | 37 | // Filter unique tweet IDs. 38 | tweetIDList = tweetIDList.filter((value, index, self) => self.indexOf(value) === index); 39 | 40 | tweetIDList.forEach((tweetID) => { 41 | // Retweet 42 | Twitter.post('statuses/retweet/:id', { 43 | id: tweetID, 44 | }, (rtErr, rtData, rtRes) => { 45 | if (!rtErr || rtData) { 46 | console.log(`\n\nRetweeted! ID - ${tweetID}`); 47 | } else { 48 | console.log(`\nError... Duplication maybe... ${tweetID}`); 49 | } 50 | }); 51 | 52 | /* 53 | // Like a tweet 54 | Twitter.post('favorites/create', { 55 | id: tweetID, 56 | }) 57 | .then(() => { 58 | console.log('Liked tweet successfully!'); 59 | }).catch(() => { 60 | console.log('Already Liked this tweet.'); 61 | }); 62 | */ 63 | }); 64 | } else { 65 | console.log(`Error while searching: ${srcErr}`); 66 | process.exit(1); 67 | } 68 | }); 69 | }; 70 | 71 | // Run every 60 seconds 72 | setInterval(() => { 73 | retweet('#javascript OR #nodejs OR #100DaysOfCode OR #NanoSoft'); 74 | }, 60000); 75 | --------------------------------------------------------------------------------