Class: MemeGeneratorPlugin
- Inherits:
-
Plugin
- Object
- Plugin
- MemeGeneratorPlugin
- Defined in:
- lib/rbot-meme_generator/plugin.rb
Instance Method Summary collapse
- #gen(m, params) ⇒ Object
- #help(plugin, topic = '') ⇒ Object
- #imgur_key(m, params) ⇒ Object
- #list(m, params) ⇒ Object
Instance Method Details
#gen(m, params) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rbot-meme_generator/plugin.rb', line 38 def gen(m, params) begin lines = Shellwords.split(params[:lines].join(' ')) if lines.size > 0 generator = Meme.new(params[:generator]) img_url = generator.generate(*lines) if @registry[:imgur_key] imgur_client = Imgur2.new(@registry[:imgur_key]) open(img_url, 'rb') do |f| m.reply imgur_client.upload(f)['upload']['links']['original'] end else m.reply img_url end else m.reply "incorrect usage: #{help m.plugin}" end rescue Meme::Error => e m.reply e end end |
#help(plugin, topic = '') ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rbot-meme_generator/plugin.rb', line 23 def help(plugin, topic='') case topic when 'list' then 'meme list => list meme generators' when 'imgur' then 'meme imgur key => set imgur API key' else 'generate a meme image using memegenerator.net: meme (imgur key | list | generator line1 [additional lines])' end end |
#imgur_key(m, params) ⇒ Object
60 61 62 63 |
# File 'lib/rbot-meme_generator/plugin.rb', line 60 def imgur_key(m, params) @registry[:imgur_key] = params[:key] m.reply 'imgur key set' end |
#list(m, params) ⇒ Object
34 35 36 |
# File 'lib/rbot-meme_generator/plugin.rb', line 34 def list(m, params) m.reply(Meme::GENERATORS.map { |k,v| "#{k}=#{v[2]}" }.sort.join(', ')) end |