Skip to content

Commit 67735c2

Browse files
author
Maye Edwin
committed
Updated code => better logging mechanisms
1 parent dbe03b4 commit 67735c2

File tree

3 files changed

+455
-20
lines changed

3 files changed

+455
-20
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
node_modules/
1+
bot/node_modules/
22
bot/config.js
33
Docs.md

bot/bot.js

+13-18
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,35 @@
11
// Our Twitter library
22
const Twit = require("twit");
33

4-
// We need to include our configuration file
4+
// We need to include our configuration file...
55
const twit = new Twit(require("./config.js"));
66

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

1010
// This function finds the latest tweet with the MeetMaye hashtag and retweets.
1111
const retweetLatest = () => {
1212
twit.get("search/tweets", mediaArtsSearch, (error, data) => {
13-
// log out any errors and responses
14-
console.log(error, data);
1513
// If our search request to the server had no errors...
16-
if (!error) {
17-
// ...then we grab the ID of the tweet we want to retweetwit...
18-
let retweetId = data.statuses[0].id_str;
19-
// ...and then we tell Twitter we want to retweet it!
14+
if (error) {
15+
// However, if our original search request had an error, we want to print it out here...
16+
console.log(error.message);
17+
} else {
18+
// Grab the ID of the tweet we want to retweetwit...
19+
const retweetId = data.statuses[0].id_str;
20+
// Tell Twitter we want to retweet it...
2021
twit.post("statuses/retweet/" + retweetId, {}, (error, response) => {
2122
if (response) {
22-
console.log(
23-
"Success! Check your bot, it should have retweeted something."
24-
);
23+
console.log("Success! Your bot has retweeted something.");
2524
}
26-
// If there was an error with our Twitter call, we print it out here.
25+
// If there was an error with our Twitter call, we print it out here...
2726
if (error) {
28-
console.log("There was an error with Twitter:", error);
27+
console.log(error.message);
2928
}
3029
});
3130
}
32-
// However, if our original search request had an error, we want to print it out here.
33-
else {
34-
console.log("There was an error with your hashtag search:", error);
35-
}
3631
});
37-
}
32+
};
3833

3934
// Try to retweet something as soon as we run the program...
4035
retweetLatest();

0 commit comments

Comments
 (0)