ssc.bot 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -2
- data/lib/ssc.bot/chat_log/message.rb +35 -15
- data/lib/ssc.bot/chat_log/message_parser.rb +34 -54
- data/lib/ssc.bot/util.rb +1 -1
- data/lib/ssc.bot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1468b04f2b3b2b2e388b2ab044ad52e8bf55d53343d4ff75d2dd56c9387b843
|
4
|
+
data.tar.gz: f8ccc21500f7b394f3be858c24d59c18c453a333da03be6265e59a6224897ba0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fb0d8ed2cd691b5a40de2a103bcb3c050da49a4993e76bcd5a2b22e3fd8edf431e9de1be271bc71abadc28218721fc0fb8f1e30127743c08bc782e25b49b790
|
7
|
+
data.tar.gz: e0d5ad76f4ee548a4b6e5e191534badb10ef39e44644179a910e05b71b325963bed96b9892c82b25606ee78ff45dd32cac35ea247288225bd6f0bd6b7be40bc3
|
data/CHANGELOG.md
CHANGED
@@ -3,12 +3,31 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
5
|
Format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
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.
|
8
|
+
## [[Unreleased]](https://github.com/esotericpig/ssc.bot/compare/v0.1.1...HEAD)
|
9
9
|
-
|
10
10
|
|
11
|
+
## [v0.1.1] - [2020-09-09](https://github.com/esotericpig/ssc.bot/compare/v0.1.0...v0.1.1)
|
12
|
+
|
13
|
+
### Added
|
14
|
+
- `ChatLog::Message`
|
15
|
+
- `type_<type>?()` for all `TYPES`
|
16
|
+
- `msg.type_chat?(); msg.type_pub?(); msg.type_q_log?()`
|
17
|
+
- `self.add_type(type)`
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
- `ChatLog::MessageParser`
|
21
|
+
- Refactored & formatted code
|
22
|
+
- Added warn message to `parse_q_namelen` if namelen > max
|
23
|
+
|
24
|
+
### Fixed
|
25
|
+
- `Util.u_blank?(str)`
|
26
|
+
|
11
27
|
## [v0.1.0] - [2020-08-29](https://github.com/esotericpig/ssc.bot/tree/v0.1.0)
|
28
|
+
|
29
|
+
First working version.
|
30
|
+
|
12
31
|
### Added
|
13
32
|
- /
|
14
33
|
- .gitignore
|
@@ -33,24 +33,44 @@ class ChatLog
|
|
33
33
|
# @since 0.1.0
|
34
34
|
###
|
35
35
|
class Message
|
36
|
+
# Adds +type+ to the list of valid {TYPES}
|
37
|
+
# and creates a boolean method for it ending with a +?+.
|
38
|
+
#
|
39
|
+
# @param type [Symbol,String] the new type to add
|
40
|
+
def self.add_type(type)
|
41
|
+
type = type.to_sym()
|
42
|
+
|
43
|
+
return if TYPES.include?(type)
|
44
|
+
|
45
|
+
TYPES.add(type)
|
46
|
+
|
47
|
+
name = type.to_s().sub('?','q_')
|
48
|
+
|
49
|
+
define_method(:"type_#{name}?") do
|
50
|
+
return @type == type
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
36
54
|
# Valid types of messages.
|
37
55
|
#
|
38
56
|
# You can add your own custom type(s) that you parse manually:
|
39
|
-
# SSCBot::ChatLog::Message
|
40
|
-
TYPES = Set
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
?
|
47
|
-
|
48
|
-
?
|
49
|
-
|
50
|
-
?
|
51
|
-
|
52
|
-
|
53
|
-
|
57
|
+
# SSCBot::ChatLog::Message.add_type(:custom)
|
58
|
+
TYPES = Set.new()
|
59
|
+
|
60
|
+
# In order of F1 Help box.
|
61
|
+
%i{
|
62
|
+
pub team private remote freq chat
|
63
|
+
?lines ?namelen ?ignore ?nopubchat ?obscene ?away ?log ?logbuffer
|
64
|
+
?kill kill ?enter enter ?leave leave ?message ?messages ?chat
|
65
|
+
?status ?scorereset ?team ?spec ?target ?time ?flags ?score ?crown
|
66
|
+
?best ?buy
|
67
|
+
?owner ?password ?usage ?userid ?find ?ping ?packetloss ?lag ?music
|
68
|
+
?sound ?alarm ?sheep ?getnews
|
69
|
+
?squadowner ?squad ?squadlist ?loadmacro ?savemacro
|
70
|
+
unknown
|
71
|
+
}.each() do |type|
|
72
|
+
add_type(type)
|
73
|
+
end
|
54
74
|
|
55
75
|
# @param type [Symbol] the type to check if valid
|
56
76
|
# @return [Boolean] +true+ if +type+ is one of {TYPES}, else +false+
|
@@ -75,42 +75,32 @@ class ChatLog
|
|
75
75
|
@regex_cache[type_name] = cached_regex
|
76
76
|
end
|
77
77
|
|
78
|
-
|
79
|
-
|
78
|
+
use_namelen &&= !@namelen.nil?()
|
79
|
+
key = use_namelen ? @namelen : :no_namelen
|
80
|
+
regex = cached_regex[key]
|
81
|
+
|
82
|
+
if regex.nil?()
|
83
|
+
name_prefix = Util.quote_str_or_regex(name_prefix)
|
84
|
+
name_suffix = Util.quote_str_or_regex(name_suffix)
|
85
|
+
type_prefix = Util.quote_str_or_regex(type_prefix)
|
80
86
|
|
81
|
-
if
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
# Be careful to not use spaces ' ', but to use '\\ ' (or '\s') instead
|
87
|
-
# because of the '/x' option.
|
88
|
-
regex = /
|
89
|
-
\A#{type_prefix}
|
90
|
-
#{name_prefix}(?<name>.{#{@namelen}})#{name_suffix}
|
91
|
-
(?<message>.*)\z
|
92
|
-
/x
|
93
|
-
|
94
|
-
cached_regex[@namelen] = regex
|
87
|
+
if use_namelen
|
88
|
+
name = /.{#{@namelen}}/
|
89
|
+
else
|
90
|
+
name = /.*?\S/
|
95
91
|
end
|
96
|
-
else
|
97
|
-
regex = cached_regex[:no_namelen]
|
98
92
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
#
|
105
|
-
#
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
/x
|
111
|
-
|
112
|
-
cached_regex[:no_namelen] = regex
|
113
|
-
end
|
93
|
+
name = Util.quote_str_or_regex(name)
|
94
|
+
|
95
|
+
# Be careful to not use spaces ' ', but to use '\\ ' (or '\s') instead
|
96
|
+
# because of the '/x' option.
|
97
|
+
regex = /
|
98
|
+
\A#{type_prefix}
|
99
|
+
#{name_prefix}(?<name>#{name})#{name_suffix}
|
100
|
+
(?<message>.*)\z
|
101
|
+
/x
|
102
|
+
|
103
|
+
cached_regex[key] = regex
|
114
104
|
end
|
115
105
|
|
116
106
|
return regex.match(line)
|
@@ -263,7 +253,7 @@ class ChatLog
|
|
263
253
|
cmd = Util.u_strip(player.message).downcase()
|
264
254
|
|
265
255
|
if cmd.start_with?('?find')
|
266
|
-
store_command(:pub,%s{?find})
|
256
|
+
store_command(:pub,%s{?find}) # See: match_q_find?()
|
267
257
|
end
|
268
258
|
|
269
259
|
return PubMessage.new(line,name: player.name,message: player.message)
|
@@ -353,6 +343,8 @@ class ChatLog
|
|
353
343
|
else
|
354
344
|
return nil
|
355
345
|
end
|
346
|
+
elsif namelen > MAX_NAMELEN
|
347
|
+
warn("namelen{#{namelen}} > max{#{MAX_NAMELEN}} for ?namelen message{#{line}}",uplevel: 0)
|
356
348
|
end
|
357
349
|
|
358
350
|
if @autoset_namelen
|
@@ -367,7 +359,7 @@ class ChatLog
|
|
367
359
|
# 'P :Self.Name:Message'
|
368
360
|
# 'P (Name)>Message'
|
369
361
|
def parse_remote(line,match:)
|
370
|
-
player = parse_player(line,type_name:
|
362
|
+
player = parse_player(line,type_name: %s{remote.private},match: match)
|
371
363
|
|
372
364
|
return nil if player.nil?()
|
373
365
|
|
@@ -468,31 +460,20 @@ class ChatLog
|
|
468
460
|
|
469
461
|
if line.start_with?(' Not online, last seen ')
|
470
462
|
match = line.match(/(?<more>more) than (?<days>\d+) days ago\z/)
|
471
|
-
|
472
|
-
if match.nil?()
|
473
|
-
match = line.match(/(?<days>\d+) days? ago\z/)
|
474
|
-
end
|
475
|
-
|
476
|
-
if match.nil?()
|
477
|
-
match = line.match(/(?<hours>\d+) hours? ago\z/)
|
478
|
-
end
|
463
|
+
match = line.match(/(?<days>\d+) days? ago\z/) if match.nil?()
|
464
|
+
match = line.match(/(?<hours>\d+) hours? ago\z/) if match.nil?()
|
479
465
|
|
480
466
|
return match
|
481
467
|
else
|
482
468
|
match = line.match(/\A (?<player>.+) is in (?<zone>.+)\z/)
|
483
|
-
|
484
|
-
if match.nil?()
|
485
|
-
match = line.match(/\A (?<player>.+) - (?<arena>.+)\z/)
|
486
|
-
end
|
469
|
+
match = line.match(/\A (?<player>.+) - (?<arena>.+)\z/) if match.nil?()
|
487
470
|
|
488
471
|
if match
|
489
472
|
caps = match.named_captures
|
490
473
|
|
491
474
|
player = caps['player']
|
492
475
|
|
493
|
-
if player.length > MAX_NAMELEN
|
494
|
-
return false
|
495
|
-
end
|
476
|
+
return false if player.length > MAX_NAMELEN
|
496
477
|
|
497
478
|
if caps.key?('arena')
|
498
479
|
area = caps['arena']
|
@@ -502,6 +483,8 @@ class ChatLog
|
|
502
483
|
return false
|
503
484
|
end
|
504
485
|
|
486
|
+
# If do /\A (?<player>[^[[:space:]]].+[^[[:space:]])/, then it won't
|
487
|
+
# capture names/zones/arenas that are only 1 char long, so do this.
|
505
488
|
[player[0],player[-1],area[0],area[-1]].each() do |c|
|
506
489
|
if c =~ /[[:space:]]/
|
507
490
|
return false
|
@@ -522,10 +505,7 @@ class ChatLog
|
|
522
505
|
return false if line.length < 17
|
523
506
|
|
524
507
|
match = /\A Log file open: (?<filename>.+)\z/.match(line)
|
525
|
-
|
526
|
-
if match.nil?()
|
527
|
-
match = /\A Log file closed\z/.match(line)
|
528
|
-
end
|
508
|
+
match = /\A Log file closed\z/.match(line) if match.nil?()
|
529
509
|
|
530
510
|
return match
|
531
511
|
end
|
data/lib/ssc.bot/util.rb
CHANGED
@@ -66,7 +66,7 @@ module SSCBot
|
|
66
66
|
|
67
67
|
# Universally, is +str+ empty after stripping or +nil+?
|
68
68
|
def self.u_blank?(str)
|
69
|
-
return str.nil?() ||
|
69
|
+
return str.nil?() || u_strip(str).empty?()
|
70
70
|
end
|
71
71
|
|
72
72
|
# Universally, left strip +str+'s leading (head) space.
|
data/lib/ssc.bot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ssc.bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Bradley Whited (@esotericpig)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: attr_bool
|