-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
118 lines (102 loc) · 3.99 KB
/
index.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
var config = require('./config.json');
var SlackBot = require('slackbots');
var CronJob = require('cron').CronJob;
var Webhook = require('./webhook');
var webhook = new Webhook();
var website = require("./la1api");
var Clifford = require('./bots/clifford'),
Stephen = require('./bots/stephen'),
Cynthia = require('./bots/cynthia'),
Sarah = require('./bots/sarah');
var stephen,
cynthia,
clifford,
sarah;
var bot = new SlackBot({
token: config.apikey,
name: 'Clifford'
});
bot.on('start', function() {
stephen = new Stephen(bot);
cynthia = new Cynthia(bot);
clifford = new Clifford(bot);
sarah = new Sarah(bot);
//Begin Webhook integration
webhook.on("vod", function(payload) {
website.apiRequest("mediaItems/" + payload.payload.id, function(data) {
var message = data.data.mediaItem.name + " in " + data.data.playlists[0].name + " now has VOD. Watch it at " + data.data.mediaItem.siteUrl + " .... woof!";
clifford.postToChannel('streammonitoring', message, {
as_user: true
});
});
});
//Begin Webhook integration
webhook.on("live", function(payload) {
website.apiRequest("mediaItems/" + payload.payload.id, function(data) {
var message = data.data.mediaItem.name + " in " + data.data.playlists[0].name + " is now live. Watch it at " + data.data.mediaItem.siteUrl + " .... woof!";
clifford.postToChannel('streammonitoring', message, {
as_user: true
});
});
});
//Begin Webhook integration
webhook.on("notLive", function(payload) {
website.apiRequest("mediaItems/" + payload.payload.id, function(data) {
var message = data.data.mediaItem.name + " in " + data.data.playlists[0].name + " is no longer live. " + data.data.mediaItem.siteUrl + " .... woof!";
clifford.postToChannel('streammonitoring', message, {
as_user: true
});
});
});
//Begin Webhook integration
webhook.on("showOver", function(payload) {
website.apiRequest("mediaItems/" + payload.payload.id, function(data) {
var message = data.data.mediaItem.name + " in " + data.data.playlists[0].name + " has now finished. Watch it at " + data.data.mediaItem.siteUrl + " .... woof!";
clifford.postToChannel('streammonitoring', message, {
as_user: true
});
});
});
webhook.on('degradedServiceStateChanged', function(enabled) {
var msg = null;
if (enabled) {
msg = 'The site has gone into degraded service mode :disappointed: .... woof!';
} else {
msg = 'The site has left degraded service mode :smile: .... woof!';
}
clifford.postToChannel('monitoring', msg, {
as_user: true
});
});
var vodUploadCheckJob = new CronJob({
cronTime: '00 00 13 * * *',
onTick: function() {
console.log("Looking for media items missing vod...");
website.apiRequest("mediaItems?sortMode=SCHEDULED_PUBLISH_TIME&sortDirection=DESC&limit=100", function(data) {
var needVod = data.data.mediaItems.filter(function(mediaItem) {
var shouldHaveVod =
// live stream ended and marked as being recorded
(mediaItem.liveStream && mediaItem.liveStream.state === "SHOW_OVER" && mediaItem.liveStream.beingRecorded) ||
// vod scheduled to go live within 2 days
(mediaItem.vod && mediaItem.vod.scheduledPublishTime >= (Date.now()/1000)-172800);
// has vod or vod is currently processing
var hasVod = mediaItem.vod && (mediaItem.vod.processing.completed || !mediaItem.vod.processing.error);
return shouldHaveVod && !hasVod;
});
if (!needVod.length) {
// all good
return
}
var msg = "The following items need VOD uploading:\r\n"+needVod.map(function(mediaItem) {
return "- "+mediaItem.name+" ("+mediaItem.siteUrl+")";
}).join("\r\n")+"\r\n...woof";
clifford.postToChannel('production', msg, {
as_user: true
});
});
},
runOnInit: true,
timeZone: 'Europe/London'
});
vodUploadCheckJob.start();
});