-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (43 loc) · 1.37 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
const Twitter = require('twitter');
const say = require('say');
var config = require('./config.json');
var client = new Twitter(config.client_auth);
var regex = /^((\d)+\'|full-time|half-time|ht|ft).+/igm;
console.log("⚽️\t🇮🇹\tForza Juve!\t🇮🇹\t⚽️ \nJuve Commentator\t🎤\tNow running....");
var queue = [];
client.stream(config.api, config.api_params, function(stream){
stream.on('data', function(tweet) {
var text = tweet.text;
if(text.match(regex) != null){
var mentions = tweet.entities.user_mentions;
if(mentions!=null && mentions.length>0){
mentions.forEach(function(mention){
var handle = '@'+mention.screen_name;
var fullName = mention.name;
text = text.replace(handle, fullName);
});
}
if(text.includes('#')){
while(text.includes('#')){
text = text.replace('#', 'Hash Tag ');
}
}
var urls = tweet.entities.urls;
if(urls!=null && urls.length>0){
urls.forEach(function(url){
text = text.replace(url.url, ' ');
});
}
queue.push(text);
var i = queue.shift();
console.log("Speaking.... "+tweet.user.name + " says " + i);
say.speak(i);
}
else {
console.error(tweet.user.name + " says "+text);
}
});
stream.on('error', function(error) {
console.log(error);
});
});