ssc.nob 0.1.0-java → 0.1.1-java
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -2
- data/Gemfile +1 -19
- data/Gemfile.lock +49 -0
- data/README.md +56 -8
- data/Rakefile +52 -25
- data/bin/ssc.nob +3 -14
- data/lib/ssc.nob.rb +743 -156
- data/lib/ssc.nob/config.rb +94 -59
- data/lib/ssc.nob/error.rb +5 -17
- data/lib/ssc.nob/ssc_bot.rb +67 -88
- data/lib/ssc.nob/ssc_chat_log.rb +34 -46
- data/lib/ssc.nob/ssc_chat_log/message.rb +15 -27
- data/lib/ssc.nob/ssc_chat_log/message_parser.rb +39 -51
- data/lib/ssc.nob/userface.rb +33 -45
- data/lib/ssc.nob/util.rb +14 -26
- data/lib/ssc.nob/version.rb +4 -16
- data/ssc.nob.gemspec +24 -43
- metadata +45 -15
data/lib/ssc.nob/ssc_chat_log.rb
CHANGED
@@ -1,27 +1,15 @@
|
|
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.Nob.
|
7
|
-
# Copyright (c) 2020 Jonathan Bradley Whited
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# it under the terms of the GNU 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.Nob 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 General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU General Public License
|
20
|
-
# along with SSC.Nob. If not, see <https://www.gnu.org/licenses/>.
|
6
|
+
# Copyright (c) 2020-2021 Jonathan Bradley Whited
|
7
|
+
#
|
8
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
21
9
|
#++
|
22
10
|
|
23
11
|
|
24
|
-
require 'attr_bool'
|
12
|
+
require 'attr_bool/core_ext'
|
25
13
|
|
26
14
|
require 'ssc.nob/ssc_chat_log/message'
|
27
15
|
require 'ssc.nob/ssc_chat_log/message_parser'
|
@@ -29,7 +17,7 @@ require 'ssc.nob/ssc_chat_log/message_parser'
|
|
29
17
|
|
30
18
|
module SSCNob
|
31
19
|
###
|
32
|
-
# @author Jonathan Bradley Whited
|
20
|
+
# @author Jonathan Bradley Whited
|
33
21
|
# @since 0.1.0
|
34
22
|
###
|
35
23
|
class SSCChatLog
|
@@ -41,74 +29,74 @@ module SSCNob
|
|
41
29
|
attr_reader? :running
|
42
30
|
attr_accessor :sleep_time
|
43
31
|
attr_reader :thread
|
44
|
-
|
32
|
+
|
45
33
|
def initialize(config,logname: 'nob.log',sleep_time: 0.2)
|
46
34
|
@config = config
|
47
35
|
@listeners = []
|
48
|
-
@log_file = File.join(config.build_ssc_log_dir
|
36
|
+
@log_file = File.join(config.build_ssc_log_dir,logname)
|
49
37
|
@logname = logname
|
50
38
|
@messages = []
|
51
39
|
@running = false
|
52
40
|
@sleep_time = sleep_time
|
53
41
|
@thread = nil
|
54
42
|
end
|
55
|
-
|
43
|
+
|
56
44
|
def add_listener(proc=nil,&block)
|
57
45
|
@listeners.push(block) if block
|
58
46
|
@listeners.push(proc) if proc
|
59
|
-
|
47
|
+
|
60
48
|
return self
|
61
49
|
end
|
62
|
-
|
63
|
-
def run
|
50
|
+
|
51
|
+
def run
|
64
52
|
return if @running # Already running
|
65
|
-
|
66
|
-
stop
|
67
|
-
|
53
|
+
|
54
|
+
stop # Justin Case
|
55
|
+
|
68
56
|
if !File.exist?(@log_file)
|
69
57
|
# Create the file.
|
70
58
|
File.open(@log_file,'at') do |fout|
|
71
59
|
end
|
72
60
|
end
|
73
|
-
|
74
|
-
@thread = Thread.new
|
75
|
-
File.open(@log_file,'rt') do |fin|
|
61
|
+
|
62
|
+
@thread = Thread.new do
|
63
|
+
File.open(@log_file,'rt',encoding: 'Windows-1252:UTF-8') do |fin|
|
76
64
|
fin.seek(0,:END)
|
77
|
-
fin.gets
|
78
|
-
|
65
|
+
fin.gets # Ignore most recent line
|
66
|
+
|
79
67
|
parser = MessageParser.new(config: @config,fin: fin)
|
80
|
-
|
68
|
+
|
81
69
|
@running = true
|
82
|
-
|
70
|
+
|
83
71
|
while @running
|
84
|
-
while !(line = fin.gets
|
72
|
+
while !(line = fin.gets).nil?
|
85
73
|
msg = parser.parse(line)
|
86
|
-
|
74
|
+
|
87
75
|
@messages.push(msg)
|
88
|
-
|
89
|
-
@listeners.each
|
76
|
+
|
77
|
+
@listeners.each do |l|
|
90
78
|
l.call(self,msg)
|
91
79
|
end
|
92
80
|
end
|
93
|
-
|
81
|
+
|
94
82
|
sleep(@sleep_time)
|
95
83
|
end
|
96
84
|
end
|
97
85
|
end
|
98
86
|
end
|
99
|
-
|
100
|
-
def stop
|
87
|
+
|
88
|
+
def stop
|
101
89
|
@running = false
|
102
|
-
|
103
|
-
if !@thread.nil?
|
104
|
-
if @thread.alive?
|
90
|
+
|
91
|
+
if !@thread.nil?
|
92
|
+
if @thread.alive?
|
105
93
|
@thread.join(5)
|
106
|
-
@thread.kill
|
94
|
+
@thread.kill if @thread.alive?
|
107
95
|
end
|
108
|
-
|
96
|
+
|
109
97
|
@thread = nil
|
110
98
|
end
|
111
|
-
|
99
|
+
|
112
100
|
@messages = []
|
113
101
|
end
|
114
102
|
end
|
@@ -1,57 +1,45 @@
|
|
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.Nob.
|
7
|
-
# Copyright (c) 2020 Jonathan Bradley Whited
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# it under the terms of the GNU 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.Nob 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 General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU General Public License
|
20
|
-
# along with SSC.Nob. If not, see <https://www.gnu.org/licenses/>.
|
6
|
+
# Copyright (c) 2020-2021 Jonathan Bradley Whited
|
7
|
+
#
|
8
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
21
9
|
#++
|
22
10
|
|
23
11
|
|
24
12
|
module SSCNob
|
25
13
|
class SSCChatLog
|
26
14
|
###
|
27
|
-
# @author Jonathan Bradley Whited
|
15
|
+
# @author Jonathan Bradley Whited
|
28
16
|
# @since 0.1.0
|
29
17
|
###
|
30
18
|
class Message
|
31
|
-
TYPES = [
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
]
|
36
|
-
|
19
|
+
TYPES = %i[
|
20
|
+
unknown
|
21
|
+
chat freq kill private pub team
|
22
|
+
q_chat q_kill q_namelen q_log
|
23
|
+
].freeze
|
24
|
+
|
37
25
|
attr_reader :lines
|
38
26
|
attr_reader :meta
|
39
27
|
attr_reader :type
|
40
|
-
|
41
|
-
TYPES.each
|
28
|
+
|
29
|
+
TYPES.each do |type|
|
42
30
|
define_method(:"#{type}?") do
|
43
31
|
return @type == type
|
44
32
|
end
|
45
33
|
end
|
46
|
-
|
34
|
+
|
47
35
|
def initialize(lines,meta: {},type: :unknown)
|
48
36
|
super()
|
49
|
-
|
37
|
+
|
50
38
|
@lines = Array(lines)
|
51
39
|
@meta = meta
|
52
40
|
@type = type
|
53
41
|
end
|
54
|
-
|
42
|
+
|
55
43
|
def [](key)
|
56
44
|
return @meta[key]
|
57
45
|
end
|
@@ -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.Nob.
|
7
|
-
# Copyright (c) 2020 Jonathan Bradley Whited
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# it under the terms of the GNU 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.Nob 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 General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU General Public License
|
20
|
-
# along with SSC.Nob. If not, see <https://www.gnu.org/licenses/>.
|
6
|
+
# Copyright (c) 2020-2021 Jonathan Bradley Whited
|
7
|
+
#
|
8
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
21
9
|
#++
|
22
10
|
|
23
11
|
|
@@ -29,25 +17,25 @@ require 'ssc.nob/ssc_chat_log/message'
|
|
29
17
|
module SSCNob
|
30
18
|
class SSCChatLog
|
31
19
|
###
|
32
|
-
# @author Jonathan Bradley Whited
|
20
|
+
# @author Jonathan Bradley Whited
|
33
21
|
# @since 0.1.0
|
34
22
|
###
|
35
23
|
class MessageParser
|
36
24
|
attr_reader :config
|
37
25
|
attr_reader :fin
|
38
26
|
attr_accessor :namelen
|
39
|
-
|
27
|
+
|
40
28
|
def initialize(config: nil,fin: nil,namelen: nil)
|
41
29
|
@config = config
|
42
30
|
@fin = fin
|
43
31
|
@namelen = namelen
|
44
32
|
end
|
45
|
-
|
33
|
+
|
46
34
|
def parse(line)
|
47
|
-
line =
|
48
|
-
|
35
|
+
line = line.sub(/[\r\n]+\z/,'')
|
36
|
+
|
49
37
|
msg = nil
|
50
|
-
|
38
|
+
|
51
39
|
case line[0]
|
52
40
|
when 'C'
|
53
41
|
msg = parse_chat(line)
|
@@ -67,93 +55,93 @@ class SSCChatLog
|
|
67
55
|
msg = parse_q_namelen(line)
|
68
56
|
end
|
69
57
|
end
|
70
|
-
|
71
|
-
msg = Message.new(line) if msg.nil?
|
72
|
-
|
58
|
+
|
59
|
+
msg = Message.new(line) if msg.nil?
|
60
|
+
|
73
61
|
return msg
|
74
62
|
end
|
75
|
-
|
63
|
+
|
76
64
|
# 'T Name> Msg'
|
77
65
|
def parse_basic(line,type:)
|
78
|
-
i = @namelen.nil?
|
79
|
-
|
66
|
+
i = @namelen.nil? ? line.index('> ',2) : (@namelen + 2)
|
67
|
+
|
80
68
|
username = line[2...i]
|
81
|
-
username = Util.strip(username.to_s
|
69
|
+
username = Util.strip(username.to_s)
|
82
70
|
message = line[i + 1..-1]
|
83
|
-
message = Util.strip(message.to_s
|
84
|
-
|
71
|
+
message = Util.strip(message.to_s)
|
72
|
+
|
85
73
|
return Message.new(line,type: type,meta: {
|
86
74
|
username: username,
|
87
75
|
message: message,
|
88
76
|
})
|
89
77
|
end
|
90
|
-
|
78
|
+
|
91
79
|
# 'C 1:Name> Msg'
|
92
80
|
# - Not affected by namelen, always full name.
|
93
81
|
def parse_chat(line)
|
94
82
|
i = line.index(':',2)
|
95
83
|
j = line.index('> ',i)
|
96
|
-
|
84
|
+
|
97
85
|
channel = line[2...i]
|
98
|
-
channel = Util.strip(channel.to_s
|
86
|
+
channel = Util.strip(channel.to_s).to_i
|
99
87
|
username = line[i + 1...j]
|
100
|
-
username = Util.strip(username.to_s
|
88
|
+
username = Util.strip(username.to_s)
|
101
89
|
message = line[j + 1..-1]
|
102
|
-
message = Util.strip(message.to_s
|
103
|
-
|
90
|
+
message = Util.strip(message.to_s)
|
91
|
+
|
104
92
|
return Message.new(line,type: :chat,meta: {
|
105
93
|
channel: channel,
|
106
94
|
username: username,
|
107
95
|
message: message,
|
108
96
|
})
|
109
97
|
end
|
110
|
-
|
98
|
+
|
111
99
|
def parse_freq(line)
|
112
100
|
return parse_basic(line,type: :freq)
|
113
101
|
end
|
114
|
-
|
102
|
+
|
115
103
|
# ' Name(100) killed by: Name'
|
116
104
|
def parse_kill(line)
|
117
105
|
i = line.index(/\(\d+\)/,2)
|
118
106
|
j = line.index(')',i)
|
119
107
|
k = line.index(':',j)
|
120
|
-
|
108
|
+
|
121
109
|
killed = line[2...i]
|
122
|
-
killed = Util.strip(killed.to_s
|
110
|
+
killed = Util.strip(killed.to_s)
|
123
111
|
bounty = line[i + 1...j]
|
124
|
-
bounty = Util.strip(bounty.to_s
|
112
|
+
bounty = Util.strip(bounty.to_s).to_i
|
125
113
|
killer = line[k + 1..-1]
|
126
|
-
killer = Util.strip(killer.to_s
|
127
|
-
|
114
|
+
killer = Util.strip(killer.to_s)
|
115
|
+
|
128
116
|
return Message.new(line,type: :kill,meta: {
|
129
117
|
killed: killed,
|
130
118
|
bounty: bounty,
|
131
119
|
killer: killer,
|
132
120
|
})
|
133
121
|
end
|
134
|
-
|
122
|
+
|
135
123
|
def parse_private(line)
|
136
124
|
return parse_basic(line,type: :private)
|
137
125
|
end
|
138
|
-
|
126
|
+
|
139
127
|
def parse_pub(line)
|
140
128
|
return parse_basic(line,type: :pub)
|
141
129
|
end
|
142
|
-
|
130
|
+
|
143
131
|
# ' Message Name Length: 24'
|
144
132
|
def parse_q_namelen(line)
|
145
133
|
i = line.index(':')
|
146
|
-
|
134
|
+
|
147
135
|
namelen = line[i + 1..-1]
|
148
|
-
namelen = Util.strip(namelen.to_s
|
149
|
-
|
136
|
+
namelen = Util.strip(namelen.to_s).to_i
|
137
|
+
|
150
138
|
@namelen = namelen
|
151
|
-
|
139
|
+
|
152
140
|
return Message.new(line,type: :q_namelen,meta: {
|
153
141
|
namelen: namelen,
|
154
142
|
})
|
155
143
|
end
|
156
|
-
|
144
|
+
|
157
145
|
def parse_team(line)
|
158
146
|
return parse_basic(line,type: :team)
|
159
147
|
end
|
data/lib/ssc.nob/userface.rb
CHANGED
@@ -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.Nob.
|
7
|
-
# Copyright (c) 2020 Jonathan Bradley Whited
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# it under the terms of the GNU 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.Nob 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 General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU General Public License
|
20
|
-
# along with SSC.Nob. If not, see <https://www.gnu.org/licenses/>.
|
6
|
+
# Copyright (c) 2020-2021 Jonathan Bradley Whited
|
7
|
+
#
|
8
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
21
9
|
#++
|
22
10
|
|
23
11
|
|
@@ -30,94 +18,94 @@ require 'tty-spinner'
|
|
30
18
|
|
31
19
|
module SSCNob
|
32
20
|
###
|
33
|
-
# @author Jonathan Bradley Whited
|
21
|
+
# @author Jonathan Bradley Whited
|
34
22
|
# @since 0.1.0
|
35
23
|
###
|
36
24
|
class Userface
|
37
25
|
extend Forwardable
|
38
26
|
include Singleton
|
39
|
-
|
27
|
+
|
40
28
|
attr_reader :line
|
41
29
|
attr_reader :rain
|
42
|
-
|
30
|
+
|
43
31
|
def_delegators :@line,:agree,:ask,:choose,:indent,:say
|
44
32
|
def_delegator :@rain,:wrap,:color
|
45
|
-
|
46
|
-
def initialize
|
33
|
+
|
34
|
+
def initialize
|
47
35
|
super()
|
48
|
-
|
49
|
-
@line = HighLine.new
|
50
|
-
@rain = Rainbow.new
|
51
|
-
|
36
|
+
|
37
|
+
@line = HighLine.new
|
38
|
+
@rain = Rainbow.new
|
39
|
+
|
52
40
|
@line.use_color = true
|
53
41
|
@rain.enabled = true
|
54
42
|
end
|
55
|
-
|
43
|
+
|
56
44
|
def cmd(cmd)
|
57
45
|
return color(cmd).yellow.bold
|
58
46
|
end
|
59
|
-
|
60
|
-
def coffee
|
47
|
+
|
48
|
+
def coffee
|
61
49
|
return color('C\_/').saddlebrown.bold
|
62
50
|
end
|
63
|
-
|
51
|
+
|
64
52
|
def error(msg)
|
65
53
|
return "#{color('Error:').red.bold} #{msg}"
|
66
54
|
end
|
67
|
-
|
55
|
+
|
68
56
|
def gt(msg=nil)
|
69
57
|
return "#{color('>').yellow.bold} #{msg}"
|
70
58
|
end
|
71
|
-
|
59
|
+
|
72
60
|
def love(msg)
|
73
61
|
return color(msg).red.bold
|
74
62
|
end
|
75
|
-
|
63
|
+
|
76
64
|
def spin(msg,&block)
|
77
65
|
spinner = TTY::Spinner.new("[:spinner] #{msg}...",
|
78
66
|
interval: 4,frames: ['o_O','O_o']
|
79
67
|
)
|
80
|
-
|
81
|
-
if block_given?
|
68
|
+
|
69
|
+
if block_given?
|
82
70
|
spinner.run(&block)
|
83
71
|
else
|
84
|
-
spinner.auto_spin
|
72
|
+
spinner.auto_spin
|
85
73
|
end
|
86
|
-
|
74
|
+
|
87
75
|
return spinner
|
88
76
|
end
|
89
|
-
|
90
|
-
def ssc
|
77
|
+
|
78
|
+
def ssc
|
91
79
|
return color('Subspace Continuum').purple.bold
|
92
80
|
end
|
93
|
-
|
81
|
+
|
94
82
|
def title(title)
|
95
83
|
return color(title).blue.bold
|
96
84
|
end
|
97
|
-
|
85
|
+
|
98
86
|
def type(msg)
|
99
|
-
msg.each_char
|
87
|
+
msg.each_char do |c|
|
100
88
|
print c
|
101
89
|
sleep(0.05)
|
102
90
|
end
|
103
91
|
end
|
104
|
-
|
92
|
+
|
105
93
|
def types(msg)
|
106
94
|
type(msg)
|
107
95
|
puts
|
108
96
|
end
|
109
|
-
|
97
|
+
|
110
98
|
def user(user)
|
111
99
|
return color(user).limegreen.bold
|
112
100
|
end
|
113
101
|
end
|
114
|
-
|
102
|
+
|
115
103
|
###
|
116
|
-
# @author Jonathan Bradley Whited
|
104
|
+
# @author Jonathan Bradley Whited
|
117
105
|
# @since 0.1.0
|
118
106
|
###
|
119
107
|
module Uface
|
120
|
-
def uface
|
108
|
+
def uface
|
121
109
|
return Userface.instance
|
122
110
|
end
|
123
111
|
end
|