Improve memes layout
This commit is contained in:
parent
0d637a4af1
commit
1365d1d273
@ -17,6 +17,11 @@
|
|||||||
async = require 'async'
|
async = require 'async'
|
||||||
|
|
||||||
module.exports = (robot) ->
|
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) ->
|
escape = (str) ->
|
||||||
str.replace( /-/g, '--')
|
str.replace( /-/g, '--')
|
||||||
.replace(/\ /g, '-')
|
.replace(/\ /g, '-')
|
||||||
@ -25,29 +30,27 @@ module.exports = (robot) ->
|
|||||||
.replace( /%/g, '~p')
|
.replace( /%/g, '~p')
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
|
|
||||||
|
gen_meme = (template, title1, title2) ->
|
||||||
|
"#{memegen}#{template}/#{escape title1}/#{escape title2}.jpg"
|
||||||
|
|
||||||
send_example = (url, res, callback) ->
|
send_example = (url, res, callback) ->
|
||||||
cb = if callback? then (-> callback()) else (-> return)
|
cb = if callback? then (-> callback()) else (-> return)
|
||||||
|
|
||||||
robot.http(url).get() (err, r, body) ->
|
robot.http(url).get() (err, r, body) ->
|
||||||
template = JSON.parse body
|
template = JSON.parse body
|
||||||
res.send template.name,
|
title = template.name
|
||||||
template.example + '.jpg',
|
names = template.aliases
|
||||||
'alias: ' + template.aliases.join(', '),
|
res.send (gen_meme names[0], title, names.join ', '),
|
||||||
if robot.adapterName is 'tg' then cb else ''
|
if robot.adapterName is 'tg' then cb else ''
|
||||||
|
|
||||||
cb() if robot.adapterName isnt 'tg'
|
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) ->
|
robot.respond /meme (.+)/i, (res) ->
|
||||||
args = res.match[1]
|
args = (i.trim() for i in res.match[1].split ',')
|
||||||
return res.send usage if args.split(',').length != 3
|
return res.send usage if args.length != 3
|
||||||
|
|
||||||
meme = (escape i.trim() for i in args.split ',').join '/'
|
res.send gen_meme args...
|
||||||
res.send memegen + meme + '.jpg'
|
|
||||||
|
|
||||||
robot.respond /memes( -v)?/i, (res) ->
|
robot.respond /memes( -v)?/i, (res) ->
|
||||||
if not res.match[1]?
|
if not res.match[1]?
|
||||||
|
Loading…
Reference in New Issue
Block a user