Skip to content

Commit

Permalink
Refactot to arrow functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeedwin committed Apr 28, 2020
1 parent 381d098 commit da23818
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions bot/retweetbot.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
// Our Twitter library
var Twit = require('twit');
const Twit = require("twit");

// We need to include our configuration file
var T = new Twit(require('./config.js'));
const twit = new Twit(require("./config.js"));

// This is the URL of a search for the latest tweets on the '#MeetMaye' hashtag.
var mediaArtsSearch = {q: "#MeetMaye", count: 100, result_type: "recent"};
const mediaArtsSearch = { q: "#MeetMaye", count: 100, result_type: "recent" };

// This function finds the latest tweet with the #mediaarts hashtag, and retweets it.
function retweetLatest() {
T.get('search/tweets', mediaArtsSearch, function (error, data) {
// log out any errors and responses
console.log(error, data);
// If our search request to the server had no errors...
if (!error) {
// ...then we grab the ID of the tweet we want to retweet...
var retweetId = data.statuses[0].id_str;
// ...and then we tell Twitter we want to retweet it!
T.post('statuses/retweet/' + retweetId, { }, function (error, response) {
if (response) {
console.log('Success! Check your bot, it should have retweeted something.')
}
// If there was an error with our Twitter call, we print it out here.
if (error) {
console.log('There was an error with Twitter:', error);
}
})
}
// However, if our original search request had an error, we want to print it out here.
else {
console.log('There was an error with your hashtag search:', error);
}
});
// This function finds the latest tweet with the MeetMaye hashtag and retweets.
const retweetLatest = () => {
twit.get("search/tweets", mediaArtsSearch, (error, data) => {
// log out any errors and responses
console.log(error, data);
// If our search request to the server had no errors...
if (!error) {
// ...then we grab the ID of the tweet we want to retweetwit...
let retweetId = data.statuses[0].id_str;
// ...and then we tell Twitter we want to retweet it!
twit.post("statuses/retweet/" + retweetId, {}, (error, response) => {
if (response) {
console.log(
"Success! Check your bot, it should have retweeted something."
);
}
// If there was an error with our Twitter call, we print it out here.
if (error) {
console.log("There was an error with Twitter:", error);
}
});
}
// However, if our original search request had an error, we want to print it out here.
else {
console.log("There was an error with your hashtag search:", error);
}
});
}

// Try to retweet something as soon as we run the program...
retweetLatest();
// ...and then every hour/half after that. Time here is in milliseconds, so
// ...and then every hour/half thereafter. Time here is in milliseconds, so
// 1000 ms = 1 second, 1 sec * 60 = 1 min, 1 min * 60 = 1 hour --> 1000 * 60 * 60
setInterval(retweetLatest, 1000 * 60 * 30);
setInterval(retweetLatest, 1000 * 60 * 30);

0 comments on commit da23818

Please sign in to comment.