Top Level Namespace
Defined Under Namespace
Classes: Bot
Constant Summary collapse
- ROOM =
ARGV[0]
- ON_MASTER_ROOM =
false
- ADMIN_USERS =
ARGV[1].split(",")
- RULES_FILE =
ARGV[2]
- STATUS_INIT =
ARGV[3].to_sym
- SHORTCUTS_FILE =
"hipchat_smart_shortcuts_#{ROOM}.rb".gsub(" ", "_")
Instance Method Summary collapse
-
#ask(question, context, to, jid_user) ⇒ Object
context: previous message to: user that should answer.
- #respond(message, jid_user) ⇒ Object
-
#rules(from, command, processed, jid_user) ⇒ Object
from: Full name of the person sending the message command: command to run processed: in case the command has been already processed on Bot class, by default false help: These are specific commands on this bot.
Instance Method Details
#ask(question, context, to, jid_user) ⇒ Object
context: previous message to: user that should answer
14 15 16 17 |
# File 'lib/hipchat_smart_rules.rb', line 14 def ask(question, context, to, jid_user) puts "Bot: #{question}" @questions[to]=context end |
#respond(message, jid_user) ⇒ Object
8 9 10 |
# File 'lib/hipchat_smart_rules.rb', line 8 def respond(, jid_user) puts end |
#rules(from, command, processed, jid_user) ⇒ Object
from: Full name of the person sending the message command: command to run processed: in case the command has been already processed on Bot class, by default false help: These are specific commands on this bot. help: They will be accessible only when the bot is listening to you just writing the command help: or the bot is not listening to you but requested on demand, for example: help: !THE_COMMAND help: @bot THE_COMMAND help: @FIRST_NAME_BOT THE_COMMAND help: FIRST_NAME_BOT THE_COMMAND help:
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hipchat_smart_rules.rb', line 31 def rules(from, command, processed, jid_user) if @testing puts "#{from}: #{command}" if @questions.keys.include?(from) context = @questions[from] @questions[from] = command command = context end end firstname = from.split(" ").first case command # help: echo SOMETHING # help: repeats SOMETHING # help: when /echo\s(.+)/i respond $1, jid_user # help: go to sleep # help: it will sleep the bot for 10 seconds # help: when /go\sto\ssleep/i unless @questions.keys.include?(from) ask("do you want me to take a siesta?", command, from, jid_user) else case @questions[from] when /yes/i, /yep/i, /sure/i respond "zZzzzzzZZZZZZzzzzzzz!", jid_user respond "I'll be sleeping for 10 secs... just for you", jid_user sleep 10 when /no/i, /nope/i, /cancel/i @questions.delete(from) respond "Thanks, I'm happy to be awake", jid_user else respond "I don't understand", jid_user ask("are you sure do you want me to sleep? (yes or no)", "go to sleep", from, jid_user) end end else unless processed resp = %w{ what huh sorry }.sample respond "#{firstname}: #{resp}?", jid_user end end end |