Class: Botkit::Bot

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBot

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

#callObject



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.

Returns:

  • (Boolean)


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

#message(&block) ⇒ Object



53
54
55
# File 'lib/botkit/bot.rb', line 53

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