-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.js
79 lines (69 loc) · 2.73 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict';
// Require messengerninja
let ninja = require('messengerninja-core'); // Too much time spent by author on googling ascii art
if (!process.env.token) {
throw new Error('You must specify a page access token in the token environmental variable.');
}
let bot = new ninja({
token: process.env.token // Your facebook page access token
});
bot.connect(function() {
console.log('Connected to MessengerNinja real time API'); // :D
}).error(function (status) {
throw new Error('Could not connect to messengerninja real time API, server returned code: ' + status); // Oh no oh no oh no
});
/*
`. \
\_)
____ _,..OOO......\...OOO-...._ ___
.` '_.-( 9``````````P )--...) `.
` (( ` || __ || ` )) `
( ) |<` ````---__|| ( )
` ` ||) ,xx xx. //)__` `
`-____-` ,/ O` O` //,'_ )`-____-`
,/ ,, // |//
/ (( //
( (._ _,) (_) -OH YEAH!
\ \````/ /
\ ^--^ /
\_ _____ __/
| | | |
( ) ( )
,--'~'\ /'~'--,
(_______) (_______)
*/
bot.attachment(function (message) {
message.reply('Thanks for the attachment!'); // I'm too lazy to actually do anything with the attachment. You could access message.payload and get the attachment and save it or something, but I don't really feel like implementing that right now.
});
bot.sticker(function (message) {
message.reply({ type: 'sticker', sticker_id: message.sticker_id }); // A thumb for a thumb
});
bot.hears(['who am i', 'what is my name'], function (message) {
bot.graph.getUserDetails(message.sender.id, function (user) { // Get basic details of sender from graph API
message.reply('Your name is ' + user.first_name + ' ' + user.last_name); // Just in case you don't know your name
});
});
bot.hears(['uptime'], function (message) {
message.reply('I have been running for ' + formatUptime(process.uptime()) + ' on ' + require('os').hostname()); // Return uptime of app
});
bot.hears(['hello', 'hi', 'sup', 'what\'s up'], function (message) {
bot.graph.getUserDetails(message.sender.id, function (user) { // Get basic details of sender from graph API
message.reply('Hello ' + user.first_name + '!'); // e.g. Hello David!
});
});
function formatUptime(uptime) {
let 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;
} // Totally copied this from botkit.