@@ -8,8 +8,9 @@ const twit = new Twit(require("./config.js"));
8
8
const mediaArtsSearch = { q : "#MeetMaye" , count : 100 , result_type : "recent" } ;
9
9
10
10
// This function finds the latest tweet with the MeetMaye hashtag and retweets.
11
- const retweetLatest = ( ) => {
12
- twit . get ( "search/tweets" , mediaArtsSearch , ( error , data ) => {
11
+ const retweetLatest = async ( ) => {
12
+ try {
13
+ twit . get ( "search/tweets" , mediaArtsSearch , ( error , data ) => {
13
14
// If our search request to the server had no errors...
14
15
if ( error ) {
15
16
// However, if our original search request had an error, we want to print it out here...
@@ -19,16 +20,20 @@ const retweetLatest = () => {
19
20
const retweetId = data . statuses [ 0 ] . id_str ;
20
21
// Tell Twitter we want to retweet it...
21
22
twit . post ( "statuses/retweet/" + retweetId , { } , ( error , response ) => {
22
- if ( response ) {
23
- console . log ( "Success! Your bot has retweeted something." ) ;
24
- }
23
+
25
24
// If there was an error with our Twitter call, we print it out here...
26
25
if ( error ) {
27
26
console . log ( error . message ) ;
27
+ } else if ( response ) {
28
+ console . log ( "Success! Retweeted!" ) ;
28
29
}
29
30
} ) ;
30
31
}
31
32
} ) ;
33
+ } catch ( error ) {
34
+ // Handle errors...
35
+ console . log ( error )
36
+ }
32
37
} ;
33
38
34
39
// Try to retweet something as soon as we run the program...
0 commit comments