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

Commit d9a5a61

Browse files
Merge pull request #1249 from phillc/master
Update to aww me
2 parents 71cdf91 + b9b602e commit d9a5a61

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/scripts/aww.coffee

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,32 @@
1313
# Author:
1414
# eliperkins
1515

16+
url = require("url")
17+
1618
module.exports = (robot) ->
1719
robot.respond /aww/i, (msg) ->
1820
search = escape(msg.match[1])
1921
msg.http('http://www.reddit.com/r/aww.json')
2022
.get() (err, res, body) ->
2123
result = JSON.parse(body)
2224

23-
if result.data.children.count <= 0
24-
msg.send "Couldn't find anything cute..."
25-
return
26-
2725
urls = [ ]
2826
for child in result.data.children
29-
urls.push(child.data.url)
30-
27+
if child.data.domain != "self.aww"
28+
urls.push(child.data.url)
29+
30+
if urls.count <= 0
31+
msg.send "Couldn't find anything cute..."
32+
return
33+
3134
rnd = Math.floor(Math.random()*urls.length)
32-
msg.send urls[rnd]
35+
picked_url = urls[rnd]
36+
37+
parsed_url = url.parse(picked_url)
38+
if parsed_url.host == "imgur.com"
39+
parsed_url.host = "i.imgur.com"
40+
parsed_url.pathname = parsed_url.pathname + ".jpg"
41+
42+
picked_url = url.format(parsed_url)
43+
44+
msg.send picked_url

0 commit comments

Comments
 (0)