diff --git a/package.json b/package.json index 73e93c8..fd47d49 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/shortener.coffee b/scripts/shortener.coffee index 16e0c90..fc5d8fc 100644 --- a/scripts/shortener.coffee +++ b/scripts/shortener.coffee @@ -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: ', ''] @@ -22,10 +24,8 @@ invalid = ['eh?', "cos'รจ sta roba?", 'sarebbe un url questo?'] 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 + if is_web_uri url + ne.post 'https://breve.xyz/api', url: url, (err, resp, body) => + res.send (res.random valid) + body.link else res.send res.random invalid \ No newline at end of file