This repository was archived by the owner on Oct 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
63 lines (50 loc) · 1.55 KB
/
main.js
File metadata and controls
63 lines (50 loc) · 1.55 KB
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
if (!process.env.TOKEN) {
console.log('Error: Specify token in environment');
process.exit(1);
}
var Botkit = require('botkit'),
os = require('os'),
mongoStorage = require('botkit-storage-mongo')({mongoUri: process.env.MONGODB_URI }),
fetchCardData = require('./lib/fetchCardData.js'),
search = require('./lib/search.js');
var controller = Botkit.slackbot({
storage: mongoStorage,
});
var bot = controller.spawn({
token: process.env.TOKEN
}).startRTM();
// On startup fetch and store card data frm api
fetchCardData(controller, bot);
controller.hears(['{{(.*)}}'],'direct_message,direct_mention,mention,ambient', function(bot, message){
var url,
title;
title = message.match[1];
controller.storage.teams.get('all_cards', function(err, data) {
url = search(data.data, title)
bot.reply(message, url);
});
});
controller.hears(['uptime', 'identify yourself', 'who are you', 'what is your name'],
'direct_message,direct_mention,mention,ambient', function(bot, message) {
var hostname = os.hostname(),
uptime = formatUptime(process.uptime());
bot.reply(message,
':robot_face: I am a bot named <@' + bot.identity.name +
'>. I have been running for ' + uptime + ' on ' + hostname + '.');
});
function formatUptime(uptime) {
var unit = 'second';
if (uptime > 60) {
uptime = uptime / 60;
unit = 'minute';
}
if (uptime > 60) {
uptime = uptime / 60;
unit = 'hour';
}
if (uptime != 1) {
unit = unit + 's';
}
uptime = uptime + ' ' + unit;
return uptime;
}