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
-
#initialize ⇒ Bot
constructor
A new instance of Bot.
- #message(&block) ⇒ Object
- #parse_message(input) ⇒ Object
- #reply_message(_message, reply) ⇒ Object
- #report_exception(exception) ⇒ Object
- #send_message(message) ⇒ Object
Constructor Details
#initialize ⇒ Bot
Returns a new instance of Bot.
11 12 13 |
# File 'lib/botkit/bot.rb', line 11 def initialize @halt = false end |
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
20 21 |
# File 'lib/botkit/bot.rb', line 20 def call end |
#command(name, &block) ⇒ Object
49 50 51 |
# File 'lib/botkit/bot.rb', line 49 def command(name, &block) on("command:#{name}", &block) end |
#exception(&block) ⇒ Object
57 58 59 |
# File 'lib/botkit/bot.rb', line 57 def exception(&block) on("internal:exception", &block) end |
#halt? ⇒ Boolean
Detect if bot should halt himself from the loop.
16 17 18 |
# File 'lib/botkit/bot.rb', line 16 def halt? @halt end |
#handle_incoming_message(message) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/botkit/bot.rb', line 30 def () if .command? emit("command:#{.command}", ) else emit("internal:message", ) end end |
#message(&block) ⇒ Object
53 54 55 |
# File 'lib/botkit/bot.rb', line 53 def (&block) on("internal:message", &block) end |
#parse_message(input) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/botkit/bot.rb', line 38 def (input) input = input.to_s _, command, text = *input.match(%r{\A/([^ @]+)(?:@.*?bot)?(?:\s+(.*?))?\z}i) { command: command, text: command ? text : input } end |
#reply_message(_message, reply) ⇒ Object
26 27 28 |
# File 'lib/botkit/bot.rb', line 26 def (, reply) (reply) end |
#report_exception(exception) ⇒ Object
61 62 63 |
# File 'lib/botkit/bot.rb', line 61 def report_exception(exception) emit("internal:exception", exception) end |
#send_message(message) ⇒ Object
23 24 |
# File 'lib/botkit/bot.rb', line 23 def () end |