-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
70 lines (54 loc) · 2.16 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
const Twit = require('twit');
const schedule = require('node-schedule');
const twit_config = require('./src/config').twit_config;
const gif = require('./src/gif');
const tweet = require('./src/tweet');
const T = new Twit(twit_config);
let user_stream = T.stream('user');
console.log("User stream has started..\n");
user_stream.on('follow', followed);
console.log("Daily gif stream has started..");
var j = schedule.scheduleJob('00 18 * * *', daily_trending_gif);
function daily_trending_gif(){
console.log('Posting today\'s gif..');
tweet.get_trending_topic(T, {id: '23424977'})
.then(response => {
const isHashtag = response.topic.indexOf('#') > -1;
let topic = response.topic.replace('#', '');
console.log(`Trending topic of ${response.date} is '${response.topic}'\n`);
topic = topic.charAt(0).toLowerCase() + topic.slice(1);
topic = topic.replace( /([A-Z])/g, " $1" ).toLowerCase().split(' ').join('+');
let date = response.date.split(' ').join('+');
const gif_search_key = topic;// + '+' + date;
console.log(gif_search_key);
let tweet_status = `Today's gif #bottweetsgifs ${response.topic}`;
post_tweet(gif_search_key, tweet_status, 'daily');
});
}
function followed(event) {
const screen_name = event.source.screen_name;
console.log(`Dude, this guy @${screen_name} checking us!`);
post_tweet('thanks', `Hey @${screen_name}, how u doin? text me anytime #bottweetsgifs`, 'thanks', true);
}
function post_tweet(gif_search_key, status, gif_file_name, random = false){
gif.search_gif(gif_search_key, random, 10)
.then(gif_url => {
return gif.download_gif(gif_url, gif_file_name);
})
.then(gif_location => {
return tweet.upload_gif_to_twitter(T, gif_location);
})
.then( data => {
let tweet_params = {
status: status,
media_ids : [data.media_id_string],
};
return tweet.post_status(T, tweet_params);
})
.then(data => {
console.log('Tweet has been posted..');
})
.catch(err => {
console.log('An error occurred..');
});
}