Class: BotBase
- Inherits:
-
Object
- Object
- BotBase
- Defined in:
- lib/botbase.rb
Instance Method Summary collapse
-
#debug(msg) ⇒ Object
used for display debug messages from modules.
-
#initialize(config = nil, botname: 'Nicole', notifier: nil, debug: false) ⇒ 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, debug: false) ⇒ BotBase
Returns a new instance of BotBase.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/botbase.rb', line 12 def initialize(config=nil, botname: 'Nicole', notifier: nil, debug: false) @h = nil @botname, @notifier, @debug = botname, notifier, debug if config then @h = SimpleConfig.new(config).to_h puts 'j:' + @h.inspect # load the service modules @modules = initialize_modules(@h[:modules]) end end |
Instance Method Details
#debug(msg) ⇒ Object
used for display debug messages from modules
31 32 33 |
# File 'lib/botbase.rb', line 31 def debug(msg) notice 'botbase/debug: ' + msg if @debug end |
#notice(msg) ⇒ Object
used for display debug messages from modules
37 38 39 |
# File 'lib/botbase.rb', line 37 def notice(msg) @notifier.notice msg if @notifier end |
#received(sender = 'user01', msg, mode: :voicechat, echo_node: 'node1') ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/botbase.rb', line 41 def received(sender='user01', msg, mode: :voicechat, echo_node: 'node1') msg.rstrip! 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
61 62 63 64 65 66 67 |
# File 'lib/botbase.rb', line 61 def restart puts 'restarting ...' @modules = initialize_modules(@h[:modules]) if @h notice "echo: #{@botname} is now ready" end |