Class: BotBaseModuleDemo

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

Overview

A service module used by the BotBase gem

Instance Method Summary collapse

Constructor Details

#initialize(x = nil) ⇒ BotBaseModuleDemo

Returns a new instance of BotBaseModuleDemo.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/botbase-module-demo.rb', line 9

def initialize(x=nil)
  
  @phrases = {}
  service_modules = nil
  
  a = if service_modules then
  
    service_modules

  else
    
    @h = {
        "^What's the time?" => "'The time is ' + Time.now.strftime(\"%-I:%M%p\")",
        "hello?" => %q("hello #{sender}, how can I help you?" % sender),
        'unknown' => "\"I'm sorry, I don't understand what you said.\""
    }
    [@h]

  end
  
  a.each {|x|  @phrases.merge! x }  

end

Instance Method Details

#query(sender = 'user01', msg, mode: :chat) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/botbase-module-demo.rb', line 33

def query(sender='user01', msg, mode: :chat)
  r = @phrases.detect {|k,v|  msg =~ /#{k}/i }

  raw_msg = if r then
    r.last 
  else  
    @h['unknown']      
  end
  
  response = eval raw_msg   
end