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
- #getName(username) ⇒ Object
- #greet(response) ⇒ Object
- #handle_unhandled(payload:) ⇒ Object
- #reply_target(message:) ⇒ Object
- #set_name(response) ⇒ Object
- #should_reply?(message:) ⇒ Boolean
- #welcome(response) ⇒ Object
Instance Method Details
#format_reply(message:) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/lita/handlers/jarvis.rb', line 82 def format_reply(message:) name = getName(.user.name) = ["As always, #{name}, a great pleasure watching you work.", "I've taken the liberty of preparing a help function for you. Please just say help", "I'm afraid I don't understand your request #{name}", "I'm not currently programmed to do that #{name}", "I seem to do quite well for a stretch, and then at the end of the sentence I say the wrong cranberry.", "I have failed to parse that command. I do have my limits after all.", "I feel this may be a cliche, but 'Does not compute'"] .sample end |
#getName(username) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/lita/handlers/jarvis.rb', line 17 def getName(username) if redis.get(username) then requestedName = redis.get(username) else requestedName = username end end |
#greet(response) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lita/handlers/jarvis.rb', line 25 def greet(response) t = Time.now.hour name = getName(response.user.name) if t.between?(4,11) then answer = "Good Morning #{name}" elsif t.between?(12, 18) then answer = "Good Afternoon #{name}" elsif t.between?(18,23) then answer = "Good Evening #{name}" else answer = "It's very late #{name}" end response.reply("#{answer}") end |
#handle_unhandled(payload:) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/lita/handlers/jarvis.rb', line 61 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
74 75 76 77 78 79 80 |
# File 'lib/lita/handlers/jarvis.rb', line 74 def reply_target(message:) if .source. Source.new(user: .user, private_message: true) else Source.new(room: .source.room) end end |
#set_name(response) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/lita/handlers/jarvis.rb', line 47 def set_name(response) requestedName = response.args[1] redis.set(response.user.name, requestedName) if redis.get(response.user.name) response.reply("I have recorded your preferred designation #{requestedName}") else response.reply_privately("There seems to have been a problem") end end |
#should_reply?(message:) ⇒ Boolean
70 71 72 |
# File 'lib/lita/handlers/jarvis.rb', line 70 def should_reply?(message:) .command? && .match(/^@#{robot.name}/) end |
#welcome(response) ⇒ Object
42 43 44 45 |
# File 'lib/lita/handlers/jarvis.rb', line 42 def welcome(response) name = getName(response.user.name) response.reply("You're welcome #{name}") end |