cinch 2.2.4 → 2.2.5
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.
- data/lib/cinch/irc.rb +1 -1
- data/lib/cinch/target.rb +35 -23
- data/lib/cinch/user.rb +4 -0
- data/lib/cinch/version.rb +1 -1
- metadata +2 -2
data/lib/cinch/irc.rb
CHANGED
data/lib/cinch/target.rb
CHANGED
@@ -18,7 +18,7 @@ module Cinch
|
|
18
18
|
# @return [void]
|
19
19
|
# @see #safe_notice
|
20
20
|
def notice(text)
|
21
|
-
|
21
|
+
send(text, true)
|
22
22
|
end
|
23
23
|
|
24
24
|
# Sends a PRIVMSG to the target.
|
@@ -36,29 +36,13 @@ module Cinch
|
|
36
36
|
split_start = @bot.config.message_split_start || ""
|
37
37
|
split_end = @bot.config.message_split_end || ""
|
38
38
|
command = notice ? "NOTICE" : "PRIVMSG"
|
39
|
+
prefix = ":#{@bot.mask} #{command} #{@name} :"
|
39
40
|
|
40
|
-
text.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
if line.bytesize > maxlength
|
46
|
-
splitted = []
|
47
|
-
|
48
|
-
while line.bytesize > maxlength_without_end
|
49
|
-
pos = line.rindex(/\s/, maxlength_without_end)
|
50
|
-
r = pos || maxlength_without_end
|
51
|
-
splitted << line.slice!(0, r) + split_end.tr(" ", "\u00A0")
|
52
|
-
line = split_start.tr(" ", "\u00A0") + line.lstrip
|
53
|
-
end
|
54
|
-
|
55
|
-
splitted << line
|
56
|
-
splitted[0, (@bot.config.max_messages || splitted.size)].each do |string|
|
57
|
-
string.tr!("\u00A0", " ") # clean string from any non-breaking spaces
|
58
|
-
@bot.irc.send("#{command} #@name :#{string}")
|
59
|
-
end
|
60
|
-
else
|
61
|
-
@bot.irc.send("#{command} #@name :#{line}")
|
41
|
+
text.lines.map(&:chomp).each do |line|
|
42
|
+
splitted = split_message(line, prefix, split_start, split_end)
|
43
|
+
|
44
|
+
splitted[0, (@bot.config.max_messages || splitted.size)].each do |string|
|
45
|
+
@bot.irc.send("#{command} #@name :#{string}")
|
62
46
|
end
|
63
47
|
end
|
64
48
|
end
|
@@ -182,5 +166,33 @@ module Cinch
|
|
182
166
|
nil
|
183
167
|
end
|
184
168
|
end
|
169
|
+
|
170
|
+
private
|
171
|
+
def split_message(msg, prefix, split_start, split_end)
|
172
|
+
max_bytesize = 510 - prefix.bytesize
|
173
|
+
max_bytesize_without_end = max_bytesize - split_end.bytesize
|
174
|
+
|
175
|
+
if msg.bytesize <= max_bytesize
|
176
|
+
return [msg]
|
177
|
+
end
|
178
|
+
|
179
|
+
splitted = []
|
180
|
+
while msg.bytesize > max_bytesize_without_end
|
181
|
+
acc = 0
|
182
|
+
acc_rune_sizes = msg.each_char.map {|ch|
|
183
|
+
acc += ch.bytesize
|
184
|
+
}
|
185
|
+
|
186
|
+
max_rune = acc_rune_sizes.rindex {|bs| bs <= max_bytesize_without_end} || 0
|
187
|
+
r = [msg.rindex(/\s/, max_rune) || (max_rune + 1), 1].max
|
188
|
+
|
189
|
+
splitted << (msg[0...r] + split_end)
|
190
|
+
msg = split_start.tr(" ", "\z") + msg[r..-1].lstrip
|
191
|
+
end
|
192
|
+
splitted << msg
|
193
|
+
|
194
|
+
# clean string from any substitute characters
|
195
|
+
splitted.map {|string| string.tr("\z", " ")}
|
196
|
+
end
|
185
197
|
end
|
186
198
|
end
|
data/lib/cinch/user.rb
CHANGED
data/lib/cinch/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-03-30 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A simple, friendly DSL for creating IRC bots
|
15
15
|
email:
|