Class: BotBase
- Inherits:
-
Object
- Object
- BotBase
- Defined in:
- lib/botbase.rb
Instance Method Summary collapse
-
#initialize(config = nil, botname: 'Nicole', notifier: nil) ⇒ BotBase
constructor
A new instance of BotBase.
- #received(sender = 'user01', msg, mode: :voicechat, echo_node: 'node1') ⇒ Object
- #restart ⇒ Object
Constructor Details
#initialize(config = nil, botname: 'Nicole', notifier: nil) ⇒ 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) @h = nil if config then @h = SimpleConfig.new(config).to_h # load the service modules @modules = initialize_modules(@h[:modules]) end @botname, @notifier = botname, notifier end |
Instance Method Details
#received(sender = 'user01', msg, mode: :voicechat, echo_node: 'node1') ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/botbase.rb', line 29 def received(sender='user01', msg, mode: :voicechat, echo_node: 'node1') msg.rstrip! self.restart if msg == @botname + ' restart' r = nil msg_recognised = @modules.detect do |m| r = m.query(msg, mode: mode, echo_node: echo_node); r and r.length > 0 end return r if msg_recognised '' end |
#restart ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/botbase.rb', line 46 def restart puts 'restarting ...' @modules = initialize_modules(@h[:modules]) if @h @notifier.notice "echo: #{@botname} is now ready" if @notifier end |