This repository was archived by the owner on May 4, 2020. 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
246 lines (221 loc) · 7.32 KB
/
Copy pathmain.js
File metadata and controls
246 lines (221 loc) · 7.32 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
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
var Botkit = require('botkit');
var os = require('os');
var request = require('request');
var controller = Botkit.slackbot();
var bot = controller.spawn({
token: getVar("SLACK_TOKEN")
});
// slack's api only gives these weird codes instead of usernames :(
var owners = [ "U0EGDRXEK" ];
var meekan_user = "U0GQF3PTL";
var annoyingness_channel = "C0L6XQ3FS";
var hexme = [ "U0G281Q8L", "U0EGDRXEK", "U0EGTKEFM"];
var chat_channel = "C0MS09H2L";
var dotdotdot_channel = "C0Q1B69HT";
var logoEmoji = "planhub";
var phIntToken = getVar("PH_INT_TOKEN");
bot.startRTM(function(err,bot,payload) {
if (err) {
throw new Error('Could not connect to Slack');
}
controller.hears(["^hexy_hello$"],["direct_message","direct_mention","mention"],function(bot,message) {
bot.api.reactions.add({
timestamp: message.ts,
channel: message.channel,
name: 'robot_face',
},function(err, res) {
if (err) {
bot.botkit.log('Failed to add emoji reaction :(',err);
}
});
bot.startConversation(message,function(err,convo) {
convo.ask('hexy_hello! How\'s the weather today?',function(response,convo) {
convo.say("Really? I'm a bot, so I don't care.");
convo.next();
});
});
});
controller.hears(["broswers", "fialls", "jabascript", "outpot"],'ambient',function(bot, message) {
bot.reply(message, 'lel speling iz inded harrd');
});
controller.hears(["LEWL"],'ambient',function(bot, message) {
bot.reply(message, '*_LEWL_*');
});
controller.hears(["shiny", "prettyful"],'direct_message,direct_mention,mention',function(bot, message) {
bot.reply(message, ":sparkles: Shiny and prettyful is good.");
});
controller.hears(["hi", "hai", "hello", "helo"],'direct_message,direct_mention,mention',function(bot, message) {
bot.reply(message, 'Hai thar, *Hexr*!');
});
controller.hears(['ping'],'direct_message,direct_mention,mention',function(bot, message) {
bot.reply(message, 'Pong!');
});
controller.hears(['identify yourself','who are you','what is your name'],'direct_message,direct_mention,mention',function(bot, message) {
bot.reply(message, 'I am *PlanBot*! Not to be confused with https://github.com/PlanHubMe/PlanHub/issues/256. Not sure what\'s up with that.');
});
controller.hears(['hex me'],'direct_mention,mention',function(bot, message) {
bot.startConversation(message,function(err, convo) {
convo.ask('Please confirm: you are *absolutely* sure you want to be hexed',[
{
pattern: bot.utterances.yes,
callback: function(response, convo) {
if (hexme.indexOf(response.user) > -1) {
convo.say('YOU HAVE BEEN HEXED :hackerman: :' + logoEmoji + ':');
convo.next();
} else {
convo.say("NU HEXING ALLOWED SORRY");
convo.next();
}
}
},
{
pattern: bot.utterances.no,
default: true,
callback: function(response, convo) {
convo.say('*Okay then, no hexing for today...*');
convo.next();
}
}
]);
});
});
controller.hears([':simple_smile:'],'ambient',function(bot, message) {
bot.reply(message, ':simple_smile:');
});
controller.hears(['test users'],'direct_message,direct_mention,mention',function(bot, message) {
bot.reply(message,
{
"attachments": [
{
"fallback": "Sorry, but the test users don't exist right now.",
"color": "danger",
"title": "Error",
"text" : "Sorry, but the test users don't exist right now."
}
]
}
);
});
controller.hears(['users'],'direct_message,direct_mention,mention',function(bot, message) {
bot.reply(message, 'Loading, please wait...');
phIntApi("users.php", function(resp) {
bot.reply(message, "Here are the 5 newest users, from newest to oldest:");
var users = resp.split(",");
for (var userIndex in users) {
var user = users[userIndex];
if (user == "") {
continue;
}
var name = user.split("|")[0];
var username = user.split("|")[1];
bot.reply(message, "• " + name + " (" + username + ")");
}
});
});
controller.hears(['uptime'],'direct_message,direct_mention,mention',function(bot, message) {
var hostname = os.hostname();
var uptime = formatUptime(process.uptime());
bot.reply(message,':robot_face: I have been running for ' + uptime + ' on ' + hostname + '. That\'s a long time. I need a break...');
});
controller.hears(['help'],'direct_message,direct_mention,mention',function(bot, message) {
bot.reply(message, "I don't really do much as of now. I hope to do more things in the future! Tell <@thatoddmailbox> if you have any suggestions.");
});
controller.hears(["I didn't get that.", "I don't understand.", "scheduling robot", "not sure what you mean.", 'That does not compute'],'ambient',function(bot, message) {
if (message.user == meekan_user && message.channel == annoyingness_channel) {
bot.reply(message, "Well, maybe be less of a _Meekan_, and more of a *PlanBot*. :" + logoEmoji + ':');
}
});
controller.hears(["\\.\\.\\."],'ambient',function(bot, message) {
if (message.channel == dotdotdot_channel) {
bot.reply(message, "...");
}
});
controller.hears(["when", "when?"],'ambient',function(bot, message) {
var mez = message.text.split(" ");
if(mez[mez.length-1].toLowerCase() == "when" || mez[mez.length-1].toLowerCase() == "when?") {
bot.reply(message, 'When you code it.');
}
});
controller.hears(["slackbot"],'ambient',function(bot, message) {
if (message.channel == annoyingness_channel) {
bot.reply(message, "Oh, that's not me!");
}
});
controller.hears([""],'ambient',function(bot, message) {
var tyme = message.ts.toString();
var countr = tyme.length - 1;
var dig = tyme[countr];
var num = 1;
while(countr > 0 && dig == tyme[countr - 1]) {
num +=1;
countr -=1
}
if(num == 3) {
bot.reply(message, "*_TRIIIIIIIIIPS!_*");
} else if(num == 4) {
bot.reply(message, "*_QUAAAAAADS_*");
} else if(num > 4) {
bot.reply(message, num + "in a row. *_BEYOND GODLIKE_*");
}
});
controller.hears(['shutdown', "goodnight", "good night"],'direct_message,direct_mention,mention',function(bot, message) {
bot.startConversation(message,function(err, convo) {
convo.ask('Are you sure you want me to shutdown?',[
{
pattern: bot.utterances.yes,
callback: function(response, convo) {
if (owners.indexOf(response.user) > -1) {
convo.say('Bye! :cry:');
convo.next();
setTimeout(function() {
process.exit();
}, 3000);
} else {
convo.say("Hey, wait a minute! You're not allowed to do that—only <@thatoddmailbox> can shut me down!");
convo.next();
}
}
},
{
pattern: bot.utterances.no,
default: true,
callback: function(response, convo) {
convo.say('*Phew!*');
convo.next();
}
}
]);
});
});
});
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;
}
function getVar(name) {
if (process.env[name]) {
return process.env[name];
}
return undefined;
}
// calls the super secret planhub internal api that may or may not exist
function phIntApi(page, callback) {
request.post({
url: 'http://aserv-cloud.cloudapp.net/phapi/' + page,
form: { token: phIntToken }
}, function(err, httpResponse, body){
callback(body);
});
}