-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextension.js
68 lines (60 loc) · 2.75 KB
/
extension.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
'use strict';
module.exports = function (nodecg) {
if (!nodecg.bundleConfig) {
nodecg.log.error('cfg/ss-twitter.json was not found. ' +
'This file is where the Twitter API keys are set. ' +
'Without those, the Twitter graphic cannot function.');
return;
} else if (typeof nodecg.bundleConfig.consumerKey === 'undefined') {
nodecg.log.error('consumerKey is not defined in cfg/ss-twitter.json! ' +
'This key (obtained from your Twitter developer account) ' +
' is required for the Twitter graphic to function.');
return;
} else if (typeof nodecg.bundleConfig.consumerSecret === 'undefined') {
nodecg.log.error('consumerSecret is not defined in cfg/ss-twitter.json! ' +
'This secret (obtained from your Twitter developer account) ' +
' is required for the Twitter graphic to function.');
return;
} else if (typeof nodecg.bundleConfig.accessTokenKey === 'undefined') {
nodecg.log.error('accessTokenKey is not defined in cfg/ss-twitter.json! ' +
'This key (obtained from your Twitter developer account) ' +
' is required for the Twitter graphic to function.');
return;
} else if (typeof nodecg.bundleConfig.accessTokenSecret === 'undefined') {
nodecg.log.error('accessTokenSecret is not defined in cfg/ss-twitter.json! ' +
'This secret (obtained from your Twitter developer account) ' +
' is required for the Twitter graphic to function.');
return;
}
var Twitter = require('twitter');
var twitter = new Twitter({
consumer_key: nodecg.bundleConfig.consumerKey,
consumer_secret: nodecg.bundleConfig.consumerSecret,
access_token_key: nodecg.bundleConfig.accessTokenKey,
access_token_secret: nodecg.bundleConfig.accessTokenSecret
});
var tweetShowing = nodecg.Replicant('tweetShowing', {defaultValue: false, persistent: false});
var tweetPulsing = nodecg.Replicant('tweetPulsing', {defaultValue: false, persistent: false});
var tweet = nodecg.Replicant('tweet', {defaultValue: {}});
nodecg.listenFor('getTweet', function(url) {
var id = url.split('/').pop();
twitter.get('statuses/show', {id: id, include_my_retweet: false}, function(error, tw){
if (error) {
nodecg.log.error('Couldn\'t get tweet:', error[0].message);
return;
}
tweet.value = tw;
});
});
nodecg.listenFor('pulseTweet', function pulse(duration) {
// Don't stack pulses
if (tweetPulsing.value) return;
tweetShowing.value = true;
tweetPulsing.value = true;
// End pulse after "duration" seconds
setTimeout(function() {
tweetShowing.value = false;
tweetPulsing.value = false;
}, duration * 1000);
});
};