Class: Cognition::Bot

Inherits:
Object
  • Object
show all
Defined in:
lib/cognition/bot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBot

Returns a new instance of Bot.



11
12
13
14
# File 'lib/cognition/bot.rb', line 11

def initialize
  # Default plugin, responds to "ping" with "PONG" and provides help text
  register(Cognition::Plugins::Default)
end

Instance Attribute Details

#matchers=(value) ⇒ Object

Sets the attribute matchers

Parameters:

  • value

    the value to set the attribute matchers to.



9
10
11
# File 'lib/cognition/bot.rb', line 9

def matchers=(value)
  @matchers = value
end

#plugins=(value) ⇒ Object

Sets the attribute plugins

Parameters:

  • value

    the value to set the attribute plugins to.



9
10
11
# File 'lib/cognition/bot.rb', line 9

def plugins=(value)
  @plugins = value
end

Instance Method Details

#helpObject



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

def help
  matchers.flat_map(&:help)
end

#plugin_namesObject



35
36
37
# File 'lib/cognition/bot.rb', line 35

def plugin_names
  plugins.map { |p| p.class.name }
end

#process(msg, metadata = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/cognition/bot.rb', line 16

def process(msg,  = {})
  if msg.respond_to? :command
    process_msg(msg)
  else
    process_string(msg.to_s, )
  end
end

#register(klass) ⇒ Object



24
25
26
27
# File 'lib/cognition/bot.rb', line 24

def register(klass)
  return false if plugin_names.include? klass.to_s
  plugins << klass.new(self)
end

#resetObject



29
30
31
32
33
# File 'lib/cognition/bot.rb', line 29

def reset
  @matchers = []
  @plugins = []
  register(Cognition::Plugins::Default)
end