-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
306 lines (219 loc) · 11.2 KB
/
index.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
var Botkit = require("botkit");
var beepboop = require("beepboop-botkit");
var token = process.env.SLACK_TOKEN
var controller = Botkit.slackbot({
debug: false
});
if (token) {
console.log("Starting in single-team mode")
controller.spawn({
token: token
}).startRTM(function(err,bot,payload) {
if (err) {
throw new Error(err);
}
});
} else {
console.log("Starting in Beep Boop multi-team mode")
require('beepboop-botkit').start(controller, { debug: true })
}
// Major Keys from http://khaledipsum.com/
var majorKeys = [
"Bless up.",
"They don't want us to win.",
"We the best.",
"They don't want us to eat.",
"Egg whites, turkey sausage, wheat toast, water. Of course they don't want us to eat our breakfast, so we are going to enjoy our breakfast.",
"Celebrate success right, the only way, apple.",
"You smart, you loyal, you a genius.",
"Hammock talk come soon.",
"Give thanks to the most high.",
"Congratulations, you played yourself.",
"Don't ever play yourself.",
"The key to more success is to have a lot of pillows.",
"The ladies always say Khaled you smell good, I use no cologne. Cocoa butter is the key.",
"Watch your back, but more importantly when you get out the shower, dry your back, it's a cold world out there.",
"It's on you how you want to live your life. Everyone has a choice. I pick my choice, squeaky clean.",
"How's business? Boomin.",
"They never said winning was easy. Some people can't handle success, I can.",
"They will try to close the door on you, just open it.",
"We don't see them, we will never see them.",
"Every chance I get, I water the plants, Lion!",
"In life there will be road blocks but we will over come it.",
"To succeed you must believe. When you believe, you will succeed.",
"Life is what you make it, so let's make it.",
"To be successful you've got to work hard, to make history, simple, you've got to make it.",
"A major key, never panic. Don't panic, when it gets crazy and rough, don't panic, stay calm.",
"Put it this way, it took me twenty five years to get these plants, twenty five years of blood sweat and tears, and I'm never giving up, I'm just getting started.",
"You see that bamboo behind me though, you see that bamboo? Ain't nothin' like bamboo. Bless up.",
"In life you have to take the trash out, if you have trash in your life, take it out, throw it away, get rid of it, major key.",
"Surround yourself with angels, positive energy, beautiful people, beautiful souls, clean heart, angel.",
"Find peace, life is like a water fall, you've gotta flow.",
"Let's see what Chef Dee got that they don't want us to eat.",
"Lion!",
"Surround yourself with angels.",
"Major key, don't fall for the trap, stay focused. It's the ones closest to you that want to see you fail.",
"The key to more success is to get a massage once a week, very important, major key, cloth talk.",
"The key to success is to keep your head above the water, never give up.",
"It's important to use cocoa butter. It's the key to more success, why not live smooth? Why live rough?",
"They key is to have every key, the key to open every door.",
"Learning is cool, but knowing is better, and I know the key to success.",
"You do know, you do know that they don't want you to have lunch. I'm keeping it real with you, so what you going do is have lunch.",
"Stay focused.",
"I told you all this before, when you have a swimming pool, do not use chlorine, use salt water, the healing, salt water is the healing.",
"You should never complain, complaining is a weak emotion, you got life, we breathing, we blessed.",
"The key is to enjoy life, because they don't want you to enjoy life. I promise you, they don't want you to jetski, they don't want you to smile.",
"The other day the grass was brown, now it's green because I ain't give up. Never surrender.",
"The key is to drink coconut, fresh coconut, trust me.",
"The weather is amazing, walk with me through the pathway of more success. Take this journey with me, Lion!",
"You see the hedges, how I got it shaped up? It's important to shape up your hedges, it's like getting a haircut, stay fresh.",
"Let me be clear, you have to make it through the jungle to make it to paradise, that's the key, Lion!",
"Always remember in the jungle there's a lot of they in there, after you overcome they, you will make it to paradise.",
"I'm giving you cloth talk, cloth. Special cloth alert, cut from a special cloth.",
"Look at the sunset, life is amazing, life is beautiful, life is what you make it.",
"The first of the month is coming, we have to get money, we have no choice. It cost money to eat and they don't want you to eat."
];
var getRandomKey = function() {
var index = Math.floor(Math.random() * majorKeys.length);
return majorKeys[index];
}
var replyRandomKey = function(bot, message) {
var majorKey = getRandomKey();
bot.reply(message, majorKey);
}
var personaliseIntro = function(userID) {
var username = "<@"+userID+">";
var intros = [
"Major :key: for "+username+"",
""+username+", this is a special :key: just for you",
"Hold up "+username+"! Major :key: for you",
""+username+", you're in need of a major :key:",
""+username+" listen up! Major :key: alert",
"Wait wait wait. "+username+", major :key: for you",
]
var index = Math.floor(Math.random() * intros.length);
return intros[index]
}
var sendKeyToHandler = function(bot, message) {
var placeholder = message.text.split("send key to ")[1],
placeholder = placeholder ? placeholder.split(" in ") : false;
var user = placeholder[0];
var channel = placeholder[1],
channel = channel ? channel.split("<#")[1] : false,
channel = channel ? channel.split(">")[0] || channel : false;
bot.startConversation(message,function(err,convo) {
if ( !user | !channel ) {
bot.reply(message, "Sorry I didn't get that. If you want me to send a key to someone, say `@khaledbot send key to @username in #channel`");
convo.stop();
} else {
convo.ask("No problem! Do make sure I've been invited to that channel first though. \n Should I tell "+user+" you requested this? Say `yes` or `no`",function(response,convo) {
if ( response.text === 'yes' | response.text === 'Yes' ) {
bot.reply(message, "Will do! Check <#"+channel+">");
bot.say({
text: "Yo "+user + ", <@"+message.user+"> thinks you need a :key: right now, listen up! " + getRandomKey(),
channel: channel
});
} else {
bot.reply(message, "Sneaky! Check <#"+channel+">");
bot.say({
text: user + " " + getRandomKey(),
channel: channel
});
}
convo.stop();
});
}
})
}
controller.on("direct_message", function(bot, message) {
if ( message.text.indexOf("hello") > -1 | message.text.indexOf("hi") > -1 | message.text.indexOf("hey") > -1 ) {
var reply = "Hello. I'm khaledbot, here to deliver to you the major :key: to success in this Slack Team. Listen closely..."
bot.reply(message, reply);
replyRandomKey(bot, message);
} else if ( message.text.indexOf("thanks") > -1 | message.text.indexOf("thank you") > -1 ) {
var reply = "You're welcome. Bless up!"
bot.reply(message, reply);
} else if ( message.text.indexOf("help") > -1 ) {
var reply = "Looks like you need help. This is what I'm here for. You can send me any messages, and I'll reply with some major :key: :key: . Otherwise, go to http://khaledbot.com to get more info. Bless up!"
bot.reply(message, reply);
} else if ( message.text.indexOf("send key to") > -1 ) {
// do nothing, handled elsewhere
} else {
var index = Math.floor(Math.random() * majorKeys.length);
var majorKey = majorKeys[index];
bot.reply(message, majorKey);
}
})
controller.on("bot_channel_join", function(bot, message) {
var intro = "I have arrived! Major :key: :key: :key: for the channel"
bot.reply(message, intro);
replyRandomKey(bot, message);
})
controller.on("direct_mention", function(bot, message) {
if ( message.text.indexOf("hello") > -1 | message.text.indexOf("hi") > -1 | message.text.indexOf("hey") > -1 ) {
var intro = "Greetings <@"+message.user+">, I'm khaledbot, here to deliver to you the major :key: to success in this Slack Team. Listen up!";
bot.reply(message, intro);
replyRandomKey(bot, message);
} else if ( message.text.indexOf("thanks") > -1 | message.text.indexOf("thank you") > -1 ) {
var reply = "You're welcome. Bless up!"
bot.reply(message, reply);
} else if ( message.text.indexOf("send key to") > -1 ) {
sendKeyToHandler(bot, message);
} else if ( message.text.indexOf("help") > -1 ) {
var reply = "Looks like you need help. This is what I'm here for. You can send me any messages, and I'll reply with some major :key: :key: . Otherwise, go to http://khaledbot.com to get more info. Bless up!"
bot.reply(message, reply);
} else {
var intro = personaliseIntro(message.user);
bot.reply(message, intro);
replyRandomKey(bot, message);
}
})
controller.on("mention", function(bot, message) {
if ( message.text.indexOf("hello") > -1 | message.text.indexOf("hi") > -1 | message.text.indexOf("hey") > -1 ) {
var intro = "Greetings <@"+message.user+">, I'm khaledbot, here to deliver to you the major :key: to success in this Slack Team. Listen up!";
bot.reply(message, intro);
replyRandomKey(bot, message);
} else if ( message.text.indexOf("thanks") > -1 | message.text.indexOf("thank you") > -1 ) {
var reply = "You're welcome. Bless up!"
bot.reply(message, reply);
} else {
var intro = personaliseIntro(message.user);
bot.reply(message, intro);
replyRandomKey(bot, message);
}
})
controller.on("user_channel_join", function(bot, message) {
var intro = "Welcome <@"+message.user+">! Major :key: for success in this channel";
bot.reply(message, intro);
replyRandomKey(bot, message);
})
controller.on("user_group_join", function(bot, message) {
var intro = "Welcome <@"+message.user+">! Major :key: for success in this group";
bot.reply(message, intro);
replyRandomKey(bot, message);
})
controller.hears(["major key", "major keys", ":key:", " key", " keys"], ["ambient"], function(bot, message) {
var intro = "Yo <@"+message.user+">! You think you can give out the :key: to success but only I have the :key:.";
bot.reply(message, intro);
})
controller.hears(["khaled"], ["ambient"], function(bot, message) {
var intro = "<@"+message.user+"> you spoke my name?";
bot.reply(message, intro);
})
controller.hears(["dj"], ["ambient"], function(bot, message) {
var intro = "<@"+message.user+"> khaledbot is the one true DJ";
bot.reply(message, intro);
})
controller.hears(["lol", "lmao", "haha"], ["ambient"], function(bot, message) {
var laughing = [
"LOL", "Hilarious", ":joy:", ":laughing:", "Stay focused. It's work time.", "Hahahaha", "So funny!", "They don't want us to laugh"
]
var r = Math.floor(Math.random() * 4);
if ( r > 1 ) {
var index = Math.floor(Math.random() * laughing.length);
bot.reply(message, laughing[index]);
}
})
controller.hears(["send key to"], ["direct_message", "direct_metion"], function(bot, message) {
sendKeyToHandler(bot, message);
})