This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
meme_generator.coffee
242 lines (222 loc) · 8.04 KB
/
meme_generator.coffee
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
# Description:
# Integrates with memegenerator.net
#
# Dependencies:
# None
#
# Configuration:
# HUBOT_MEMEGEN_USERNAME
# HUBOT_MEMEGEN_PASSWORD
# HUBOT_MEMEGEN_DIMENSIONS
#
# Commands:
# hubot memegen Y U NO <text> - Generates the Y U NO GUY with the bottom caption of <text>
# hubot memegen I don't always <something> but when i do <text> - Generates The Most Interesting man in the World
# hubot memegen <text> ORLY? - Generates the ORLY? owl with the top caption of <text>
# hubot memegen <text> (SUCCESS|NAILED IT) - Generates success kid with the top caption of <text>
# hubot memegen <text> ALL the <things> - Generates ALL THE THINGS
# hubot memegen <text> TOO DAMN <high> - Generates THE RENT IS TOO DAMN HIGH guy
# hubot memegen good news everyone! <news> - Generates Professor Farnsworth
# hubot memegen khanify <text> - TEEEEEEEEEEEEEEEEEXT!
# hubot memegen Not sure if <text> or <text> - Generates Futurama Fry
# hubot memegen Yo dawg <text> so <text> - Generates Yo Dawg
# hubot memegen ALL YOUR <text> ARE BELONG TO US - Generates Zero Wing with the caption of <text>
# hubot memegen if <text>, <word that can start a question> <text>? - Generates Philosoraptor
# hubot memegen <text> FUCK YOU - Angry Linus
# hubot memegen (Oh|You) <text> (Please|Tell) <text> - Willy Wonka
# hubot memegen <text> you're gonna have a bad time - Bad Time Ski Instructor
# hubot memegen one does not simply <text> - Lord of the Rings Boromir
# hubot memegen it looks like (you|you're) <text> - Generates Clippy
# hubot memegen AM I THE ONLY ONE AROUND HERE <text> - The Big Lebowski
# hubot memegen <text> NOT IMPRESSED - Generates McKayla Maroney
# hubot memegen PREPARE YOURSELF <text> - Generates GoT
# hubot memegen WHAT IF I TOLD YOU <text> - Generates Morpheus
# hubot memegen <text> BETTER DRINK MY OWN PISS - Generates Bear Grylls
# hubot memegen INTERNET KID <text>, <text> - Generates First-day-on-the-Internet Kid
# Author:
# skalnik
inspect = require('util').inspect
module.exports = (robot) ->
unless robot.brain.data.memes?
robot.brain.data.memes = [
{
regex: /(memegen )?(Y U NO) (.+)/i,
generatorID: 2,
imageID: 166088
},
{
regex: /(memegen )?(I DON'?T ALWAYS .*) (BUT WHEN I DO,? .*)/i,
generatorID: 74,
imageID: 2485
},
{
regex: /(memegen )?(.*)(O\s?RLY\??.*)/i,
generatorID: 920,
imageID: 117049
},
{
regex: /(memegen )?(.*)(SUCCESS|NAILED IT.*)/i,
generatorID: 121,
imageID: 1031
},
{
regex: /(memegen )?(.*) (ALL the .*)/i,
generatorID: 6013,
imageID: 1121885
},
{
regex: /(memegen )?(.*) (\w+\sTOO DAMN .*)/i,
generatorID: 998,
imageID: 203665
},
{
regex: /(memegen )?(GOOD NEWS EVERYONE[,.!]?) (.*)/i,
generatorID: 1591,
imageID: 112464
},
{
regex: /(memegen )?(NOT SURE IF .*) (OR .*)/i,
generatorID: 305,
imageID: 84688
},
{
regex: /(memegen )?(YO DAWG .*) (SO .*)/i,
generatorID: 79,
imageID: 108785
},
{
regex: /(memegen )?(ALL YOUR .*) (ARE BELONG TO US)/i,
generatorID: 349058,
imageID: 2079825
},
{
regex: /(memegen )?(.*) (FUCK YOU)/i,
generatorID: 1189472,
imageID: 5044147
},
{
regex: /(memegen )?(.*) (You'?re gonna have a bad time)/i,
generatorID: 825296,
imageID: 3786537
},
{
regex: /(memegen )?(one does not simply) (.*)/i,
generatorID: 274947,
imageID: 1865027
},
{
regex: /(memegen )?(grumpy cat) (.*),(.*)/i,
generatorID: 1590955,
imageID: 6541210
},
{
regex: /(memegen )?(it looks like you're|it looks like you) (.*)/i,
generatorID: 20469,
imageID: 1159769
},
{
regex: /(memegen )?(AM I THE ONLY ONE AROUND HERE) (.*)/i,
generatorID: 953639,
imageID: 4240352
}
{
regex: /(memegen)?(.*)(NOT IMPRESSED*)/i,
generatorID: 1420809,
imageID: 5883168
},
{
regex: /(memegen)?(PREPARE YOURSELF) (.*)/i,
generatorID: 414926,
imageID: 2295701
},
{
regex: /(memegen)?(WHAT IF I TOLD YOU) (.*)/i,
generatorID: 1118843,
imageID: 4796874
},
{
regex: /(memegen)?(.*) (BETTER DRINK MY OWN PISS)/i,
generatorID: 92,
imageID: 89714
},
{
regex: /(memegen)? ?INTERNET KID ?([^,]*),?(.*)/i,
generatorID: 1095654,
imageID: 4714007
}
]
for meme in robot.brain.data.memes
memeResponder robot, meme
robot.respond /(memegen )?add meme \/(.+)\/i,(.+),(.+)/i, (msg) ->
meme =
regex: new RegExp(msg.match[2], "i")
generatorID: parseInt(msg.match[3])
imageID: parseInt(msg.match[4])
robot.brain.data.memes.push meme
memeResponder robot, meme
robot.respond /(memegen )?k(?:ha|ah)nify (.*)/i, (msg) ->
if Math.random() > 0.5
# Kirk khan
memeGenerator msg, 6443, 1123022, "", khanify(msg.match[2]), (url) ->
msg.send url
else
# Spock khan
memeGenerator msg, 2103732, 8814557, "", khanify(msg.match[2]), (url) ->
msg.send url
robot.respond /(memegen )?(IF .*), ((ARE|CAN|DO|DOES|HOW|IS|MAY|MIGHT|SHOULD|THEN|WHAT|WHEN|WHERE|WHICH|WHO|WHY|WILL|WON\'T|WOULD)[ \'N].*)/i, (msg) ->
memeGenerator msg, 17, 984, msg.match[2], msg.match[3] + (if msg.match[3].search(/\?$/)==(-1) then '?' else ''), (url) ->
msg.send url
robot.respond /(memegen )?((Oh|You) .*) ((Please|Tell) .*)/i, (msg) ->
memeGenerator msg, 542616, 2729805, msg.match[2], msg.match[4], (url) ->
msg.send url
memeResponder = (robot, meme) ->
robot.respond meme.regex, (msg) ->
memeGenerator msg, meme.generatorID, meme.imageID, msg.match[2], msg.match[3], (url) ->
msg.send url
memeGenerator = (msg, generatorID, imageID, text0, text1, callback) ->
username = process.env.HUBOT_MEMEGEN_USERNAME
password = process.env.HUBOT_MEMEGEN_PASSWORD
preferredDimensions = process.env.HUBOT_MEMEGEN_DIMENSIONS
unless username? and password?
msg.send "MemeGenerator account isn't setup. Sign up at http://memegenerator.net"
msg.send "Then ensure the HUBOT_MEMEGEN_USERNAME and HUBOT_MEMEGEN_PASSWORD environment variables are set"
return
msg.http('http://version1.api.memegenerator.net/Instance_Create')
.query
username: username,
password: password,
languageCode: 'en',
generatorID: generatorID,
imageID: imageID,
text0: text0,
text1: text1
.get() (err, res, body) ->
if err
msg.reply "Ugh, I got an exception trying to contact memegenerator.net:", inspect(err)
return
jsonBody = JSON.parse(body)
success = jsonBody.success
errorMessage = jsonBody.errorMessage
result = jsonBody.result
if not success
msg.reply "Ugh, stupid request to memegenerator.net failed: \"#{errorMessage}.\" What does that even mean?"
return
instanceID = result?.instanceID
instanceURL = result?.instanceUrl
img = result?.instanceImageUrl
unless instanceID and instanceURL and img
msg.reply "Ugh, I got back weird results from memegenerator.net. Expected an image URL, but couldn't find it in the result. Here's what I got:", inspect(jsonBody)
return
msg.http(instanceURL).get() (err, res, body) ->
# Need to hit instanceURL so that image gets generated
if preferredDimensions?
callback "http://images.memegenerator.net/instances/#{preferredDimensions}/#{instanceID}.jpg"
else
callback "http://images.memegenerator.net/instances/#{instanceID}.jpg"
khanify = (msg) ->
msg = msg.toUpperCase()
vowels = [ 'A', 'E', 'I', 'O', 'U' ]
index = -1
for v in vowels when msg.lastIndexOf(v) > index
index = msg.lastIndexOf(v)
"#{msg.slice 0, index}#{Array(10).join msg.charAt(index)}#{msg.slice index}!!!!!"