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-tg": "rnhmjoj/hubot-tg",
"hubot-youtube": "^0.1.2", "hubot-youtube": "^0.1.2",
"moment": "^2.10.2", "moment": "^2.10.2",
"needle": "^0.10.0",
"nightmare": "^1.8.0", "nightmare": "^1.8.0",
"nock": "^1.7.1", "nock": "^1.7.1",
"nodepie": "^0.6.7", "nodepie": "^0.6.7",

View File

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