ssc.bot 0.1.1 → 0.2.0
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/.yardopts +3 -0
- data/CHANGELOG.md +11 -1
- data/Gemfile +0 -18
- data/README.md +17 -42
- data/Rakefile +6 -23
- data/lib/ssc.bot.rb +6 -17
- data/lib/ssc.bot/chat_log.rb +102 -126
- data/lib/ssc.bot/chat_log/message.rb +32 -42
- data/lib/ssc.bot/chat_log/message_parsable.rb +14 -38
- data/lib/ssc.bot/chat_log/message_parser.rb +153 -164
- data/lib/ssc.bot/chat_log/messages.rb +43 -55
- data/lib/ssc.bot/chat_log_file.rb +12 -25
- data/lib/ssc.bot/clu.rb +55 -0
- data/lib/ssc.bot/error.rb +11 -33
- data/lib/ssc.bot/jruby.rb +31 -0
- data/lib/ssc.bot/ssc_file.rb +44 -55
- data/lib/ssc.bot/user.rb +21 -0
- data/lib/ssc.bot/user/jrobot_message_sender.rb +51 -62
- data/lib/ssc.bot/user/message_sender.rb +104 -162
- data/lib/ssc.bot/util.rb +37 -31
- data/lib/ssc.bot/version.rb +4 -16
- data/ssc.bot.gemspec +21 -44
- data/test/test_helper.rb +3 -19
- data/test/util_test.rb +93 -0
- metadata +21 -16
@@ -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
|
8
|
-
#
|
9
|
-
#
|
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
|
|
@@ -25,41 +13,40 @@ require 'attr_bool'
|
|
25
13
|
|
26
14
|
require 'ssc.bot/chat_log/message'
|
27
15
|
|
28
|
-
|
29
16
|
module SSCBot
|
30
17
|
class ChatLog
|
31
18
|
###
|
32
|
-
# @author Jonathan Bradley Whited
|
19
|
+
# @author Jonathan Bradley Whited
|
33
20
|
# @since 0.1.0
|
34
21
|
###
|
35
22
|
class PlayerMessage < Message
|
36
23
|
attr_reader :message
|
37
24
|
attr_reader :name
|
38
|
-
|
25
|
+
|
39
26
|
def initialize(line,type:,name:,message:)
|
40
27
|
super(line,type: type)
|
41
|
-
|
28
|
+
|
42
29
|
@message = message
|
43
30
|
@name = name
|
44
31
|
end
|
45
32
|
end
|
46
|
-
|
33
|
+
|
47
34
|
###
|
48
|
-
# @author Jonathan Bradley Whited
|
35
|
+
# @author Jonathan Bradley Whited
|
49
36
|
# @since 0.1.0
|
50
37
|
###
|
51
38
|
class ChatMessage < PlayerMessage
|
52
39
|
attr_reader :channel
|
53
|
-
|
40
|
+
|
54
41
|
def initialize(line,channel:,name:,message:)
|
55
42
|
super(line,type: :chat,name: name,message: message)
|
56
|
-
|
43
|
+
|
57
44
|
@channel = channel
|
58
45
|
end
|
59
46
|
end
|
60
|
-
|
47
|
+
|
61
48
|
###
|
62
|
-
# @author Jonathan Bradley Whited
|
49
|
+
# @author Jonathan Bradley Whited
|
63
50
|
# @since 0.1.0
|
64
51
|
###
|
65
52
|
class FreqMessage < PlayerMessage
|
@@ -67,27 +54,27 @@ class ChatLog
|
|
67
54
|
super(line,type: :freq,name: name,message: message)
|
68
55
|
end
|
69
56
|
end
|
70
|
-
|
57
|
+
|
71
58
|
###
|
72
|
-
# @author Jonathan Bradley Whited
|
59
|
+
# @author Jonathan Bradley Whited
|
73
60
|
# @since 0.1.0
|
74
61
|
###
|
75
62
|
class KillMessage < Message
|
76
63
|
attr_reader :bounty
|
77
64
|
attr_reader :killed
|
78
65
|
attr_reader :killer
|
79
|
-
|
66
|
+
|
80
67
|
def initialize(line,killed:,bounty:,killer:)
|
81
68
|
super(line,type: :kill)
|
82
|
-
|
69
|
+
|
83
70
|
@bounty = bounty
|
84
71
|
@killed = killed
|
85
72
|
@killer = killer
|
86
73
|
end
|
87
74
|
end
|
88
|
-
|
75
|
+
|
89
76
|
###
|
90
|
-
# @author Jonathan Bradley Whited
|
77
|
+
# @author Jonathan Bradley Whited
|
91
78
|
# @since 0.1.0
|
92
79
|
###
|
93
80
|
class PrivateMessage < PlayerMessage
|
@@ -95,9 +82,9 @@ class ChatLog
|
|
95
82
|
super(line,type: type,name: name,message: message)
|
96
83
|
end
|
97
84
|
end
|
98
|
-
|
85
|
+
|
99
86
|
###
|
100
|
-
# @author Jonathan Bradley Whited
|
87
|
+
# @author Jonathan Bradley Whited
|
101
88
|
# @since 0.1.0
|
102
89
|
###
|
103
90
|
class PubMessage < PlayerMessage
|
@@ -105,9 +92,9 @@ class ChatLog
|
|
105
92
|
super(line,type: :pub,name: name,message: message)
|
106
93
|
end
|
107
94
|
end
|
108
|
-
|
95
|
+
|
109
96
|
###
|
110
|
-
# @author Jonathan Bradley Whited
|
97
|
+
# @author Jonathan Bradley Whited
|
111
98
|
# @since 0.1.0
|
112
99
|
###
|
113
100
|
class QFindMessage < Message
|
@@ -119,10 +106,11 @@ class ChatLog
|
|
119
106
|
attr_reader :player
|
120
107
|
attr_reader? :private
|
121
108
|
attr_reader :zone
|
122
|
-
|
123
|
-
def initialize(line,find_type:,arena: nil,days: nil,hours: nil,more: false,player: nil,private: false,
|
124
|
-
|
125
|
-
|
109
|
+
|
110
|
+
def initialize(line,find_type:,arena: nil,days: nil,hours: nil,more: false,player: nil,private: false,
|
111
|
+
zone: nil)
|
112
|
+
super(line,type: %s(?find))
|
113
|
+
|
126
114
|
@arena = arena
|
127
115
|
@days = days
|
128
116
|
@find_type = find_type
|
@@ -133,55 +121,55 @@ class ChatLog
|
|
133
121
|
@zone = zone
|
134
122
|
end
|
135
123
|
end
|
136
|
-
|
124
|
+
|
137
125
|
###
|
138
|
-
# @author Jonathan Bradley Whited
|
126
|
+
# @author Jonathan Bradley Whited
|
139
127
|
# @since 0.1.0
|
140
128
|
###
|
141
129
|
class QLogMessage < Message
|
142
130
|
attr_reader :filename
|
143
131
|
attr_reader :log_type # [:open,:close]
|
144
|
-
|
132
|
+
|
145
133
|
def initialize(line,log_type:,filename: nil)
|
146
|
-
super(line,type: %s
|
147
|
-
|
134
|
+
super(line,type: %s(?log))
|
135
|
+
|
148
136
|
@filename = filename
|
149
137
|
@log_type = log_type
|
150
138
|
end
|
151
139
|
end
|
152
|
-
|
140
|
+
|
153
141
|
###
|
154
|
-
# @author Jonathan Bradley Whited
|
142
|
+
# @author Jonathan Bradley Whited
|
155
143
|
# @since 0.1.0
|
156
144
|
###
|
157
145
|
class QNamelenMessage < Message
|
158
146
|
attr_reader :namelen
|
159
|
-
|
147
|
+
|
160
148
|
def initialize(line,namelen:)
|
161
|
-
super(line,type: %s
|
162
|
-
|
149
|
+
super(line,type: %s(?namelen))
|
150
|
+
|
163
151
|
@namelen = namelen
|
164
152
|
end
|
165
153
|
end
|
166
|
-
|
154
|
+
|
167
155
|
###
|
168
|
-
# @author Jonathan Bradley Whited
|
156
|
+
# @author Jonathan Bradley Whited
|
169
157
|
# @since 0.1.0
|
170
158
|
###
|
171
159
|
class RemoteMessage < PrivateMessage
|
172
160
|
attr_reader? :own
|
173
161
|
attr_reader? :squad
|
174
|
-
|
162
|
+
|
175
163
|
def initialize(line,own:,squad:,name:,message:)
|
176
164
|
super(line,type: :remote,name: name,message: message)
|
177
|
-
|
165
|
+
|
178
166
|
@own = own
|
179
167
|
@squad = squad
|
180
168
|
end
|
181
169
|
end
|
182
|
-
|
170
|
+
|
183
171
|
###
|
184
|
-
# @author Jonathan Bradley Whited
|
172
|
+
# @author Jonathan Bradley Whited
|
185
173
|
# @since 0.1.0
|
186
174
|
###
|
187
175
|
class TeamMessage < PlayerMessage
|
@@ -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
|
8
|
-
#
|
9
|
-
#
|
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
|
|
@@ -28,25 +16,24 @@ require 'ssc.bot/chat_log/message_parsable'
|
|
28
16
|
require 'ssc.bot/chat_log/message_parser'
|
29
17
|
require 'ssc.bot/chat_log/messages'
|
30
18
|
|
31
|
-
|
32
19
|
module SSCBot
|
33
20
|
###
|
34
|
-
# @author Jonathan Bradley Whited
|
21
|
+
# @author Jonathan Bradley Whited
|
35
22
|
# @since 0.1.0
|
36
23
|
###
|
37
24
|
class ChatLogFile < SSCFile
|
38
25
|
include ChatLog::MessageParsable
|
39
|
-
|
40
|
-
def initialize(filename,mode=DEFAULT_MODE,parser: ChatLog::MessageParser.new
|
26
|
+
|
27
|
+
def initialize(filename,mode=DEFAULT_MODE,parser: ChatLog::MessageParser.new,**file_kargs)
|
41
28
|
super(filename,mode,**file_kargs)
|
42
|
-
|
29
|
+
|
43
30
|
@parser = parser
|
44
31
|
end
|
45
|
-
|
46
|
-
def parse_line
|
47
|
-
line =
|
48
|
-
|
49
|
-
return line.nil?
|
32
|
+
|
33
|
+
def parse_line
|
34
|
+
line = read_uline
|
35
|
+
|
36
|
+
return line.nil? ? nil : parse(line)
|
50
37
|
end
|
51
38
|
end
|
52
39
|
end
|
data/lib/ssc.bot/clu.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#--
|
5
|
+
# This file is part of SSC.Bot.
|
6
|
+
# Copyright (c) 2020-2021 Jonathan Bradley Whited
|
7
|
+
#
|
8
|
+
# SPDX-License-Identifier: LGPL-3.0-or-later
|
9
|
+
#++
|
10
|
+
|
11
|
+
|
12
|
+
require 'forwardable'
|
13
|
+
|
14
|
+
require 'ssc.bot/chat_log'
|
15
|
+
require 'ssc.bot/user'
|
16
|
+
|
17
|
+
module SSCBot
|
18
|
+
###
|
19
|
+
# Chat Log + User
|
20
|
+
#
|
21
|
+
# @author Jonathan Bradley Whited
|
22
|
+
# @since 0.1.2
|
23
|
+
###
|
24
|
+
class Clu
|
25
|
+
include Forwardable
|
26
|
+
|
27
|
+
attr_reader :bots
|
28
|
+
attr_reader :chat_log
|
29
|
+
attr_reader :msg_sender
|
30
|
+
|
31
|
+
def initialize(chat_log,msg_sender)
|
32
|
+
super()
|
33
|
+
|
34
|
+
@bots = {}
|
35
|
+
@chat_log = chat_log
|
36
|
+
@msg_sender = msg_sender
|
37
|
+
|
38
|
+
def_delegators(:@bots,:[])
|
39
|
+
def_delegator(:@bots,:key?,:bot?)
|
40
|
+
def_delegators(:@chat_log,*(@chat_log.public_methods - public_methods))
|
41
|
+
def_delegators(:@msg_sender,*(@msg_sender.public_methods - public_methods))
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_bot(bot_class)
|
45
|
+
bot = @bots[bot_class]
|
46
|
+
|
47
|
+
if bot.nil?
|
48
|
+
bot = bot_class.new(self)
|
49
|
+
@bots[bot_class] = bot
|
50
|
+
end
|
51
|
+
|
52
|
+
return bot
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/ssc.bot/error.rb
CHANGED
@@ -1,59 +1,37 @@
|
|
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
|
8
|
-
#
|
9
|
-
#
|
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
|
module SSCBot
|
25
13
|
###
|
26
|
-
# @author Jonathan Bradley Whited
|
14
|
+
# @author Jonathan Bradley Whited
|
27
15
|
# @since 0.1.0
|
28
16
|
###
|
29
17
|
class Error < ::StandardError; end
|
30
|
-
|
18
|
+
|
31
19
|
###
|
32
|
-
# @author Jonathan Bradley Whited
|
20
|
+
# @author Jonathan Bradley Whited
|
33
21
|
# @since 0.1.0
|
34
22
|
###
|
35
23
|
class AbstractMethodError < Error
|
36
24
|
def initialize(msg=nil)
|
37
|
-
if msg.
|
38
|
-
|
39
|
-
|
40
|
-
if !method_name.nil?()
|
41
|
-
index = method_name.rindex('`')
|
42
|
-
|
43
|
-
if !index.nil?() && (index += 1) < method_name.length
|
44
|
-
method_name = method_name[index..-2]
|
45
|
-
|
46
|
-
msg = "abstract method{#{method_name}(...)} not implemented"
|
47
|
-
end
|
48
|
-
end
|
25
|
+
if msg.is_a?(Symbol)
|
26
|
+
msg = "abstract method not implemented: #{msg}(...)"
|
49
27
|
end
|
50
|
-
|
28
|
+
|
51
29
|
super(msg)
|
52
30
|
end
|
53
31
|
end
|
54
|
-
|
32
|
+
|
55
33
|
###
|
56
|
-
# @author Jonathan Bradley Whited
|
34
|
+
# @author Jonathan Bradley Whited
|
57
35
|
# @since 0.1.0
|
58
36
|
###
|
59
37
|
class ParseError < Error
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#--
|
5
|
+
# This file is part of SSC.Bot.
|
6
|
+
# Copyright (c) 2020-2021 Jonathan Bradley Whited
|
7
|
+
#
|
8
|
+
# SPDX-License-Identifier: LGPL-3.0-or-later
|
9
|
+
#++
|
10
|
+
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'java'
|
14
|
+
rescue LoadError => e
|
15
|
+
raise e.exception('Must use JRuby for Java-related files')
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'ssc.bot/user/jrobot_message_sender'
|
19
|
+
|
20
|
+
module SSCBot
|
21
|
+
###
|
22
|
+
# Require this file to include all JRuby (Java-related) files.
|
23
|
+
# Must be using JRuby.
|
24
|
+
# require 'ssc.bot/jruby'
|
25
|
+
#
|
26
|
+
# @author Jonathan Bradley Whited
|
27
|
+
# @since 0.1.2
|
28
|
+
###
|
29
|
+
module JRuby
|
30
|
+
end
|
31
|
+
end
|
data/lib/ssc.bot/ssc_file.rb
CHANGED
@@ -1,131 +1,120 @@
|
|
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
|
8
|
-
#
|
9
|
-
#
|
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/util'
|
25
13
|
|
26
|
-
|
27
14
|
module SSCBot
|
28
15
|
###
|
29
|
-
# @author Jonathan Bradley Whited
|
16
|
+
# @author Jonathan Bradley Whited
|
30
17
|
# @since 0.1.0
|
31
18
|
###
|
32
19
|
class SSCFile < ::File
|
33
20
|
DEFAULT_BUFFER_LEN = 520
|
34
21
|
DEFAULT_ENCODING = 'Windows-1252:UTF-8'
|
35
22
|
DEFAULT_MODE = 'rt'
|
36
|
-
DEFAULT_SEPARATOR = /\r?\n|\r
|
37
|
-
|
23
|
+
DEFAULT_SEPARATOR = /\r?\n|\r/.freeze # Instead, could use +/\R/+ for Ruby v2.0+.
|
24
|
+
|
38
25
|
# Clear (truncate) the contents of +filename+.
|
39
|
-
#
|
26
|
+
#
|
40
27
|
# @param filename [String] the file to clear
|
41
28
|
# @param strip [Boolean] +true+ to strip +filename+ to help prevent fat-fingering, else +false+ to not
|
42
29
|
def self.clear_content(filename,strip: true,textmode: true,**opt)
|
43
30
|
filename = Util.u_strip(filename) if strip
|
44
|
-
|
45
|
-
return if filename.empty?
|
46
|
-
return
|
47
|
-
|
31
|
+
|
32
|
+
return if filename.empty?
|
33
|
+
return unless File.file?(filename) # Also checks if exists.
|
34
|
+
|
48
35
|
# Clear the file.
|
49
36
|
# - Do NOT call truncate() as it's not available on all platforms.
|
50
|
-
open(filename,'w',textmode: textmode,**opt) do |file|
|
37
|
+
self.open(filename,'w',textmode: textmode,**opt) do |file|
|
51
38
|
end
|
52
39
|
end
|
53
|
-
|
40
|
+
|
54
41
|
# If +filename+ exists, then it does nothing (does *not* update time),
|
55
42
|
# else, it creates the file.
|
56
|
-
#
|
43
|
+
#
|
57
44
|
# I just prefer this over +FileUtils.touch+.
|
58
|
-
#
|
45
|
+
#
|
59
46
|
# @param filename [String] the file to soft touch
|
60
47
|
# @param strip [Boolean] +true+ to strip +filename+ to help prevent fat-fingering, else +false+ to not
|
61
48
|
def self.soft_touch(filename,strip: true,textmode: true,**opt)
|
62
49
|
filename = Util.u_strip(filename) if strip
|
63
|
-
|
64
|
-
return if filename.empty?
|
50
|
+
|
51
|
+
return if filename.empty?
|
65
52
|
return if File.exist?(filename)
|
66
|
-
|
53
|
+
|
67
54
|
# Create the file.
|
68
|
-
open(filename,'a',textmode: textmode,**opt) do |file|
|
55
|
+
self.open(filename,'a',textmode: textmode,**opt) do |file|
|
69
56
|
end
|
70
57
|
end
|
71
|
-
|
72
|
-
def initialize(filename,mode=DEFAULT_MODE,buffer_len: DEFAULT_BUFFER_LEN,encoding: DEFAULT_ENCODING,
|
58
|
+
|
59
|
+
def initialize(filename,mode=DEFAULT_MODE,buffer_len: DEFAULT_BUFFER_LEN,encoding: DEFAULT_ENCODING,
|
60
|
+
separator: DEFAULT_SEPARATOR,**opt)
|
73
61
|
super(filename,mode,encoding: encoding,**opt)
|
74
|
-
|
62
|
+
|
75
63
|
@sscbot_buffer = nil
|
76
64
|
@sscbot_buffer_len = buffer_len
|
77
65
|
@sscbot_separator = separator
|
78
66
|
end
|
79
|
-
|
80
|
-
|
81
|
-
|
67
|
+
|
68
|
+
# Read a universal line.
|
69
|
+
def read_uline
|
70
|
+
if @sscbot_buffer.nil?
|
82
71
|
# See comment at loop below.
|
83
72
|
# - Use gets() instead of eof?() because of this method's name.
|
84
73
|
line = gets(nil,@sscbot_buffer_len)
|
85
|
-
|
86
|
-
return nil if line.nil?
|
87
|
-
|
74
|
+
|
75
|
+
return nil if line.nil? # Still EOF?
|
76
|
+
|
88
77
|
@sscbot_buffer = line
|
89
78
|
end
|
90
|
-
|
79
|
+
|
91
80
|
lines = @sscbot_buffer.split(@sscbot_separator,2)
|
92
|
-
|
81
|
+
|
93
82
|
# Will only have 2 if there was a separator.
|
94
83
|
if lines.length == 2
|
95
84
|
@sscbot_buffer = lines[1]
|
96
|
-
|
85
|
+
|
97
86
|
return lines[0]
|
98
87
|
end
|
99
|
-
|
88
|
+
|
100
89
|
# - Use a separator of nil to get all of the different types of newlines.
|
101
90
|
# - Use gets() [instead of read(), etc.] to work probably with text (e.g., UTF-8)
|
102
91
|
# and to not throw an error at EOF (returns nil).
|
103
|
-
while !(line = gets(nil,@sscbot_buffer_len)).nil?
|
92
|
+
while !(line = gets(nil,@sscbot_buffer_len)).nil?
|
104
93
|
lines = line.split(@sscbot_separator,2)
|
105
|
-
|
94
|
+
|
106
95
|
# Will only have 2 if there was a separator.
|
107
96
|
if lines.length == 2
|
108
97
|
line = "#{@sscbot_buffer}#{lines[0]}"
|
109
98
|
@sscbot_buffer = lines[1]
|
110
|
-
|
99
|
+
|
111
100
|
return line
|
112
101
|
else
|
113
102
|
@sscbot_buffer << line
|
114
103
|
end
|
115
104
|
end
|
116
|
-
|
105
|
+
|
117
106
|
# EOF reached with text in the buffer.
|
118
107
|
line = @sscbot_buffer
|
119
108
|
@sscbot_buffer = nil
|
120
|
-
|
109
|
+
|
121
110
|
return line
|
122
111
|
end
|
123
|
-
|
124
|
-
def seek_to_end
|
112
|
+
|
113
|
+
def seek_to_end
|
125
114
|
result = seek(0,:END)
|
126
|
-
|
127
|
-
|
128
|
-
|
115
|
+
|
116
|
+
read_uline # Justin Case
|
117
|
+
|
129
118
|
return result
|
130
119
|
end
|
131
120
|
end
|