Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit 8215b1d

Browse files
committed
Merge branch 'master' of git://github.com/benjamine/hubot-scripts into benjamine-master
Conflicts: src/scripts/meme_captain.coffee
2 parents c58345c + 6abbd74 commit 8215b1d

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/scripts/meme_captain.coffee

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,28 @@ module.exports = (robot) ->
7878

7979

8080
memeGenerator = (msg, imageName, text1, text2, callback) ->
81-
imageUrl = "http://v1.memecaptain.com/" + imageName
82-
msg.http("http://v1.memecaptain.com/g")
83-
.query(
84-
u: imageUrl,
85-
t1: text1,
86-
t2: text2
87-
).get() (err, res, body) ->
81+
imageUrl = "http://memecaptain.com/" + imageName
82+
83+
processResult = (err, res, body) ->
8884
return msg.send err if err
89-
result = JSON.parse(body)
85+
if res.statusCode == 301
86+
msg.http(res.headers.location).get() processResult
87+
return
88+
if res.statusCode > 300
89+
msg.reply "Sorry, I couldn't generate that meme. Unexpected status from memecaption.com: #{res.statusCode}"
90+
return
91+
try
92+
result = JSON.parse(body)
93+
catch error
94+
msg.reply "Sorry, I couldn't generate that meme. Unexpected response from memecaptain.com: #{body}"
9095
if result? and result['imageUrl']?
9196
callback result['imageUrl']
9297
else
9398
msg.reply "Sorry, I couldn't generate that meme."
9499

95-
96-
100+
msg.http("http://memecaptain.com/g")
101+
.query(
102+
u: imageUrl,
103+
t1: text1,
104+
t2: text2
105+
).get() processResult

0 commit comments

Comments
 (0)