-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
bot.js
58 lines (49 loc) · 1.24 KB
/
bot.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
function botDefinition (botkit, configuration) {
const bot = {
type: 'discord',
botkit: botkit,
config: configuration || {},
utterance: botkit.utterance
}
bot.send = (message, cb) => {
if (typeof cb !== 'function') {
cb = (err, resp) => {
if (err) {
return botkit.debug('Message failed to send: ', err);
}
botkit.debug('Message successfully sent: ', resp);
}
}
message.channel.send(message.text, message.options)
.then(success => cb(null, success))
.catch(cb);
}
bot.reply = (src, resp, cb) => {
let message = {};
if (typeof(resp) == 'string') {
message.text = resp;
} else {
message = resp;
}
src.response = message;
// sends to format middle before sent
bot.say(src, cb);
}
bot.findConversation = function(message, cb) {
for (var t = 0; t < botkit.tasks.length; t++) {
for (var c = 0; c < botkit.tasks[t].convos.length; c++) {
if (
botkit.tasks[t].convos[c].isActive() &&
botkit.tasks[t].convos[c].source_message.user == message.user &&
botkit.excludedEvents.indexOf(message.type) == -1 // this type of message should not be included
) {
cb(botkit.tasks[t].convos[c]);
return;
}
}
}
cb();
};
return bot;
};
module.exports = botDefinition;