ssc.bot 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1468b04f2b3b2b2e388b2ab044ad52e8bf55d53343d4ff75d2dd56c9387b843
4
- data.tar.gz: f8ccc21500f7b394f3be858c24d59c18c453a333da03be6265e59a6224897ba0
3
+ metadata.gz: 988c653f2db596a5d3b9b0e1537f2443e6c41f65842df5ba6a4283a564f7d916
4
+ data.tar.gz: a272071c621d71f278761f77a34dc787984a86f10ef15fabe48668e7c4d342bf
5
5
  SHA512:
6
- metadata.gz: 2fb0d8ed2cd691b5a40de2a103bcb3c050da49a4993e76bcd5a2b22e3fd8edf431e9de1be271bc71abadc28218721fc0fb8f1e30127743c08bc782e25b49b790
7
- data.tar.gz: e0d5ad76f4ee548a4b6e5e191534badb10ef39e44644179a910e05b71b325963bed96b9892c82b25606ee78ff45dd32cac35ea247288225bd6f0bd6b7be40bc3
6
+ metadata.gz: a5525a87c8cb6ca2186ee20d596c44c76f6a85e6fb3996b94e314c10510dd4195837c29154951a6afd78251fce6861bf501b77e869320c41880a9da71f376f99
7
+ data.tar.gz: 7ba1b91a451d94cf01a1f1fab8de7e5892da04cffbca0d3085b162538c58c3b90aca99fcabf00f28e5734844c9fbaf72c51a439767096eb2fe6086e3a588101f
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --files 'CHANGELOG.md,LICENSE.txt'
2
+ --protected
3
+ --readme 'README.md'
data/CHANGELOG.md CHANGED
@@ -5,9 +5,18 @@ All notable changes to this project will be documented in this file.
5
5
  Format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning v2.0.0](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [[Unreleased]](https://github.com/esotericpig/ssc.bot/compare/v0.1.1...HEAD)
8
+ ## [[Unreleased]](https://github.com/esotericpig/ssc.bot/compare/v0.2.0...HEAD)
9
9
  -
10
10
 
11
+
12
+ ## [v0.2.0] - [2021-06-22](https://github.com/esotericpig/ssc.bot/compare/v0.1.1...v0.2.0)
13
+ ### Changed
14
+ - Renamed `SSCBot::SSCFile#get_line()` to `read_uline()` due to RuboCop complaining about using `get_`.
15
+ - Formatted all code with RuboCop.
16
+ - Formatted all files.
17
+ - Updated dev Gems.
18
+
19
+
11
20
  ## [v0.1.1] - [2020-09-09](https://github.com/esotericpig/ssc.bot/compare/v0.1.0...v0.1.1)
12
21
 
13
22
  ### Added
@@ -24,6 +33,7 @@ and this project adheres to [Semantic Versioning v2.0.0](https://semver.org/spec
24
33
  ### Fixed
25
34
  - `Util.u_blank?(str)`
26
35
 
36
+
27
37
  ## [v0.1.0] - [2020-08-29](https://github.com/esotericpig/ssc.bot/tree/v0.1.0)
28
38
 
29
39
  First working version.
data/Gemfile CHANGED
@@ -1,24 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- #--
5
- # This file is part of SSC.Bot.
6
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
7
- #
8
- # SSC.Bot is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU Lesser General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # SSC.Bot is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU Lesser General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU Lesser General Public License
19
- # along with SSC.Bot. If not, see <https://www.gnu.org/licenses/>.
20
- #++
21
-
22
4
 
23
5
  source 'https://rubygems.org'
24
6
 
data/README.md CHANGED
@@ -12,48 +12,15 @@ It's currently in development and only offers limited functionality.
12
12
 
13
13
  ## Contents
14
14
 
15
- - [Setup](#-setup)
16
15
  - [Using](#-using)
17
16
  - [Hacking](#-hacking)
18
17
  - [License](#-license)
19
18
 
20
- ## [//](#contents) Setup
21
-
22
- Pick your poison...
23
-
24
- In your Gemspec (*&lt;project&gt;*.gemspec):
25
-
26
- ```Ruby
27
- # Pick one...
28
- spec.add_runtime_dependency 'ssc.bot', '~> X.X'
29
- spec.add_development_dependency 'ssc.bot', '~> X.X'
30
- ```
31
-
32
- In your Gemfile:
33
-
34
- ```Ruby
35
- # Pick one...
36
- gem 'ssc.bot', '~> X.X'
37
- gem 'ssc.bot', '~> X.X', group: :development
38
- gem 'ssc.bot', git: 'https://github.com/esotericpig/ssc.bot.git', tag: 'vX.X.X'
39
- ```
40
-
41
- With the RubyGems package manager:
42
-
43
- ```
44
- $ gem install ssc.bot
45
- ```
19
+ ## [//](#contents) Using
46
20
 
47
- Manually:
21
+ Gem name: `ssc.bot`
48
22
 
49
- ```
50
- $ git clone 'https://github.com/esotericpig/ssc.bot.git'
51
- $ cd ssc.bot
52
- $ bundle install
53
- $ bundle exec rake install:local
54
- ```
55
-
56
- ## [//](#contents) Using
23
+ See [SSC.Nob](https://github.com/esotericpig/ssc.nob) for example usage.
57
24
 
58
25
  TODO: readme.using
59
26
 
@@ -86,20 +53,28 @@ $ bundle exec rake install:local
86
53
 
87
54
  ### Releasing
88
55
 
89
- 1. Update *CHANGELOG.md* & *version.rb*
90
- - `$ raketary bump -v`
91
- 2. Check for updates
56
+ 1. Check for updates
57
+ - `$ git pull`
92
58
  - `$ bundle update`
93
59
  - `$ bundle outdated`
94
- - `$ git pull`
95
- 3. `$ bundle exec rake release`
60
+ 2. Update *CHANGELOG.md* & *version.rb*
61
+ - `$ raketary bump -v`
62
+ - `$ raketary bump --patch`
63
+ - `$ bundle update`
64
+ 3. Release to *GitHub* & *GitHub Packages*
65
+ - `$ bundle exec rake clobber build`
66
+ - `$ gh release create v0.0.0 pkg/*.gem`
67
+ - `$ git fetch --tags origin`
68
+ - `$ raketary github_pkg`
69
+ 4. Release to *RubyGems*
70
+ - `$ bundle exec rake release`
96
71
 
97
72
  ## [//](#contents) License
98
73
 
99
74
  [GNU LGPL v3+](LICENSE.txt)
100
75
 
101
76
  > SSC.Bot (<https://github.com/esotericpig/ssc.bot>)
102
- > Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
77
+ > Copyright (c) 2020-2021 Jonathan Bradley Whited
103
78
  >
104
79
  > SSC.Bot is free software: you can redistribute it and/or modify
105
80
  > it under the terms of the GNU Lesser General Public License as published by
data/Rakefile CHANGED
@@ -1,52 +1,35 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- #--
5
- # This file is part of SSC.Bot.
6
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
7
- #
8
- # SSC.Bot is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU Lesser General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # SSC.Bot is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU Lesser General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU Lesser General Public License
19
- # along with SSC.Bot. If not, see <https://www.gnu.org/licenses/>.
20
- #++
21
-
22
4
 
23
5
  require 'bundler/gem_tasks'
24
6
 
7
+ require 'yard'
8
+
25
9
  require 'rake/clean'
26
10
  require 'rake/testtask'
27
- require 'yard'
28
11
 
29
12
  require 'ssc.bot/version'
30
13
 
31
-
32
14
  CLEAN.exclude('{.git,stock}/**/*')
33
15
  CLOBBER.include('doc/')
34
16
 
35
17
  task default: [:test]
36
18
 
37
19
  desc 'Generate documentation'
38
- task :doc => [:yard] do |task|
20
+ task doc: [:yard] do |task|
39
21
  end
40
22
 
41
- Rake::TestTask.new() do |task|
23
+ Rake::TestTask.new do |task|
42
24
  task.libs = ['lib','test']
43
25
  task.pattern = File.join('test','**','*_test.rb')
44
26
  task.description += ": '#{task.pattern}'"
27
+ task.options = '--pride'
45
28
  task.verbose = false
46
29
  task.warning = true
47
30
  end
48
31
 
49
- YARD::Rake::YardocTask.new() do |task|
32
+ YARD::Rake::YardocTask.new do |task|
50
33
  #task.options.push('--template-path',File.join('yard','templates'))
51
34
  task.options.push('--title',"SSC.Bot v#{SSCBot::VERSION} Doc")
52
35
  end
data/lib/ssc.bot.rb CHANGED
@@ -1,30 +1,20 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  #--
6
5
  # This file is part of SSC.Bot.
7
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # SSC.Bot is free software: you can redistribute it and/or modify
10
- # it under the terms of the GNU Lesser General Public License as published by
11
- # the Free Software Foundation, either version 3 of the License, or
12
- # (at your option) any later version.
13
- #
14
- # SSC.Bot is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- # GNU Lesser General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU Lesser General Public License
20
- # along with SSC.Bot. If not, see <https://www.gnu.org/licenses/>.
6
+ # Copyright (c) 2020-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
21
9
  #++
22
10
 
23
11
 
24
12
  require 'ssc.bot/chat_log'
25
13
  require 'ssc.bot/chat_log_file'
14
+ require 'ssc.bot/clu'
26
15
  require 'ssc.bot/error'
27
16
  require 'ssc.bot/ssc_file'
17
+ require 'ssc.bot/user'
28
18
  require 'ssc.bot/util'
29
19
  require 'ssc.bot/version'
30
20
 
@@ -35,9 +25,8 @@ require 'ssc.bot/chat_log/messages'
35
25
 
36
26
  require 'ssc.bot/user/message_sender'
37
27
 
38
-
39
28
  ###
40
- # @author Jonathan Bradley Whited (@esotericpig)
29
+ # @author Jonathan Bradley Whited
41
30
  # @since 0.1.0
42
31
  ###
43
32
  module SSCBot
@@ -1,23 +1,11 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  #--
6
5
  # This file is part of SSC.Bot.
7
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # SSC.Bot is free software: you can redistribute it and/or modify
10
- # it under the terms of the GNU Lesser General Public License as published by
11
- # the Free Software Foundation, either version 3 of the License, or
12
- # (at your option) any later version.
13
- #
14
- # SSC.Bot is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- # GNU Lesser General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU Lesser General Public License
20
- # along with SSC.Bot. If not, see <https://www.gnu.org/licenses/>.
6
+ # Copyright (c) 2020-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
21
9
  #++
22
10
 
23
11
 
@@ -31,15 +19,15 @@ require 'ssc.bot/chat_log/message_parsable'
31
19
  require 'ssc.bot/chat_log/message_parser'
32
20
  require 'ssc.bot/chat_log/messages'
33
21
 
34
-
35
22
  module SSCBot
36
23
  ###
37
- # @author Jonathan Bradley Whited (@esotericpig)
24
+ # @author Jonathan Bradley Whited
38
25
  # @since 0.1.0
39
26
  ###
40
27
  class ChatLog
28
+ extend AttrBool::Ext
41
29
  include MessageParsable
42
-
30
+
43
31
  attr_reader? :alive
44
32
  attr_accessor :file_mode
45
33
  attr_reader :file_opt
@@ -47,10 +35,10 @@ module SSCBot
47
35
  attr_accessor :idle_secs
48
36
  attr_reader :observers
49
37
  attr_reader :thread
50
-
38
+
51
39
  def initialize(filename,file_mode: 'rt',file_opt: {},idle_secs: 0.250,**parser_kargs)
52
40
  super()
53
-
41
+
54
42
  @alive = false
55
43
  @file_mode = file_mode
56
44
  @file_opt = file_opt
@@ -58,224 +46,212 @@ module SSCBot
58
46
  @idle_secs = idle_secs
59
47
  @observers = {}
60
48
  @parser = MessageParser.new(**parser_kargs)
61
- @semaphore = Mutex.new()
49
+ @semaphore = Mutex.new
62
50
  @thread = nil
63
51
  end
64
-
52
+
65
53
  def add_observer(observer=nil,*funcs,type: :any,&block)
66
- if observer.nil?() && block.nil?()
54
+ if observer.nil? && block.nil?
67
55
  raise ArgumentError,'no observer'
68
56
  end
69
-
57
+
70
58
  check_type(type)
71
-
59
+
72
60
  type_observers = fetch_observers(type: type)
73
-
74
- if !observer.nil?()
75
- funcs << :call if funcs.empty?()
76
-
61
+
62
+ if !observer.nil?
63
+ funcs << :call if funcs.empty?
64
+
77
65
  type_observers << Observer.new(observer,*funcs)
78
66
  end
79
-
80
- if !block.nil?()
67
+
68
+ if !block.nil?
81
69
  type_observers << Observer.new(block,:call)
82
70
  end
83
71
  end
84
-
72
+
85
73
  def add_observers(*observers,type: :any,func: :call,&block)
86
- if observers.empty?() && block.nil?()
74
+ if observers.empty? && block.nil?
87
75
  raise ArgumentError,'no observer'
88
76
  end
89
-
77
+
90
78
  check_type(type)
91
-
79
+
92
80
  type_observers = fetch_observers(type: type)
93
-
94
- observers.each() do |observer|
81
+
82
+ observers.each do |observer|
95
83
  type_observers << Observer.new(observer,func)
96
84
  end
97
-
98
- if !block.nil?()
85
+
86
+ if !block.nil?
99
87
  type_observers << Observer.new(block,:call)
100
88
  end
101
89
  end
102
-
90
+
103
91
  def check_type(type,nil_ok: false)
104
- if type.nil?()
92
+ if type.nil?
105
93
  if !nil_ok
106
- raise ArgumentError,"invalid type{#{type.inspect()}}"
94
+ raise ArgumentError,"invalid type{#{type.inspect}}"
107
95
  end
108
96
  else
109
97
  if type != :any && !Message.valid_type?(type)
110
- raise ArgumentError,"invalid type{#{type.inspect()}}"
98
+ raise ArgumentError,"invalid type{#{type.inspect}}"
111
99
  end
112
100
  end
113
101
  end
114
-
115
- def clear_content()
102
+
103
+ def clear_content
116
104
  SSCFile.clear(@filename)
117
105
  end
118
-
106
+
119
107
  def count_observers(type: nil)
120
108
  check_type(type,nil_ok: true)
121
-
109
+
122
110
  count = 0
123
-
124
- if type.nil?()
125
- @observers.each_value() do |type_observers|
111
+
112
+ if type.nil?
113
+ @observers.each_value do |type_observers|
126
114
  count += type_observers.length
127
115
  end
128
116
  else
129
117
  type_observers = @observers[type]
130
-
131
- if !type_observers.nil?()
118
+
119
+ if !type_observers.nil?
132
120
  count += type_observers.length
133
121
  end
134
122
  end
135
-
123
+
136
124
  return count
137
125
  end
138
-
126
+
139
127
  def delete_observer(observer,type: nil)
140
128
  delete_observers(observer,type: type)
141
129
  end
142
-
130
+
143
131
  def delete_observers(*observers,type: nil)
144
132
  check_type(type,nil_ok: true)
145
-
146
- if observers.empty?()
147
- if type.nil?()
148
- @observers.clear()
133
+
134
+ if observers.empty?
135
+ if type.nil?
136
+ @observers.clear
149
137
  else
150
- type_observers = @observers[type]
151
-
152
- if !type_observers.nil?()
153
- type_observers.clear()
154
- end
138
+ @observers[type]&.clear
155
139
  end
156
140
  else
157
- observers = observers.to_set()
158
-
159
- if type.nil?()
160
- @observers.each_value() do |type_observers|
161
- type_observers.delete_if() do |observer|
141
+ observers = observers.to_set
142
+
143
+ if type.nil?
144
+ @observers.each_value do |type_observers|
145
+ type_observers.delete_if do |observer|
162
146
  observers.include?(observer.object)
163
147
  end
164
148
  end
165
149
  else
166
- type_observers = @observers[type]
167
-
168
- if !type_observers.nil?()
169
- type_observers.delete_if() do |observer|
170
- observers.include?(observer.object)
171
- end
150
+ @observers[type]&.delete_if do |observer|
151
+ observers.include?(observer.object)
172
152
  end
173
153
  end
174
154
  end
175
155
  end
176
-
156
+
177
157
  def fetch_observers(type: :any)
178
158
  check_type(type)
179
-
159
+
180
160
  type_observers = @observers[type]
181
-
182
- if type_observers.nil?()
161
+
162
+ if type_observers.nil?
183
163
  type_observers = []
184
164
  @observers[type] = type_observers
185
165
  end
186
-
166
+
187
167
  return type_observers
188
168
  end
189
-
169
+
190
170
  def notify_observers(message)
191
171
  any_observers = @observers[:any]
192
172
  type_observers = @observers[message.type]
193
-
194
- if !any_observers.nil?()
195
- any_observers.each() do |observer|
196
- observer.notify(self,message)
197
- end
173
+
174
+ any_observers&.each do |observer|
175
+ observer.notify(self,message)
198
176
  end
199
-
200
- if !type_observers.nil?()
201
- type_observers.each() do |observer|
202
- observer.notify(self,message)
203
- end
177
+
178
+ type_observers&.each do |observer|
179
+ observer.notify(self,message)
204
180
  end
205
181
  end
206
-
182
+
207
183
  def run(seek_to_end: true)
208
- @semaphore.synchronize() do
184
+ @semaphore.synchronize do
209
185
  return if @alive # Already running
210
186
  end
211
-
212
- stop() # Justin Case
213
-
214
- @semaphore.synchronize() do
187
+
188
+ stop # Justin Case
189
+
190
+ @semaphore.synchronize do
215
191
  @alive = true
216
-
217
- soft_touch() # Create the file if it doesn't exist
218
-
219
- @thread = Thread.new() do
192
+
193
+ soft_touch # Create the file if it doesn't exist
194
+
195
+ @thread = Thread.new do
220
196
  SSCFile.open(@filename,@file_mode,**@file_opt) do |fin|
221
- fin.seek_to_end() if seek_to_end
222
-
197
+ fin.seek_to_end if seek_to_end
198
+
223
199
  while @alive
224
- while !(line = fin.get_line()).nil?()
200
+ while !(line = fin.read_uline).nil?
225
201
  message = @parser.parse(line)
226
-
202
+
227
203
  notify_observers(message)
228
204
  end
229
-
205
+
230
206
  sleep(@idle_secs)
231
207
  end
232
208
  end
233
209
  end
234
210
  end
235
211
  end
236
-
237
- def soft_touch()
212
+
213
+ def soft_touch
238
214
  SSCFile.soft_touch(@filename)
239
215
  end
240
-
216
+
241
217
  def stop(wait_secs=5)
242
- @semaphore.synchronize() do
218
+ @semaphore.synchronize do
243
219
  @alive = false
244
-
245
- if !@thread.nil?()
246
- if @thread.alive?()
220
+
221
+ if !@thread.nil?
222
+ if @thread.alive?
247
223
  # First, try to kill it gracefully (waiting X secs).
248
224
  @thread.join(@idle_secs + wait_secs)
249
-
225
+
250
226
  # Die!
251
- @thread.kill() if @thread.alive?()
227
+ @thread.kill if @thread.alive?
252
228
  end
253
-
229
+
254
230
  @thread = nil
255
231
  end
256
232
  end
257
233
  end
258
-
234
+
259
235
  ###
260
- # @author Jonathan Bradley Whited (@esotericpig)
236
+ # @author Jonathan Bradley Whited
261
237
  # @since 0.1.0
262
238
  ###
263
239
  class Observer
264
240
  attr_reader :funcs
265
241
  attr_reader :object
266
-
242
+
267
243
  def initialize(object,*funcs)
268
244
  super()
269
-
270
- raise ArgumentError,'empty funcs' if funcs.empty?()
271
-
245
+
246
+ raise ArgumentError,'empty funcs' if funcs.empty?
247
+
272
248
  @funcs = funcs
273
249
  @object = object
274
250
  end
275
-
276
- def notify(chatlog,message)
277
- @funcs.each() do |func|
278
- @object.__send__(func,chatlog,message)
251
+
252
+ def notify(chat_log,message)
253
+ @funcs.each do |func|
254
+ @object.__send__(func,chat_log,message)
279
255
  end
280
256
  end
281
257
  end