Proper escape urls

This commit is contained in:
rnhmjoj 2015-08-16 02:55:39 +02:00
parent df68dd1e60
commit d203174912
2 changed files with 6 additions and 5 deletions

View File

@ -30,6 +30,7 @@
"hubot-tg": "rnhmjoj/hubot-tg",
"hubot-youtube": "^0.1.2",
"moment": "^2.10.2",
"needle": "^0.10.0",
"nightmare": "^1.8.0",
"nock": "^1.7.1",
"nodepie": "^0.6.7",

View File

@ -3,6 +3,7 @@
#
# Dependencies:
# valid-url
# needle
#
# Configuration:
# None
@ -14,6 +15,7 @@
# Michele Guerini Rocco (rnhmjoj)
#
ne = require 'needle'
{ is_web_uri } = require 'valid-url'
valid = ['eccoti: ', 'ecco qui: ', 'fatto: ', '']
@ -23,9 +25,7 @@ module.exports = (robot) ->
robot.respond /breve|accorcia (.+)$/i, (res) ->
url = res.match[1]
if is_web_uri url
robot.http('https://breve.xyz/api')
.header('Content-Type','application/x-www-form-urlencoded')
.post("url=#{url}") (err, r, body) ->
res.send (res.random valid) + (JSON.parse body).link
ne.post 'https://breve.xyz/api', url: url, (err, resp, body) =>
res.send (res.random valid) + body.link
else
res.send res.random invalid