-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
694 lines (605 loc) · 24.5 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
/**
* Created by eslam on 13.01.16.
*/
/**
* required modules
* @type {exports|module.exports}
*/
var fs = require('fs');
var SQLite = require('sqlite3').verbose();
var Lucy = require('slackbots');
var schedule = require('node-schedule');
var winston = require('winston');
var request = require('request');
var json = require('json');
var http = require('http');
var https = require('https');
var ffmpeg = require('fluent-ffmpeg');
// var video_config = require("./config.js");
var work_dir = '/home/zoobe/lucy/';
winston.add(
winston.transports.File, {
filename: work_dir + '/logs/logfile.log',
level: 'info',
json: true,
eol: 'rn', // for Windows, or `eol: ‘n’,` for *NIX OSs
timestamp: true
}
);
winston.log('info', 'Start of the bot.');
// create a bot
//slack_token = process.env.SLACK_API_TOKEN;
slack_token = 'xoxb-15921234150-SIhR1hgyvyw3xrxgx3oMtuO1';
var settings = {
token: slack_token,
name: 'Lucy'
};
if (settings.token === undefined) {
console.error("SLACK_TOKEN environment variable is not defined");
}
var lucy = new Lucy(settings);
lucy.dbPath = work_dir +'data/lucy.db';
/**
* Flag for the environment
* @type {boolean}
*/
var debug = false;
/**
* settings for debug and live environment;
*/
if (debug === true) {
var config = {
MONDAY: 5,
TUESDAY: 5,
WEDNESDAY: 5,
MONDAYMESSAGE_HOUR: 16,
MONDAYMESSAGE_MINUTE: 45,
MONDAYMESSAGE_SECOND: 00,
TUESDAYSALADMESSAGE_HOUR: 16,
TUESDAYSALADMESSAGE_MINUTE: 50,
TUESDAYSALADMESSAGE_SECOND: 05,
WEDNESDAYSMOOTHIEMESSAGE_HOUR: 16,
WEDNESDAYSMOOTHIEMESSAGE_MINUTE: 53,
WEDNESDAYSMOOTHIEMESSAGE_SECOND: 12,
MONDAYMESSAGEPAYCHECK_HOUR: 16,
MONDAYMESSAGEPAYCHECK_MINUTE: 47,
CHAT_ROOM: 'smoothieforlucy',
USER_TO_REPORT_TO: 'eslam.shala'
};
}
else {
var config = {
MONDAY: 1,
TUESDAY: 2,
WEDNESDAY: 3,
MONDAYMESSAGE_HOUR: 10,
MONDAYMESSAGE_MINUTE: 00,
MONDAYMESSAGE_SECOND: 00,
TUESDAYSALADMESSAGE_HOUR: 12,
TUESDAYSALADMESSAGE_MINUTE: 30,
TUESDAYSALADMESSAGE_SECOND: 09,
WEDNESDAYSMOOTHIEMESSAGE_HOUR: 09,
WEDNESDAYSMOOTHIEMESSAGE_MINUTE: 30,
WEDNESDAYSMOOTHIEMESSAGE_SECOND: 17,
MONDAYMESSAGEPAYCHECK_HOUR: 11,
MONDAYMESSAGEPAYCHECK_MINUTE: 00,
CHAT_ROOM: 'smoothiesandsalads',
USER_TO_REPORT_TO: 'smonicats'
};
}
/**
* On start callback, called when lucy connects to Slack server
*/
lucy.on('start', function () {
winston.log('info', 'on start method');
lucy._connectDb();
lucy._firstRunCheck();
lucy._mondayMessage();
//lucy._feedbackToMonica();
lucy._tuesdaySaladMessage();
lucy._wednesdaySmoothieMessage();
lucy._payCheck();
});
/**
* On message callback, called when a message (of any type) is detected with the real time messaging API
*/
lucy.on('message', function (message) {
winston.log('info', 'on message method.');
var currentDay = new Date().getDay(); // returns an integer, 0 for sun, 1 for mon, 2 for tue
if (this._isChatMessage(message) &&
this._isDirectConversationToLucy(message) && !this._isFromLucyBot(message)) { // check if the day is monday
// @TODO: change the 3 into 1; where 3 is for wednesday and 1 is for monday
winston.log('info', 'is chat message and a direct conv to lucy and not from lucy.');
//console.log(message);
this._inOrOutForSmoothie(message, currentDay);
}
});
/**
* Check if it's the first time for the bot to run. If so, it sends a welcome message to the Channel.
* @private
*/
lucy._firstRunCheck = function () {
winston.log('info', 'this is my first run check.');
var self = this;
self.db.get('SELECT val FROM info WHERE name = "lastrun" LIMIT 1', function (err, record) {
if (err) {
winston.log('error', 'database error' + err);
return console.error('DATABASE ERROR:', err);
}
var currentTime = (new Date()).toJSON();
// this is a first run
if (!record) {
winston.log('info', 'Not a record');
self._welcomeMessage();
return self.db.run('INSERT INTO info(name, val) VALUES("lastrun", ?)', currentTime);
}
// updates with new last running time
self.db.run('UPDATE info SET val = ? WHERE name = "lastrun"', currentTime);
});
};
/**
* Sends a welcome message to the channel
* @private
*/
lucy._welcomeMessage = function () {
lucy.postMessageToChannel(config.CHAT_ROOM, 'My name is Lucy and it is super nice to meet all of you on my first day! I am supposed to help Monica with the Smoothies and Salad. However, there is no limit to what I can do. Hopefully, one day I will be able to deliver coffee to your very own desk.', {as_user: true});
};
/**
* Opens connection to the database
* @private
*/
lucy._connectDb = function () {
if (!fs.existsSync(this.dbPath)) {
console.error('Database path ' + '"' + this.dbPath + '" does not exists or it\'s not readable.');
process.exit(1);
}
this.db = new SQLite.Database(this.dbPath);
this._setupDb(this.db);
};
/**
* Initialize the database tables for the first run
* @param db
* @private
*/
lucy._setupDb = function (db) {
db.serialize(function () {
console.log("creating table");
db.run('CREATE TABLE IF NOT EXISTS info (name TEXT PRIMARY KEY, val TEXT DEFAULT NULL)');
db.run('CREATE TABLE IF NOT EXISTS saladrecord(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username TEXT NOT NULL, date TEXT NOT NULL, interested INTEGER DEFAULT NULL, paid INTEGER DEFAULT NULL)');
db.run('CREATE TABLE IF NOT EXISTS talktolucy(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username TEXT NOT NULL, date TEXT NOT NULL, text TEXT)');
db.run('CREATE TABLE IF NOT EXISTS user(id TEXT PRIMARY KEY NOT NULL, token TEXT NOT NULL)');
console.log("table created");
})
};
/**
* Checks if the username of the message is Lucy
* @param message
* @returns {boolean}
* @private
*/
lucy._isFromLucyBot = function (message) {
return message.username === 'Lucy' || message.user === lucy.self.id;
};
/**
* checks if the username of the message is Eslam
* @param message
* @returns {boolean}
* @private
*/
lucy._isFromEslam = function (message) {
var users = lucy.getUsers();
var user = this.getUserById(message.user,users);
return user.name === 'eslam.shala';
};
/**
* Checks if the User is the Bot/Lucy
* @param user
* @returns {boolean}
* @private
*/
lucy._userIsLucy = function (user) {
return user.name === 'lucy';
};
/**
* Util function to check if a given real time message object represents a chat message
* @param message
* @returns {boolean}
* @private
*/
lucy._isChatMessage = function (message) {
return message.type === 'message' && Boolean(message.text);
};
/**
* Util function ot check if a given real time message is being sent directly to Lucy
* @param message
* @returns {boolean}
* @private
*/
lucy._isDirectConversationToLucy = function (message) {
return typeof message.channel === 'string' &&
message.channel[0] === 'D';
};
/**
* Check if someone is mentioning Lucy in any of the chats
* @param message
* @returns {boolean}
* @private
*/
lucy._isMentioningLucy = function (message) {
return message.text.toLowerCase().indexOf('lucy') > -1
};
//@TODO: create a settings file for debug and live mode where in debug the channel should be 'smoothieforlucy' and in live it should be 'smoothiesandsalads'
/**
* Get users in the S&S channel.
* @param channels
* @returns {*|Array}
*/
lucy.getSSUsers = function (channels) {
var index;
for (var i = 0; i < channels._value.channels.length; i++) {
if (channels._value.channels[i].name === config.CHAT_ROOM) {
index = i;
break;
}
}
var result = channels._value.channels[index].members;
if (result === undefined) {
console.error("The bot is not in the specified room");
process.exit(1);
process.exit(1);
}
return result;
};
/**
* Gets user details by providing his/her ID
* @param userId
* @param users
* @returns {*}
*/
lucy.getUserById = function (userId, users) {
var index;
for (var i = 0; i < users._value.members.length; i++) {
if (userId === users._value.members[i].id) {
index = i;
break;
}
}
var result = users._value.members[index];
return result;
};
/**
* Checks if user paid or not based on a schedule
* @private
*/
lucy._payCheck = function () {
var payCheckSchedule = new schedule.RecurrenceRule();
payCheckSchedule.second = config.MONDAYMESSAGE_SECOND;
payCheckSchedule.minute = config.MONDAYMESSAGEPAYCHECK_MINUTE;
payCheckSchedule.dayOfWeek = config.MONDAY;
payCheckSchedule.hour = [config.MONDAYMESSAGEPAYCHECK_HOUR, new schedule.Range(10, 15)];
schedule.scheduleJob(payCheckSchedule, function () {
var date = new Date();
var currentDate = date.getDate().toString() + date.getMonth().toString() + date.getFullYear().toString();
lucy.db.each('SELECT id, username, interested, paid FROM saladrecord WHERE date=\'' + currentDate + '\'', function (err, record) {
if (err) {
return console.error('DATABASE ERROR: ' + err);
}
if (record.interested === 1 && record.paid === null) {
lucy.postMessageToUser(record.username, "Did you pay Monica the S&S money?", {as_user: true});
}
});
});
};
/**
* Sends a msgs to users in a channel asking if they are interested to register for S&S this week.
* @private
*/
lucy._mondayMessage = function () {
//@TODO: Add Berlin TimeZone
var mondaySchedule = new schedule.RecurrenceRule();
// schedule the message for mondays at 9:45am
mondaySchedule.second = config.MONDAYMESSAGE_SECOND;
mondaySchedule.minute = config.MONDAYMESSAGE_MINUTE;
mondaySchedule.hour = config.MONDAYMESSAGE_HOUR;
mondaySchedule.dayOfWeek = config.MONDAY; // 1 is for mondays
schedule.scheduleJob(mondaySchedule, function () {
var users = lucy.getUsers();
var channels = lucy.getChannels();
var channelUsers = lucy.getSSUsers(channels);
var date = new Date();
var currentDate = date.getDate().toString() + date.getMonth().toString() + date.getFullYear().toString();
for (var i = 0; i < channelUsers.length; i++) {
var user = lucy.getUserById(channelUsers[i], users);
if (!lucy._userIsLucy(user)) {
// 1 - create a DB entry with the username
var insertStatement = 'INSERT INTO saladrecord(username, date) VALUES ("' + user.name + '", ' + '"' + currentDate + '"' + ');';
lucy.db.run(insertStatement);
// 2 - send a private message to each user if they want to register for SS this week
var messageToUser = "Good morning " + user.name + "! \n Would you like to register for the S&S this week? :-) you can answer with yes/no";
lucy.postMessageToUser(user.name, messageToUser, {as_user: true});
}
}
});
};
/**
* Checks if user wants to join or not join a
* @param message
* @private
*/
lucy._inOrOutForSmoothie = function (message, currentDay) {
var userId = message.user;
var users = lucy.getUsers();
var user = this.getUserById(userId, users);
var text = message.text.toLowerCase();
// to trim whitespaces, \s regex for whiespace, g global flag meaning all \s, + is faster as all string
//space characters are replace with empty string instead of character by character.
text = text.replace(/\s+/g, '');
// check if the message is yes, then update the DB record and tell him to pay monica now
if ((text === 'yes' || text === "ja" || text === "yea" || text === "yeah" || text === "ye" || text === "si") && (
currentDay === config.MONDAY)) {
// update database
// 1- get the latest entry for that user
// 2- update the the interested part to 1 instead of null
this.db.get('SELECT id, date, interested, paid FROM saladrecord WHERE username=' + '\'' + user.name + '\' ORDER BY id DESC LIMIT 1', function (err, record) {
if (err) {
return console.error("DATABASE ERROR: " + err);
}
//console.log(record.paid);
if (record.interested === null && record.paid === null) {
lucy.postMessageToUser(user.name, "Cool, I am adding you now to the S&S sheet for this week. For now, please pay Monica :-)", {as_user: true});
lucy.db.run('UPDATE saladrecord SET interested = 1 WHERE id = ?', record.id);
lucy.postMessageToUser(config.USER_TO_REPORT_TO, user.name + " is interested in salad this week!", {as_user: true});
}
else if (record.interested === 1 && record.paid === null) {
lucy.postMessageToUser(user.name, "Awesome! Thank you. Have a great work day!", {as_user: true});
lucy.db.run('UPDATE saladrecord SET paid = 1 WHERE id = ?', record.id);
}
});
}
else if ((text === 'no' || text === 'nein' || text === 'nop' || text === 'nope') && (
currentDay === config.MONDAY)) {
// user answered no;
// update database
// 1- get the latest entry for that user
// 2- update the the interested part to 0 instead of null
this.db.get('SELECT id, date, interested FROM saladrecord WHERE username=' + '\'' + user.name + '\' ORDER BY id DESC LIMIT 1', function (err, record) {
if (err) {
return console.error("DATABASE ERROR: " + err);
}
if (record.interested !== 1) {
lucy.postMessageToUser(user.name, "That's sad :-( We would really love that you would join us.", {as_user: true});
lucy.db.run('UPDATE saladrecord SET interested = 0 WHERE id = ?', record.id);
}
if (record.interested === 0) {
lucy.postMessageToUser(user.name, "Ok :-)", {as_user: true})
}
if (record.interested === 1) {
lucy.postMessageToUser(user.name, "Then please proceed with the payment to Monica :-)", {as_user: true});
}
});
}
else if (text === 'hi' || text === 'hii') {
this._handleHiMsg(user);
}
else if (text === 'howareyou?' || text === 'howru?' || text.indexOf('howareyou') > -1 || text.indexOf('howru') > -1 || text.indexOf('hwru') > -1) {
this._handleHowAreYouMsg(user);
}
else if(message.type == "message" && text.indexOf("token=") > -1 && text.indexOf("YOURTOKEN") <= -1){
this._handleSaveUserToken(user, text);
}
else if (text.indexOf('fine') > -1 || text.indexOf('good') > -1 || text.indexOf('ok') > -1) {
console.log("MYTEXT " + text);
this._handleGoodMsg(user);
}
else if (text === 'door') {
http.get({
host: '192.168.2.236',
port: 8080,
path: '/',
method: 'GET'
}, function(res) {
lucy.postMessageToUser(user.name, "Opening it for you! ;-)", {as_user: true});
})
}
else if(message.type == "message" && text.indexOf("how") > -1 && text.indexOf("compress") > -1){
this._handleHowToCompress(user);
}
else if(message.type == "message" && message.subtype == "file_share" && message.file != null && message.file.filetype == "mp4" && text.indexOf("compress") > -1 ){
this._handleCompressVideo(user, message);
}
else {
this._handleOtherMsg(user, text);
}
};
/**
* helper method to handle unknown messages
* @param user
* @param text
* @private
*/
lucy._handleOtherMsg = function (user, text) {
var date = new Date();
var currentDate = date.getDate().toString() + date.getMonth().toString() + date.getFullYear().toString();
var insertStatement = 'INSERT INTO talktolucy(username, date, text) VALUES ("' + user.name + '", ' + '"' + currentDate + '",' + '"' + text + '"' + ');';
lucy.db.run(insertStatement);
lucy.postMessageToUser(user.name, "I did not understand what you are trying to say. But I am still learning. However, feel free to talk!", {as_user: true});
};
/**
* helper method to handle Good msg
* @param user
* @private
*/
lucy._handleGoodMsg = function (user) {
lucy.postMessageToUser(user.name, ":-)", {as_user: true});
};
/**
* helper method to handle 'how are you' messages
* @param user
* @private
*/
lucy._handleHowAreYouMsg = function (user) {
lucy.postMessageToUser(user.name, "Unfortunately, I am a bot. I do not feel at all. But since you are reading this message, it means that servers are running in a good way.", {as_user: true});
};
/**
* helper method to handle the hi messages
* @param user
* @private
*/
lucy._handleHiMsg = function (user) {
//console.log(user);
lucy.postMessageToUser(user.name, "Hi " + user.name + ", How's everything?", {as_user: true});
};
/**
* helper method to handle the how to compress message
* @param user : user to send the steps of how to compress to.
* @private
*/
lucy._handleHowToCompress = function(user){
lucy.postMessageToUser(user.name, "Go to the link : https://api.slack.com/docs/oauth-test-tokens \n If you have token copy it and send it to me \n If not generate a token and send it to me \n You should send it in the format token=YOURTOKEN \n Then upload the video and call me in the comment to compress it for you by typing compress lucy in the comment part", {as_user: true});
}
/**
* helper method to handle saving user tokens
* @param user
* @param text : the string including the token in formar token=XXX
* @private
*/
lucy._handleSaveUserToken = function(user, text){
var token = text.split("=");
token = token[token.length - 1];
lucy.db.get('SELECT token FROM user WHERE id = ' + '\'' + user.id + '\' LIMIT 1', function (err, record) {
if (err) {
winston.log('error', 'database error' + err);
return console.error('DATABASE ERROR:', err);
}
// this is the first recored for this user
if (!record) {
winston.log('info', 'Not a record');
lucy.db.run('INSERT INTO user(id, token) VALUES(?, ?)', user.id, token);
}else{
// updates user last token
lucy.db.run('UPDATE user SET token = ? WHERE id = ?' , token, user.id);
}
lucy.postMessageToUser(user.name, "I have saved your token do not worry I will not share it with anyone", {as_user: true});
});
}
/**
* helper method to handle compressing video.
* @param user
* @param data : the slack message response.
* @private
*/
lucy._handleCompressVideo = function(user, data){
lucy.db.get('SELECT token FROM user WHERE id = ' + '\'' + user.id + '\' LIMIT 1', function (err, record) {
if (err) {
winston.log('error', 'database error' + err);
return console.error('DATABASE ERROR:', err);
}
// The record not found.
if (!record) {
winston.log('info', 'Not a record');
lucy.postMessageToUser(user, "Please follow the following steps to add your token first : ", {as_user: true});
lucy._handleHowToCompress(user);
}else{
lucy._sendCompressRequest(user, record.token, data);
}
});
}
/**
* helper method to handle compressing video.
* @param user
* @param token : the user slack auth token.
* @param data : the slack message response.
* @private
*/
lucy._sendCompressRequest = function(user, token, data){
var url = "https://slack.com/api/files.sharedPublicURL?token=" + token + "&file=" + data.file.id;
var request = https.get(url, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
fi(JSON.parse(chunk).ok){
var s = data.file.permalink_public.split("-");
s = s[s.length - 1];
var downloadURL = data.file.url_private+ "?pub_secret=" + s;
lucy._compressVideoFFMPEG(downloadURL, data, token, user);
//lucy.postMessageToUser(user.name, downloadURL, {as_user: true});
// compressOnlineVideo(data.file.id, downloadURL, data, token, user);
}else{
// The token has been expired.
lucy.postMessageToUser(user.name, JSON.parse(chunk).error, {as_user: true});
lucy.postMessageToUser(user.name, "Please follow the following steps to add your token first : ", {as_user: true});
lucy._handleHowToCompress(user);
}
});
});
}
/**
* helper method to running ffmpeg command.
* @param path : The path to the video.
* @param data : the slack message response.
* @param token : the user slack auth token.
* @param user
* @private
*/
lucy._compressVideoFFMPEG = function(path, data, token, user){
var videoId = data.file.id;
lucy.postMessageToUser(user.name, "Fetching the video", {as_user: true});
var proc = new ffmpeg(path)
.addOption('-c:v', 'libx264', '-profile:v', 'baseline', '-level', '3.0', '-b:v', '800k')
.addOption('-g', 10, '-qmin', 10, '-qmax', 51, '-i_qfactor', 0.71, '-qcomp', 0.6, '-me_method', 'hex')
.addOption('-subq', 5, '-r', 20/1 ,'-pix_fmt', 'yuv420p')
.addOption('-c:a', 'libfdk_aac', '-ac', 2 ,'-ar', 44100)
.on('progress', function(progress) {
lucy.postMessageToUser(user.name, "Do not worry still working for you on "+ videoId + ".mp4 " +": " + 'Processing: ' + progress.frames + ' frames done', {as_user: true});
})
.on('start', function(commandLine) {
console.log("%s: Spawned FFmpeg with command: %s", commandLine);
})
.on('error', function(err, stdout, stderr) {
console.log('Cannot process video: ' + err.message);
lucy.postMessageToUser(user.name, 'Cannot process video: ' + err.message, {as_user: true});
})
.on('end', function() {
// Delete the file after compressing it to save space on slack.
var url = "https://slack.com/api/files.delete?token=" + token + "&file=" + data.file.id;
var request = https.get(url, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
lucy.postMessageToUser(user.name, "Here is the link : " + video_config.path_url + videoId + ".mp4" + " , and I have deleted the original file to save space on Slack.", {as_user: true});
});
});
})
.save(video_config.video_path + videoId + ".mp4");
}
/**
* Sends channel remined msg for ready Salad
* @private
*/
lucy._tuesdaySaladMessage = function () {
var tuesdaySchedule = new schedule.RecurrenceRule();
// schedule the message for Tuesday at 1:00pm
tuesdaySchedule.second = config.TUESDAYSALADMESSAGE_SECOND;
tuesdaySchedule.minute = config.TUESDAYSALADMESSAGE_MINUTE;
tuesdaySchedule.hour = config.TUESDAYSALADMESSAGE_HOUR;
tuesdaySchedule.dayOfWeek = config.TUESDAY; // 1 is for mondays
schedule.scheduleJob(tuesdaySchedule, function () {
lucy.postMessageToChannel(config.CHAT_ROOM, "@channel: Salad is ready! Run to the Kitchen!", {as_user: true});
});
};
/**
* Sends channel reminder msg for ready smoothie
* @private
*/
lucy._wednesdaySmoothieMessage = function () {
var wednesdaySchedule = new schedule.RecurrenceRule();
wednesdaySchedule.second = config.WEDNESDAYSMOOTHIEMESSAGE_SECOND;
wednesdaySchedule.minute = config.WEDNESDAYSMOOTHIEMESSAGE_MINUTE;
wednesdaySchedule.hour = config.WEDNESDAYSMOOTHIEMESSAGE_HOUR;
wednesdaySchedule.dayOfWeek = config.WEDNESDAY; // 1 is for mondays
schedule.scheduleJob(wednesdaySchedule, function () {
lucy.postMessageToChannel(config.CHAT_ROOM, "@channel: Smoothies are ready! Run to the Kitchen!", {as_user: true});
});
};