cinch 2.2.4 → 2.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -616,7 +616,7 @@ module Cinch
616
616
  def on_307(msg, events)
617
617
  # RPL_WHOISREGNICK
618
618
  user = User(msg.params[1])
619
- update_whois(user, {:authname => user.nick})
619
+ update_whois(user, {:registered => true})
620
620
  end
621
621
 
622
622
  def on_311(msg, events)
@@ -18,7 +18,7 @@ module Cinch
18
18
  # @return [void]
19
19
  # @see #safe_notice
20
20
  def notice(text)
21
- msg(text, true)
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.split(/\r\n|\r|\n/).each do |line|
41
- maxlength = 510 - (":" + " #{command} " + " :").size
42
- maxlength = maxlength - @bot.mask.to_s.length - @name.to_s.length
43
- maxlength_without_end = maxlength - split_end.bytesize
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
@@ -303,6 +303,10 @@ module Cinch
303
303
  return
304
304
  end
305
305
 
306
+ if values[:registered]
307
+ values[:authname] ||= self.nick
308
+ values.delete(:registered)
309
+ end
306
310
  {
307
311
  :authname => nil,
308
312
  :idle => 0,
@@ -1,4 +1,4 @@
1
1
  module Cinch
2
2
  # Version of the library
3
- VERSION = '2.2.4'
3
+ VERSION = '2.2.5'
4
4
  end
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
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-02-10 00:00:00.000000000 Z
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: