Class: Lita::Handlers::Todo
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Todo
- Defined in:
- lib/lita/handlers/todo.rb
Instance Method Summary collapse
Instance Method Details
#add(response) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/lita/handlers/todo.rb', line 25 def add(response) user_id = response..source.user.id.to_s task = response.match_data['task'] redis.rpush(user_id, task) response.reply("task #{redis.llen(user_id) - 1} added") end |
#delete(response) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/lita/handlers/todo.rb', line 32 def delete(response) user_id = response..source.user.id.to_s task = response.match_data['task'] text = redis.lindex user_id, task redis.lset(user_id, task, nil) response.reply("task #{task} (#{text}) deleted") end |
#list(response) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/lita/handlers/todo.rb', line 10 def list(response) user_id = response..source.user.id.to_s reply = [] redis.lrange(user_id, 0, -1).each_with_index do |task, index| unless task.nil? || task == '' reply << "[#{index}] #{task}" end end if reply.empty? response.reply "todo list is empty" else response.reply(reply.join("\n")) end end |