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
81 lines (69 loc) · 2.9 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
# Integrates with memegenerator.net
#
# Y U NO <text> - Generates the Y U NO GUY with the bottom caption
# of <text>
#
# I don't always <something> but when i do <text> - Generates The Most Interesting man in the World
#
# <text> ORLY? - Generates the ORLY? owl with the top caption of <text>
#
# <text> (SUCCESS|NAILED IT) - Generates success kid with the top caption of <text>
#
# <text> ALL the <things> - Generates ALL THE THINGS
#
# <text> TOO DAMN <high> - Generates THE RENT IS TOO DAMN HIGH guy
#
# Good news everyone! <news> - Generates Professor Farnsworth
module.exports = (robot) ->
robot.respond /Y U NO (.+)/i, (msg) ->
caption = msg.match[1] || ""
memeGenerator msg, 2, 166088, "Y U NO", caption, (url) ->
msg.send url
robot.respond /(I DON'?T ALWAYS .*) (BUT WHEN I DO,? .*)/i, (msg) ->
memeGenerator msg, 74, 2485, msg.match[1], msg.match[2], (url) ->
msg.send url
robot.respond /(.*)(O\s?RLY\??.*)/i, (msg) ->
memeGenerator msg, 920, 117049, msg.match[1], msg.match[2], (url) ->
msg.send url
robot.respond /(.*)(SUCCESS|NAILED IT.*)/i, (msg) ->
memeGenerator msg, 121, 1031, msg.match[1], msg.match[2], (url) ->
msg.send url
robot.respond /(.*) (ALL the .*)/i, (msg) ->
memeGenerator msg, 6013, 1121885, msg.match[1], msg.match[2], (url) ->
msg.send url
robot.respond /(.*) (\w+\sTOO DAMN .*)/i, (msg) ->
memeGenerator msg, 998, 203665, msg.match[1], msg.match[2], (url) ->
msg.send url
robot.respond /(GOOD NEWS EVERYONE[,.!]?) (.*)/i, (msg) ->
memeGenerator msg, 1591, 112464, msg.match[1], msg.match[2], (url) ->
msg.send url
memeGenerator = (msg, generatorID, imageID, text0, text1, callback) ->
username = process.env.HUBOT_MEMEGEN_USERNAME
password = process.env.HUBOT_MEMEGEN_PASSWORD
unless username
msg.send "MemeGenerator username isn't set. Sign up at http://memegenerator.net"
msg.send "Then set the HUBOT_MEMEGEN_USERNAME environment variable"
return
unless password
msg.send "MemeGenerator password isn't set. Sign up at http://memegenerator.net"
msg.send "Then set the HUBOT_MEMEGEN_PASSWORD environment variable"
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) ->
result = JSON.parse(body)['result']
if result? and result['instanceUrl']? and result['instanceImageUrl']?
instanceURL = result['instanceUrl']
img = result['instanceImageUrl']
msg.http(instanceURL).get() (err, res, body) ->
# Need to hit instanceURL so that image gets generated
callback "http://memegenerator.net#{img}"
else
msg.reply "Sorry, I couldn't generate that image."