-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter.js
51 lines (46 loc) · 1.18 KB
/
twitter.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
'use strict';
const Twit = require('twit');
const Bobase = require('./lib/Bobase');
class Twitter extends Bobase {
constructor() {
super('twitter');
this.follow = this.config.twitter.follow;
this.T = new Twit(this.config.twitter.api);
}
start() {
this.stream = this.T.stream('statuses/filter', {
follow: this.follow,
});
this.stream.on('error', (error) => {
this.log.error(error);
});
this.stream.on('disconnect', (disconnectMessage) => {
this.log.warn(disconnectMessage);
});
this.stream.on('connect', (r) => {
this.debug(r);
this.log.info('Connecting...');
});
this.stream.on('connected', (r) => {
this.debug(r);
this.log.info('Connected!');
});
this.stream.on('reconnect', (r) => {
this.debug(r);
this.log.info('Re-Connecting...');
});
this.stream.on('warning', (warning) => {
this.log.warn(warning);
});
this.stream.on('tweet', (tweet) => {
if (this.follow.includes(tweet.user.id_str)) {
this.rc.publish('twitter', JSON.stringify(tweet));
}
});
}
stop() {
this.stream.stop();
}
}
const twitter = new Twitter();
twitter.start();