botbase 0.1.6 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/botbase.rb +85 -45
  4. data.tar.gz.sig +0 -0
  5. metadata +52 -29
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ff6c3b0ea464e7839677611732bb1389551737a8
4
- data.tar.gz: 1ad5c911800819f41a64ee43ecb6cbee28973923
2
+ SHA256:
3
+ metadata.gz: 801284ecc457532920f6f6ae54adaa0dc9ff49d2f2b021341cd4d4bf5f4e4ef9
4
+ data.tar.gz: 1638c34bc647c6d550e662f621b715e0d473877094c04d5a6351cfbaf19dc83b
5
5
  SHA512:
6
- metadata.gz: 13c7599d1d80812e1c19affcc5d0f7537552025aee3bef8acf106c9deb222d3b15fb0c1f1825f924c22174392e8d39496ebe09c7606df67c2f0b070f460a7936
7
- data.tar.gz: 7a6b77d09ddfcc2e1e7cbbe21d634b51e56c2e3e22fc05ed37cc425b45c30ddd8cb01ab2261a57184a0759677962b821c5c3f46a8102d662811d473e527c784c
6
+ metadata.gz: a3309cf2096cfadf1f638177c94360fbbeb8c213ec11c6ea61bb994f40e2b9db4c3b3c0b6ea6fc913f43abcddf832bcda8eebb138acaaf2915d4210719654060
7
+ data.tar.gz: f410511eb2994605d428532a5e1ad90b59d46f7d022f4b0637f65fcc594526f81741c4989bb216ab87122175d809fa128f75e682bb68541dc6b972a56733afcd
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/botbase.rb CHANGED
@@ -3,55 +3,89 @@
3
3
  # file: botbase.rb
4
4
 
5
5
 
6
+ require 'mtlite'
6
7
  require 'simple-config'
7
8
 
8
9
 
9
-
10
10
  class BotBase
11
-
12
- def initialize(config=nil, botname: 'Nicole', notifier: nil, debug: false)
13
11
 
14
- @h = nil
12
+ attr_reader :log
13
+ attr_accessor :channel_lock, :message_prefix
14
+
15
+ def initialize(config=nil, botname: 'Nicole', notifier: nil, log: nil,
16
+ debug: false)
17
+
18
+ @botname, @notifier, @log, @h, @debug = botname, notifier, log, nil, debug
15
19
 
16
- @botname, @notifier, @debug = botname, notifier, debug
17
-
18
20
  if config then
19
-
20
- @h = SimpleConfig.new(config).to_h
21
- puts 'j:' + @h.inspect
22
- # load the service modules
21
+
22
+ @h = SimpleConfig.new(config).to_h
23
+ puts '@h: ' + @h.inspect if @debug
23
24
  @modules = initialize_modules(@h[:modules])
24
-
25
+
25
26
  end
26
27
 
27
28
  end
28
-
29
- # used for display debug messages from modules
30
- #
31
- def debug(msg)
32
- notice 'botbase/debug: ' + msg if @debug
33
- end
34
-
35
- # used for display debug messages from modules
29
+
30
+ # displays debug messages from modules
36
31
  #
37
32
  def notice(msg)
38
33
  @notifier.notice msg if @notifier
39
- end
40
-
34
+ puts msg
35
+ end
36
+
41
37
  def received(sender='user01', msg, mode: :voicechat, echo_node: 'node1')
42
38
 
43
39
  msg.rstrip!
40
+
41
+ if msg.downcase == 'exit' then
42
+ @channel_lock, @message_prefix = nil, nil
43
+ end
44
+
45
+ log.info 'BotBase/received: ' + msg if log
44
46
  self.restart if msg == @botname + ' restart'
45
-
47
+
46
48
  r = nil
47
-
48
- detected = @modules.detect do |m|
49
- r = m.query(msg, mode: mode, echo_node: echo_node)
50
- r and r.length > 0
49
+
50
+ detected = if @channel_lock then
51
+
52
+ if @debug then
53
+ notice 'botbase: inside channel locked'
54
+ notice 'botbase: fullmsg:' + (@message_prefix.to_s + msg).inspect
55
+ end
56
+
57
+ r = @modules[@channel_lock].query(@message_prefix.to_s + msg,
58
+ mode: mode, echo_node: echo_node)
59
+ puts 'r: ' + r.inspect if @debug
60
+ r and r.length > 0
61
+
62
+ else
63
+
64
+ if @debug then
65
+ puts 'before modules.detect'
66
+ puts '@modules.values: ' + @modules.values\
67
+ .map {|x| x.inspect[0..100] }.join("\n")
68
+ end
69
+
70
+ @modules.detect do |name, obj|
71
+ puts 'name: ' + name.inspect if @debug
72
+ r = obj.query(msg, mode: mode, echo_node: echo_node)
73
+ r and r.length > 0
74
+ end
75
+
51
76
  end
52
-
77
+
78
+
53
79
  if detected then
54
- r
80
+
81
+ puts 'detected: ' + detected.inspect[0..200] + ' ...' if @debug
82
+
83
+ if mode == :voicechat then
84
+ MTLite.new(r).to_s.gsub(/ +https:\/\/[\S]+/,'')
85
+ else
86
+ MTLite.new(r).to_html
87
+ end
88
+
55
89
  else
