Class: BotBase
- Inherits:
-
Object
- Object
- BotBase
- Defined in:
- lib/botbase.rb
Instance Attribute Summary collapse
-
#channel_lock ⇒ Object
Returns the value of attribute channel_lock.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#message_prefix ⇒ Object
Returns the value of attribute message_prefix.
Instance Method Summary collapse
-
#initialize(config = nil, botname: 'Nicole', notifier: nil, log: nil, debug: false) ⇒ BotBase
constructor
A new instance of BotBase.
-
#notice(msg) ⇒ Object
displays 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: nil, debug: false) ⇒ BotBase
Returns a new instance of BotBase.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/botbase.rb', line 15 def initialize(config=nil, botname: 'Nicole', notifier: nil, log: nil, debug: false) @botname, @notifier, @log, @h, @debug = botname, notifier, log, nil, debug if config then @h = SimpleConfig.new(config).to_h puts '@h: ' + @h.inspect if @debug @modules = initialize_modules(@h[:modules]) end end |
Instance Attribute Details
#channel_lock ⇒ Object
Returns the value of attribute channel_lock.
13 14 15 |
# File 'lib/botbase.rb', line 13 def channel_lock @channel_lock end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
12 13 14 |
# File 'lib/botbase.rb', line 12 def log @log end |
#message_prefix ⇒ Object
Returns the value of attribute message_prefix.
13 14 15 |
# File 'lib/botbase.rb', line 13 def @message_prefix end |
Instance Method Details
#notice(msg) ⇒ Object
displays debug messages from modules
32 33 34 35 |
# File 'lib/botbase.rb', line 32 def notice(msg) @notifier.notice msg if @notifier puts msg end |
#received(sender = 'user01', msg, mode: :voicechat, echo_node: 'node1') ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/botbase.rb', line 37 def received(sender='user01', msg, mode: :voicechat, echo_node: 'node1') msg.rstrip! if msg.downcase == 'exit' then @channel_lock, @message_prefix = nil, nil end log.info 'BotBase/received: ' + msg if log self.restart if msg == @botname + ' restart' r = nil detected = if @channel_lock then if @debug then notice 'botbase: inside channel locked' notice 'botbase: fullmsg:' + (@message_prefix.to_s + msg).inspect end r = @modules[@channel_lock].query(@message_prefix.to_s + msg, mode: mode, echo_node: echo_node) puts 'r: ' + r.inspect if @debug r and r.length > 0 else if @debug then puts 'before modules.detect' puts '@modules.values: ' + @modules.values\ .map {|x| x.inspect[0..100] }.join("\n") end @modules.detect do |name, obj| puts 'name: ' + name.inspect if @debug r = obj.query(msg, mode: mode, echo_node: echo_node) r and r.length > 0 end end if detected then puts 'detected: ' + detected.inspect[0..200] + ' ...' if @debug if mode == :voicechat then MTLite.new(r).to_s.gsub(/ +https:\/\/[\S]+/,'') else MTLite.new(r).to_html end else '' end end |
#restart ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/botbase.rb', line 95 def restart log.info 'BotBase/restart: restarting ...' if log @modules = initialize_modules(@h[:modules]) if @h notice "echo: #{@botname} is now ready" end |