Add memes overview and escape special characters
This commit is contained in:
parent
8a1d6e49ed
commit
6c3e6730e7
@ -3,6 +3,7 @@
|
||||
#
|
||||
# Commands:
|
||||
# hubot meme <template>,<upper title>,<lower title> - genera un meme
|
||||
# hubot memes [-v] - mostra i templates disponibili
|
||||
#
|
||||
# Configuration:
|
||||
# None
|
||||
@ -10,16 +11,47 @@
|
||||
# Author:
|
||||
# Enrico Fasoli (fazo96)
|
||||
|
||||
async = require 'async'
|
||||
|
||||
module.exports = (robot) ->
|
||||
escape = (str) -> (str.replace /-/g, '--').replace /\ /g, '-'
|
||||
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) ->
|
||||
text = res.match[1]
|
||||
return res.send usage if text.split(',').length != 3
|
||||
|
||||
meme = (escape i.trim() for i in text.split ',').join '/'
|
||||
url = 'http://memegen.link/' + meme + '.jpg'
|
||||
res.send url
|
||||
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()
|
Loading…
Reference in New Issue
Block a user