Class: Botkit::Bot

Inherits:
Object
  • Object
show all
Includes:
Signal
Defined in:
lib/botkit/bot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#callObject



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.

Returns:

  • (Boolean)


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 handle_incoming_message(message)
  if message.command?
    emit("command:#{message.command}", message)
  else
    emit("internal:message", message)
  end
end

#message(&block) ⇒ Object



50
51
52
# File 'lib/botkit/bot.rb', line 50

def message(&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 parse_message(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_message(_message, reply)
  send_message(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 send_message(message)
end