57 lines
1.6 KiB
CoffeeScript
57 lines
1.6 KiB
CoffeeScript
# Description:
|
|
# makes dank maymays
|
|
#
|
|
# Commands:
|
|
# hubot meme <template>,<upper title>,<lower title> - genera un meme
|
|
# hubot memes [-v] - mostra i templates disponibili
|
|
#
|
|
# Configuration:
|
|
# None
|
|
#
|
|
# Author:
|
|
# Enrico Fasoli (fazo96)
|
|
|
|
async = require 'async'
|
|
|
|
module.exports = (robot) ->
|
|
escape = (str) ->
|
|
str.replace( /-/g, '--')
|
|
.replace(/\ /g, '-')
|
|
.replace( /_/g, '__')
|
|
.replace(/\?/g, '~q')
|
|
.replace( /%/g, '~p')
|
|
.toLowerCase()
|
|
|
|
send_example = (url, res, callback) ->
|
|
cb = if callback? then (-> callback()) else (-> return)
|
|
|
|
robot.http(url).get() (err, r, body) ->
|
|
template = JSON.parse body
|
|
res.send template.name,
|
|
template.example + '.jpg',
|
|
'alias: ' + template.aliases.join(', '),
|
|
if robot.adapterName is 'tg' then cb else ''
|
|
|
|
cb() if robot.adapterName isnt 'tg'
|
|
|
|
|
|
memegen = 'http://memegen.link/'
|
|
|
|
usage = 'non si usa così: prova a chiedermi "asjon help meme" per
|
|
sapere sapere come funziona il comando'
|
|
|
|
robot.respond /meme (.+)/i, (res) ->
|
|
args = res.match[1]
|
|
return res.send usage if args.split(',').length != 3
|
|
|
|
meme = (escape i.trim() for i in args.split ',').join '/'
|
|
res.send memegen + meme + '.jpg'
|
|
|
|
robot.respond /memes( -v)?/i, (res) ->
|
|
if not res.match[1]?
|
|
res.send 'guarda qui: http://memegen.link/overview'
|
|
else
|
|
robot.http(memegen + 'templates/').get() (err, r, body) ->
|
|
templates = (url for _, url of JSON.parse body)
|
|
async.eachSeries templates, (url, done) ->
|
|
send_example url, res, -> done() |