Class: Lita::Handlers::CustomMeme
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::CustomMeme
- Defined in:
- lib/lita/handlers/custom_meme.rb
Constant Summary collapse
- REDIS_KEY =
"cmeme"
Instance Method Summary collapse
- #meme_add(response) ⇒ Object
- #meme_delete(response) ⇒ Object
- #meme_image(response) ⇒ Object
- #meme_list(response) ⇒ Object
Instance Method Details
#meme_add(response) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/lita/handlers/custom_meme.rb', line 58 def meme_add(response) name, image = response.matches.first name = normalize_key(name) redis.hset(REDIS_KEY, name, image) response.reply "Meme '#{name}' has been added." end |
#meme_delete(response) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/lita/handlers/custom_meme.rb', line 67 def meme_delete(response) key = normalize_key(response.matches.first.first) if redis.hdel(REDIS_KEY, key) >= 1 response.reply "Deleted meme '#{key}'." else response.reply "Meme '#{key}' was not found." end end |
#meme_image(response) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lita/handlers/custom_meme.rb', line 34 def meme_image(response) # If command only is desired, then bail if general message return if config.command_only && !response..command? output = [] response.matches.each do |match| term = normalize_key(match[0]) image = redis.hget(REDIS_KEY, term) if image output << image end end if output.size > 0 response.reply *output elsif response..command? response.reply "Meme not found" end end |
#meme_list(response) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/lita/handlers/custom_meme.rb', line 77 def meme_list(response) keys = redis.hkeys(REDIS_KEY) if keys.empty? response.reply "No memes have been added" else response.reply "Available memes: #{keys.sort.join(', ')}" end end |