Class: Boty::Bot
- Inherits:
-
Object
- Object
- Boty::Bot
- Includes:
- Eventable, Logger, MatchHandler, Slack
- Defined in:
- lib/boty/bot.rb
Instance Attribute Summary collapse
-
#brain ⇒ Object
readonly
Returns the value of attribute brain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes included from Logger
Attributes included from MatchHandler
Instance Method Summary collapse
- #im(text, destiny: nil, to: nil, user_id: nil) ⇒ Object
-
#initialize(bot_info) ⇒ Bot
constructor
A new instance of Bot.
- #know_how ⇒ Object
- #say(message, api_parameters = {}) ⇒ Object
Methods included from Slack
Methods included from Logger
Methods included from MatchHandler
#commands, #desc, #execute_commands, #execute_matches, #listeners, #match, #no, #no_match, #no_respond, #respond
Methods included from Eventable
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
#brain ⇒ Object (readonly)
Returns the value of attribute brain.
8 9 10 |
# File 'lib/boty/bot.rb', line 8 def brain @brain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/boty/bot.rb', line 8 def id @id end |
#name ⇒ Object (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_how ⇒ Object
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 |