botbase 0.1.4 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/botbase.rb +80 -22
  5. metadata +49 -26
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c49f48d9068f6671537fbc4b3d918d20000b9db4
4
- data.tar.gz: c06f85abe4019c35066b3306425848e027a9cb9c
2
+ SHA256:
3
+ metadata.gz: 3bbd23516c8209afe0fdb853910f6b0c92c21b8dd62065ce7b7454a2273469b7
4
+ data.tar.gz: a905535704581fdbbf8fb4857565bff1e238328c911db44cc94c49209a2bc64a
5
5
  SHA512:
6
- metadata.gz: 1e40e2b91ee40ad574ae5ae08778d6c5df2a068fedfd6ac97c70fa15fc5a346b14836906841d5850dce914825f2451039dc72b37a5804bc2decd80bff3a2ae71
7
- data.tar.gz: 4fc7f28b12980b0a0efc23ab19af8c5f32ce5206dd83ad024c27fcd50fa1eb140d83f3e83af143adbd42ea88b3471b95143b9e6a53624b8cf09eb61296c0eeec
6
+ metadata.gz: aadebb98b3ce7d1f64272e32d67e8bdfe9673043305c0d0135f2757feb44386aa64c6e3e3a216a6ccf04b5da4a16b9e397ca6ff104fee496208f629cda1402df
7
+ data.tar.gz: 9674b8b047ffbbaa524920c8e1920143854032b32efd50fbe81d77e70ae0aebf83506ffdf30467c68ddd10f4e4fcf3981f98290291286a497b6ac4d81be7ada0
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -3,51 +3,100 @@
3
3
  # file: botbase.rb
4
4
 
5
5
 
6
+ require 'mtlite'
6
7
  require 'simple-config'
7
8
 
8
9
 
9
-
10
- class BotBase
10
+ class BotBase
11
11
 
12
- def initialize(config=nil, botname: 'Nicole', notifier: nil)
13
-
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)
15
17
 
18
+ @botname, @notifier, @log, @h, @debug = botname, notifier, log, nil, debug
19
+
16
20
  if config then
17
21
 
18
22
  @h = SimpleConfig.new(config).to_h
19
-
20
- # load the service modules
23
+ puts '@h: ' + @h.inspect if @debug
21
24
  @modules = initialize_modules(@h[:modules])
22
25
 
23
26
  end
24
-
25
- @botname, @notifier = botname, notifier
26
27
 
27
28
  end
28
29
 
29
- def received(sender='user01', msg, mode: :voicechat)
30
+ # displays debug messages from modules
31
+ #
32
+ def notice(msg)
33
+ @notifier.notice msg if @notifier
34
+ puts msg
35
+ end
36
+
37
+ def received(sender='user01', msg, mode: :voicechat, echo_node: 'node1')
30
38
 
31
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
32
46
  self.restart if msg == @botname + ' restart'
33
47
 
34
48
  r = nil
35
49
 
36
- msg_recognised = @modules.detect do |m|
37
- r = m.query(msg, mode: mode); r and r.length > 0
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
+
38
76
  end
39
77
 
40
- return r if msg_recognised
41
78
 
42
- ''
79
+ if detected then
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
+
89
+ else
90
+ ''
91
+ end
43
92
 
44
93
  end
45
94
 
46
95
  def restart
47
96
 
48
- puts 'restarting ...'
97
+ log.info 'BotBase/restart: restarting ...' if log
49
98
  @modules = initialize_modules(@h[:modules]) if @h
50
- @notifier.notice "echo: #{@botname} is now ready" if @notifier
99
+ notice "echo: #{@botname} is now ready"
51
100
 
52
101
  end
53
102
 
@@ -55,17 +104,26 @@ class BotBase
55
104
 
56
105
  def initialize_modules(modules)
57
106
 
58
- modules.inject([]) do |r, m|
107
+ a = modules.map do |name, settings|
59
108
 
60
- name, settings = m
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
61
115
 
62
116
  klass_name = 'BotBaseModule' + name.to_s
63
-
64
- r << Kernel.const_get(klass_name).new(settings)
117
+
118
+ [name, Kernel.const_get(klass_name).new(settings.merge({callback: self,
119
+ debug: @debug}))]
65
120
 
66
121
  end
122
+
123
+ puts 'a: ' + a[0..100].inspect if @debug
124
+ a.to_h
125
+
67
126
 
68
127
  end
69
-
70
128
 
71
- end
129
+ end
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.4
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,29 +10,53 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
- YXN0ZX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wwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEANqST3Gm40i57l2OKhRbdS4FOR/XkqeHhTwu0WFp3
29
+ wsjAQukDmPg8vNvNiHTZ5zvN24c0k419zdzzTvL9bCj6it8nsRWJaSIZLkhaL+xM
30
+ DA4gur/nt5CZKZS0l0EYaJd9WzTTasHtm35zes6P3sWJQYlT0miUFy6EGYoimtvr
31
+ 0w5Ede3UNDxb6pE0WA0a482Jmos9UeHYf9eilENDRyFx+YZa7GSdZXlsiv9GK+IC
32
+ 262I7WGjLgCUNff+IyUpqoamAKS1QnPaESTOuveagyLCFS1vPNHAKYK5AZBFcf6y
33
+ 8ebqh6Juc9VkxCopWu04bDjrjCvNZ04YtbUwvP5ypsK6PqMw+leSn6T9aN8H3jcc
34
+ als1Sa+uEEug4C+DfnxUhoC0AvbZHy8DfDB8b0CRwqfo4PHDQUEDMSuoq62MuGqw
35
+ 6lxxv/jQ5LA2SHCIatmdVQQqUXVpPmCojcHy4+FB0Vfcq9e/pEdiGEhaJnQkNjMc
36
+ NH8JIgyRVXldUCa9Ahsubk7V
33
37
  -----END CERTIFICATE-----
34
- date: 2017-05-08 00:00:00.000000000 Z
38
+ date: 2020-07-03 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.3'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.3.5
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.3'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.3.5
36
60
  - !ruby/object:Gem::Dependency
37
61
  name: simple-config
38
62
  requirement: !ruby/object:Gem::Requirement
@@ -42,7 +66,7 @@ dependencies:
42
66
  version: '0.6'
43
67
  - - ">="
44
68
  - !ruby/object:Gem::Version
45
- version: 0.6.1
69
+ version: 0.6.4
46
70
  type: :runtime
47
71
  prerelease: false
48
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -52,7 +76,7 @@ dependencies:
52
76
  version: '0.6'
53
77
  - - ">="
54
78
  - !ruby/object:Gem::Version
55
- version: 0.6.1
79
+ version: 0.6.4
56
80
  description:
57
81
  email: james@jamesrobertson.eu
58
82
  executables: []
@@ -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.8
106
+ rubygems_version: 3.0.3
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