Class: BotBase
- Inherits:
-
Object
- Object
- BotBase
- Defined in:
- lib/botbase.rb
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
Instance Method Summary collapse
-
#initialize(config = nil, botname: 'Nicole', notifier: nil, log: log) ⇒ BotBase
constructor
A new instance of BotBase.
-
#notice(msg) ⇒ Object
used for display debug messages from modules.
- #received(sender = 'user01', msg, mode: :voicechat, echo_node: 'node1') ⇒ Object
- #restart ⇒ Object
Constructor Details
#initialize(config = nil, botname: 'Nicole', notifier: nil, log: log) ⇒ BotBase
Returns a new instance of BotBase.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/botbase.rb', line 14 def initialize(config=nil, botname: 'Nicole', notifier: nil, log: log) @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
#log ⇒ Object (readonly)
Returns the value of attribute log.
11 12 13 |
# File 'lib/botbase.rb', line 11 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 |
# 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 r else '' end end |
#restart ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/botbase.rb', line 56 def restart log.info 'BotBase/restart: restarting ...' @modules = initialize_modules(@h[:modules]) if @h notice "echo: #{@botname} is now ready" end |