diff --git a/scripts/memes.coffee b/scripts/memes.coffee index 812f2f8..8b4ebdb 100644 --- a/scripts/memes.coffee +++ b/scripts/memes.coffee @@ -17,6 +17,11 @@ async = require 'async' module.exports = (robot) -> + memegen = 'http://memegen.link/' + + usage = 'non si usa così: prova a chiedermi "asjon help meme" per + sapere sapere come funziona il comando' + escape = (str) -> str.replace( /-/g, '--') .replace(/\ /g, '-') @@ -25,29 +30,27 @@ module.exports = (robot) -> .replace( /%/g, '~p') .toLowerCase() + gen_meme = (template, title1, title2) -> + "#{memegen}#{template}/#{escape title1}/#{escape title2}.jpg" + 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(', '), + title = template.name + names = template.aliases + res.send (gen_meme names[0], title, names.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 + args = (i.trim() for i in res.match[1].split ',') + return res.send usage if args.length != 3 - meme = (escape i.trim() for i in args.split ',').join '/' - res.send memegen + meme + '.jpg' + res.send gen_meme args... robot.respond /memes( -v)?/i, (res) -> if not res.match[1]?