Add url shortener script

This commit is contained in:
rnhmjoj 2015-08-15 17:30:30 +02:00
parent 9b01a17a69
commit df68dd1e60
2 changed files with 32 additions and 0 deletions

View File

@ -34,6 +34,7 @@
"nock": "^1.7.1",
"nodepie": "^0.6.7",
"soupselect": "^0.2.0",
"valid-url": "^1.0.9",
"weak": "^0.4.0"
},
"scripts": {

31
scripts/shortener.coffee Normal file
View File

@ -0,0 +1,31 @@
# Description:
# Accorcia un link usando l'api di breve.xyz
#
# Dependencies:
# valid-url
#
# Configuration:
# None
#
# Commands:
# hubot accorcia/breve <url> - accorcia un link
#
# Author:
# Michele Guerini Rocco (rnhmjoj)
#
{ is_web_uri } = require 'valid-url'
valid = ['eccoti: ', 'ecco qui: ', 'fatto: ', '']
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
else
res.send res.random invalid