Class: Lita::Alias::ChatHandler
- Inherits:
-
Handler
- Object
- Handler
- Lita::Alias::ChatHandler
- Defined in:
- lib/lita/alias/chat_handler.rb
Overview
Chat handler for lita-alias
Instance Method Summary collapse
-
#add(response) ⇒ Object
Route Handlers.
-
#alias_store ⇒ Object
The repository where aliases are persisted.
- #delete(response) ⇒ Object
- #foo(response) ⇒ Object
- #list(response) ⇒ Object
-
#load_aliases(payload) ⇒ Object
Event Handlers.
- #test_alias(response) ⇒ Object
- #trigger_alias(response) ⇒ Object
Instance Method Details
#add(response) ⇒ Object
Route Handlers
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lita/alias/chat_handler.rb', line 46 def add(response) name = response.match_data[1] command = response.match_data[2] # TODO: support multiple commands ac = AliasedCommand.new(name, command) add_alias_route(ac) alias_store.add(ac) response.reply "Added alias '#{name}' for '#{command}'" rescue AliasStore::AliasAddException => e response.reply(e.) end |
#alias_store ⇒ Object
The repository where aliases are persisted
91 92 93 |
# File 'lib/lita/alias/chat_handler.rb', line 91 def alias_store @alias_store ||= AliasStore.new(redis) end |
#delete(response) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/lita/alias/chat_handler.rb', line 80 def delete(response) name = response.match_data[1] ac = alias_store.delete(name) delete_alias_route(ac) response.reply("Deleted alias '#{ac.name}' => '#{ac.command}'") rescue AliasStore::AliasNotFoundException response.reply("Alias '#{name}' does not exist") end |
#foo(response) ⇒ Object
104 105 106 |
# File 'lib/lita/alias/chat_handler.rb', line 104 def foo(response) response.reply 'foo' end |
#list(response) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/lita/alias/chat_handler.rb', line 66 def list(response) aliases = alias_store.list if aliases.empty? = 'No aliases have been saved' else = aliases.map do |ac| "#{ac.name} => #{ac.command}" end end response.reply end |
#load_aliases(payload) ⇒ Object
Event Handlers
36 37 38 39 40 41 |
# File 'lib/lita/alias/chat_handler.rb', line 36 def load_aliases(payload) log.debug("Loading aliases") alias_store.list.each do |ac| add_alias_route(ac) end end |
#test_alias(response) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/lita/alias/chat_handler.rb', line 95 def test_alias(response) command = redis.hgetall(REDIS_ALIASES_KEY).first.last = Lita::Message.new(robot, command, response..source) after(5) do response.reply "Sending #{command}" robot.receive() end end |
#trigger_alias(response) ⇒ Object
60 61 62 63 64 |
# File 'lib/lita/alias/chat_handler.rb', line 60 def trigger_alias(response) ac = alias_store.lookup(response.match_data[1]) = Lita::Message.new(robot, "#{robot.alias}#{ac.command}", response..source) robot.receive() end |