asjon/scripts/shortener.coffee

33 lines
811 B
CoffeeScript
Raw Permalink Normal View History

2015-08-15 17:30:30 +02:00
# Description:
2017-02-22 22:12:06 +01:00
# Accorcia un link usando l'api di brve.bit
2015-08-15 17:30:30 +02:00
#
# Dependencies:
# valid-url
2015-08-16 02:55:39 +02:00
# needle
2015-08-15 17:30:30 +02:00
#
# Configuration:
# None
#
# Commands:
# hubot accorcia/breve <url> - accorcia un link
#
# Author:
# Michele Guerini Rocco (rnhmjoj)
#
2015-08-16 02:55:39 +02:00
ne = require 'needle'
2015-08-15 17:30:30 +02:00
{ 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]
2015-08-16 02:55:39 +02:00
if is_web_uri url
2017-02-22 22:12:06 +01:00
ne.post 'https://brve.bit/api', url: url, {rejectUnauthorized: false}, (err, resp, body) =>
return res.send "c'è qualche problema: #{err}" if err
2015-08-16 02:55:39 +02:00
res.send (res.random valid) + body.link
2015-08-15 17:30:30 +02:00
else
2017-02-22 22:12:06 +01:00
res.send res.random invalid