Class: Lita::Handlers::Jarvis
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Jarvis
- Defined in:
- lib/lita/handlers/jarvis.rb
Instance Method Summary collapse
- #format_reply(message:) ⇒ Object
- #greet(response) ⇒ Object
- #handle_unhandled(payload:) ⇒ Object
- #reply_target(message:) ⇒ Object
- #should_reply?(message:) ⇒ Boolean
Instance Method Details
#format_reply(message:) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lita/handlers/jarvis.rb', line 40 def format_reply(message:) name = .user = ["As always, @#{name}, a great pleasure watching you work.", "I've taken the liberty of preparing a help function for you.", "I'm afraid I don't understand your request @#{name}", "I'm not currently programmed to do that @#{name}", "That command failed. Perhaps I will run a self diagnostic", "I feel this may be a cliche, but 'Does not compute'"] .sample end |
#greet(response) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/lita/handlers/jarvis.rb', line 7 def greet(response) name = response.user.name greetings = ["Welcome back #{name}","Hello #{name}"] answer = greetings.sample response.reply("#{answer}") end |
#handle_unhandled(payload:) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/lita/handlers/jarvis.rb', line 19 def handle_unhandled(payload:) = payload[:message] if should_reply?(message: ) target = reply_target(message: ) robot.(target, format_reply( message: )) end end |
#reply_target(message:) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/lita/handlers/jarvis.rb', line 32 def reply_target(message:) if .source. Source.new(user: .user, private_message: true) else Source.new(room: .source.room) end end |
#should_reply?(message:) ⇒ Boolean
28 29 30 |
# File 'lib/lita/handlers/jarvis.rb', line 28 def should_reply?(message:) .command? && .match(/^@#{robot.name}/) end |