-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
executable file
·122 lines (105 loc) · 3.47 KB
/
bot.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*!
* Bot.js : A Twitter bot that can retweet in response to the tweets matching particluar keyword
* Version 1.0.0
* Created by Debashis Barman (http://www.debashisbarman.in)
* License : http://creativecommons.org/licenses/by-sa/3.0
*/
/* Configure the Twitter API */
var TWITTER_CONSUMER_KEY = 'XGlpjA30aisbh4w4kn5ppioF7';
var TWITTER_CONSUMER_SECRET = 'PW7zvG6oQ9yP14F21i4AK8dFQ0A801bbHWAYzE51sQiFqiLWTw';
var TWITTER_ACCESS_TOKEN = '1051406254424420352-hdJokCjXkxbw9D7XzINaLPbllil2Vd';
var TWITTER_ACCESS_TOKEN_SECRET = 'hSyp8NtbfxJyZADRLd7VDDLQ5hLog0VN53tdXmcKKFjBb';
/* Set Twitter search phrase */
var TWITTER_SEARCH_PHRASE = 'Paris PSG';
var Twit = require('twit');
var Bot = new Twit({
consumer_key: TWITTER_CONSUMER_KEY,
consumer_secret: TWITTER_CONSUMER_SECRET,
access_token: TWITTER_ACCESS_TOKEN,
access_token_secret: TWITTER_ACCESS_TOKEN_SECRET
});
console.log('The bot is running...');
/* BotInit() : To initiate the bot */
function BotInit() {
deleteUser();
BotRetweet();
}
function deleteUser() {
var query = {
screen_name: 'PSGInMyBlood',
count: 100
};
console.log(query + '\n');
Bot.get('friends/ids', query, unfollow);
function unfollow(error, data, response) {
if (error) {
console.log(error);
console.log('pas get\n');
}
else {
for (user of data.ids) {
var id = {
user_id: user
}
Bot.post('friendships/destroy', id, work);
function work(error, data, response) {
if (error) {
console.log('error')
} else {
console.log('unfollow')
}
}
}
}
}
}
/* BotRetweet() : To retweet the matching recent tweet */
function BotRetweet() {
var query = {
q: TWITTER_SEARCH_PHRASE,
result_type: "recent",
}
Bot.get('search/tweets', query, BotGotLatestTweet);
function BotGotLatestTweet (error, data, response) {
if (error) {
console.log('-------------------');
console.log('Bot could not find latest tweet. ' + error);
console.log('-------------------');
}
else {
for (tweet of data.statuses) {
var id = {
id: tweet.id_str,
message: tweet.message
}
var rt = {
user_id: tweet.user.id
}
Bot.post('statuses/retweet/:id', id, BotRetweeted);
Bot.post('friendships/create', rt, lookRt);
function lookRt(error, response) {
if (error) {
console.log('error = ' + error);
} else {
console.log('sucess = ' + response)
}
}
function BotRetweeted(error, response) {
if (error) {
console.log(id.id);
console.log('Bot could not retweet, : ' + error);
}
else {
console.log('-------------------------');
console.log('Bot retweeted : ' + id.id);
console.log(id.message);
console.log('-------------------------');
}
}
}
}
}
}
setInterval(BotRetweet, 5*60*1000);
setInterval(deleteUser, 60*60*1000);
BotInit();