Class: BotBase

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil, botname: 'Nicole', notifier: nil, log: nil) ⇒ BotBase

Returns a new instance of BotBase.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/botbase.rb', line 15

def initialize(config=nil, botname: 'Nicole', notifier: nil, log: nil)

  @botname, @notifier, @log, @h = botname, notifier, log, nil
  
  if config then
    
    @h = SimpleConfig.new(config).to_h      
    @modules = initialize_modules(@h[:modules])
    
  end

end

Instance Attribute Details

#logObject (readonly)

Returns the value of attribute log.



12
13
14
# File 'lib/botbase.rb', line 12

def log
  @log
end

Instance Method Details

#notice(msg) ⇒ Object

used for display debug messages from modules



30
31
32
# File 'lib/botbase.rb', line 30

def notice(msg)
  @notifier.notice msg if @notifier
end

#received(sender = 'user01', msg, mode: :voicechat, echo_node: 'node1') ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/botbase.rb', line 34

def received(sender='user01', msg, mode: :voicechat, echo_node: 'node1')

  msg.rstrip!
  
  log.info 'BotBase/received: ' + msg if log
  self.restart if msg == @botname + ' restart'
  
  r = nil
  
  detected = @modules.detect do |m| 
    r = m.query(msg, mode: mode, echo_node: echo_node)
    r and r.length > 0 
  end
  
  if detected then
    
    if mode == :voicechat then
      MTLite.new(r).to_s.gsub(/ +https:\/\/[\S]+/,'')
    else
      MTLite.new(r).to_html
    end

  else
    ''
  end

end

#restartObject



62
63
64
65
66
67
68
# File 'lib/botbase.rb', line 62

def restart

  log.info 'BotBase/restart: restarting ...' if log
  @modules = initialize_modules(@h[:modules]) if @h
  notice "echo: #{@botname} is now ready"
        
end