-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
91 lines (63 loc) · 1.92 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const Twitter = require('twit');
const config = require('./config/congif.js');
var T = new Twitter(config);
// Fethcing our Own user ID.
const getBotId = async ()=>{
const result = await T.get('account/verify_credentials');
let botId = result['data']['id_str'];
return botId;
};
getBotId().then((ourBotId)=>{
let queries = ['#javascript', '#100DaysOfCode'];
console.log(ourBotId);
});
function likeATweet(tweet, botId){
console.log("before liking", botId);
T.post('/2/users/:id/likes', { 'id': botId, 'tweet_id': tweet['id_str'] })
.catch((err) => {
console.log("Oh damn, here we go again");
console.log(err);
});
}
function searchingForTweets(T, queries, botId){
return new Promise((resolve, reject)=>{
T.get('search/tweets', {
q: queries[1],
result_type: 'recent',
count: 1,
lang: 'en'
}).then(async (result) => {
const resultTweets = result['data'].statuses;
resolve(resultTweets);
}).catch((err) => {
console.log('OOPS This went a bit rough.');
reject(err);
});
})
}
function postAStatus(T, status){
T.post('statuses/update', {
status: status
}).then((result) => {
console.log(result['data']);
console.log('Tweeted Successfully');
}).catch((err) => {
console.log('OOPS an error occurred');
console.log(err.stack);
})
}
function retweetATweet(T, tweet){
T.post('statuses/retweet/:id', { id: tweet['id_str'] })
.catch((err) => {
console.log('Something horrible happened');
console.log(err);
process.exit(1);
});
}
function searchAndRetweet(T, queries, ourBotId){
searchingForTweets(T, queries, ourBotId).then((resultTweets) => {
for (tweet of resultTweets) {
retweetATweet(T, tweet);
}
})
}