56
90
  ''
57
91
  end
@@ -60,30 +94,36 @@ class BotBase
60
94
 
61
95
  def restart
62
96
 
63
- puts 'restarting ...'
97
+ log.info 'BotBase/restart: restarting ...' if log
64
98
  @modules = initialize_modules(@h[:modules]) if @h
65
99
  notice "echo: #{@botname} is now ready"
66
-
100
+
67
101
  end
68
-
102
+
69
103
  private
70
-
104
+
71
105
  def initialize_modules(modules)
72
-
73
- modules.inject([]) do |r, m|
74
-
75
- name, settings = m
76
-
77
- debug 'initialising botbase-module-' + name.to_s
78
-
106
+
107
+ a = modules.map do |name, settings|
108
+
109
+ settings = {} if settings.is_a? String
110
+
111
+ if log then
112
+ log.info 'BotBase/initialize_modules: ' +
113
+ 'initialising botbase-module-' + name.to_s
114
+ end
115
+
79
116
  klass_name = 'BotBaseModule' + name.to_s
80
117
 
81
-
82
- r << Kernel.const_get(klass_name).new(settings.merge({callback: self}))
118
+ [name, Kernel.const_get(klass_name).new(**settings.merge({callback: self,
119
+ debug: @debug}))]
83
120
 
84
121
  end
85
-
86
- end
87
122
 
88
-
89
- end
123
+ puts 'a: ' + a[0..100].inspect if @debug
124
+ a.to_h
125
+
126
+
127
+ end
128
+
129
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: botbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,51 +10,75 @@ b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nb+qKJLL0vZGdW7LuB0JifKY9LikC5evipOSos5tdzUg75Py8ECAwEA
25
+ AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU8p+uyIrA
26
+ nUjO5yD1hormXlgS144wJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEAG0/x3cnRIl8bMU26Jx4yD4H7hx1YdAiOk3ySWjU8
29
+ P+3aWZq+9AtgC0TtgRG4sHIipoDarQfxXt8FXMo7AwRg+NhzL3xFHdtUKsah1hOE
30
+ DKthV6xIdIaGTuBxbFD1hB8eS29CpkgT7mhvL+sDwcCd+AU89A5DpLrIVKXZj09W
31
+ BzCNk4ZgPoCa/ELtGZSdXOw1I+fST8RPFzl7odXDVTPbViLRlQGNjy7nUaCX5Gzf
32
+ Xjy2/XlRfMhNUE/rdconP2gkLZ/UogT3oPXWWHCYT2NfWEme29O7Oo4bhLfDbi/t
33
+ gXKQpLqSFAl3GIiL6MKM6NCpS/f6N4NVdQ7oNyVdm2/gYq9k4U5s0fZ3MFc8NVUS
34
+ 9pKO1E6ZwgJWCS8i3OXR+KGLD6vM9EXKxhHt3xTTmmDSkh+NSFX7cUCFrT2JMf9h
35
+ IAiTYWcp2K6HhPr/C46tBo6SMl9cc8ZhSEe6o+v8LhynIxIGj7fUgkDRI7mFC8BE
36
+ apXkbMI804Bcbz4RKd7yRvY/
33
37
  -----END CERTIFICATE-----
34
- date: 2017-10-14 00:00:00.000000000 Z
38
+ date: 2022-02-18 00:00:00.000000000 Z
35
39
  dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: mtlite
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.4'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.4.1
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.4'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.4.1
36
60
  - !ruby/object:Gem::Dependency
37
61
  name: simple-config
38
62
  requirement: !ruby/object:Gem::Requirement
39
63
  requirements:
40
64
  - - "~>"
41
65
  - !ruby/object:Gem::Version
42
- version: '0.6'
66
+ version: '0.7'
43
67
  - - ">="
44
68
  - !ruby/object:Gem::Version
45
- version: 0.6.1
69
+ version: 0.7.2
46
70
  type: :runtime
47
71
  prerelease: false
48
72
  version_requirements: !ruby/object:Gem::Requirement
49
73
  requirements:
50
74
  - - "~>"
51
75
  - !ruby/object:Gem::Version
52
- version: '0.6'
76
+ version: '0.7'
53
77
  - - ">="
54
78
  - !ruby/object:Gem::Version
55
- version: 0.6.1
79
+ version: 0.7.2
56
80
  description:
57
- email: james@jamesrobertson.eu
81
+ email: digital.robertson@gmail.com
58
82
  executables: []
59
83
  extensions: []
60
84
  extra_rdoc_files: []
@@ -79,8 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
103
  - !ruby/object:Gem::Version
80
104
  version: '0'
81
105
  requirements: []
82
- rubyforge_project:
83
- rubygems_version: 2.6.13
106
+ rubygems_version: 3.2.22
84
107
  signing_key:
85
108
  specification_version: 4
86
109
  summary: Provides bot functionality primarily for use by the sps_bot gem.
metadata.gz.sig CHANGED
Binary file