Class: Boty::Bot

Inherits:
Object
  • Object
show all
Includes:
Eventable, Logger, MatchHandler, Slack
Defined in:
lib/boty/bot.rb

Instance Attribute Summary collapse

Attributes included from Logger

#logger

Attributes included from MatchHandler

#trigger_message

Instance Method Summary collapse

Methods included from Slack

#User, chat, rtm, users

Methods included from Logger

adapter, adapter=, #log_error

Methods included from MatchHandler

#commands, #desc, #execute_commands, #execute_matches, #listeners, #match, #no, #no_match, #no_respond, #respond

Methods included from Eventable

#event, #events, #off, #on

Constructor Details

#initialize(bot_info) ⇒ Bot

Returns a new instance of Bot.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/boty/bot.rb', line 10

def initialize(bot_info)
  Locale.reload
  @raw_info = bot_info
  @id       = bot_info["id"]
  @name     = bot_info["name"]

  @brain ||= {}

  on :message, &method(:message_handler)
  ScriptLoader.new(self).load
end

Instance Attribute Details

#brainObject (readonly)

Returns the value of attribute brain.



8
9
10
# File 'lib/boty/bot.rb', line 8

def brain
  @brain
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/boty/bot.rb', line 8

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/boty/bot.rb', line 8

def name
  @name
end

Instance Method Details

#im(text, destiny: nil, to: nil, user_id: nil) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/boty/bot.rb', line 29

def im(text, destiny: nil, to: nil, user_id: nil)
  destiny = User(user_id) || user_by_name(destiny, to)
  if destiny
    logger.debug do "Sending #{text} to #{destiny.name}." end
    Slack.chat.post_im destiny.id, text
  else
    logger.debug do "User not found, refusing to send im." end
  end
end

#know_howObject



39
40
41
42
# File 'lib/boty/bot.rb', line 39

def know_how
  actions = Array(commands) + Array(listeners)
  actions.sort_by { |action| action.desc.command || "_" }
end

#say(message, api_parameters = {}) ⇒ Object



22
23
24
25
26
27
# File 'lib/boty/bot.rb', line 22

def say(message, api_parameters = {})
  channel = (trigger_message && trigger_message.channel) || "#general"
  options = { channel: channel }.merge api_parameters
  post_response = Slack.chat.post_message message, options
  logger.debug { "Post response: #{post_response}." }
end