Class: Botkit::Bot
Instance Attribute Summary collapse
-
#halt ⇒ Object
writeonly
When setting ‘bot.halt = true`, the bot will be halted after the current loop.
Instance Method Summary collapse
- #call ⇒ Object
- #command(name, &block) ⇒ Object
- #exception(&block) ⇒ Object
-
#halt? ⇒ Boolean
Detect if bot should halt himself from the loop.
- #handle_incoming_message(message) ⇒ Object
- #message(&block) ⇒ Object
- #parse_message(input, matcher = nil) ⇒ Object
- #reply_message(_message, reply) ⇒ Object
- #report_exception(exception) ⇒ Object
- #send_message(message) ⇒ Object
Instance Attribute Details
#halt=(value) ⇒ Object (writeonly)
When setting ‘bot.halt = true`, the bot will be halted after the current loop.
9 10 11 |
# File 'lib/botkit/bot.rb', line 9 def halt=(value) @halt = value end |
Instance Method Details
#call ⇒ Object
16 17 |
# File 'lib/botkit/bot.rb', line 16 def call end |
#command(name, &block) ⇒ Object
46 47 48 |
# File 'lib/botkit/bot.rb', line 46 def command(name, &block) on("command:#{name}", &block) end |
#exception(&block) ⇒ Object
54 55 56 |
# File 'lib/botkit/bot.rb', line 54 def exception(&block) on("internal:exception", &block) end |
#halt? ⇒ Boolean
Detect if bot should halt himself from the loop.
12 13 14 |
# File 'lib/botkit/bot.rb', line 12 def halt? @halt end |
#handle_incoming_message(message) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/botkit/bot.rb', line 26 def () if .command? emit("command:#{.command}", ) else emit("internal:message", ) end end |
#message(&block) ⇒ Object
50 51 52 |
# File 'lib/botkit/bot.rb', line 50 def (&block) on("internal:message", &block) end |
#parse_message(input, matcher = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/botkit/bot.rb', line 34 def (input, matcher = nil) input = input.to_s _, command, text = *input.match(%r{\A/([^ @]+)(?:@.*?bot)?(?:\s+(.*?))?\z}i) matches = text.to_s.match(matcher) if matcher { command: command, text: command ? text : input, matches: matches&.named_captures } end |
#reply_message(_message, reply) ⇒ Object
22 23 24 |
# File 'lib/botkit/bot.rb', line 22 def (, reply) (reply) end |
#report_exception(exception) ⇒ Object
58 59 60 |
# File 'lib/botkit/bot.rb', line 58 def report_exception(exception) emit("internal:exception", exception) end |
#send_message(message) ⇒ Object
19 20 |
# File 'lib/botkit/bot.rb', line 19 def () end |