cinch 2.0.10 → 2.0.11

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.
@@ -112,7 +112,7 @@ module Cinch
112
112
  socket.write_nonblock [total].pack("N")
113
113
  rescue Errno::EWOULDBLOCK, Errno::AGAIN
114
114
  # Nobody cares about ACKs, really. And if the sender
115
- # couldn't receive it at this point, he probably doesn't
115
+ # couldn't receive it at this point, they probably don't
116
116
  # care, either.
117
117
  end
118
118
  io << buf
data/lib/cinch/irc.rb CHANGED
@@ -36,7 +36,7 @@ module Cinch
36
36
  def setup
37
37
  @registration = []
38
38
  @network = Network.new(:unknown, :unknown)
39
- @whois_updates = Hash.new {|h, k| h[k] = {}}
39
+ @whois_updates = {}
40
40
  @in_lists = Set.new
41
41
  end
42
42
 
@@ -233,7 +233,7 @@ module Cinch
233
233
  msg = Message.new(input, @bot)
234
234
  events = [[:catchall]]
235
235
 
236
- if ("001".."004").include? msg.command
236
+ if ["001", "002", "003", "004", "422"].include?(msg.command)
237
237
  @registration << msg.command
238
238
  if registered?
239
239
  events << [:connect]
@@ -276,7 +276,7 @@ module Cinch
276
276
 
277
277
  # @return [Boolean] true if we successfully registered yet
278
278
  def registered?
279
- (("001".."004").to_a - @registration).empty?
279
+ (("001".."004").to_a - @registration).empty? || @registration.include?("422")
280
280
  end
281
281
 
282
282
  # Send a message to the server.
@@ -366,6 +366,11 @@ module Cinch
366
366
  end
367
367
  end
368
368
 
369
+ def update_whois(user, data)
370
+ @whois_updates[user] ||= {}
371
+ @whois_updates[user].merge!(data)
372
+ end
373
+
369
374
  # @since 2.0.0
370
375
  def on_away(msg, events)
371
376
  if msg.message.to_s.empty?
@@ -538,10 +543,10 @@ module Cinch
538
543
 
539
544
  if msg.message.downcase == "excess flood" && msg.user == @bot
540
545
  @bot.warn ["Looks like your bot has been kicked because of excess flood.",
541
- "If you haven't modified the throttling options manually, please file a bug report at https://github.com/cinchrb/cinch/issues and include the following information:",
542
- "- Server: #{@bot.config.server}",
543
- "- Messages per second: #{@bot.config.messages_per_second}",
544
- "- Server queue size: #{@bot.config.server_queue_size}"]
546
+ "If you haven't modified the throttling options manually, please file a bug report at https://github.com/cinchrb/cinch/issues and include the following information:",
547
+ "- Server: #{@bot.config.server}",
548
+ "- Messages per second: #{@bot.config.messages_per_second}",
549
+ "- Server queue size: #{@bot.config.server_queue_size}"]
545
550
  end
546
551
  end
547
552
 
@@ -603,7 +608,7 @@ module Cinch
603
608
  away = msg.message
604
609
 
605
610
  if @whois_updates[user]
606
- @whois_updates[user].merge!({:away => away})
611
+ update_whois(user, {:away => away})
607
612
  end
608
613
  end
609
614
 
@@ -611,36 +616,38 @@ module Cinch
611
616
  def on_307(msg, events)
612
617
  # RPL_WHOISREGNICK
613
618
  user = User(msg.params[1])
614
- @whois_updates[user].merge!({:authname => user.nick})
619
+ update_whois(user, {:authname => user.nick})
615
620
  end
616
621
 
617
622
  def on_311(msg, events)
618
623
  # RPL_WHOISUSER
619
624
  user = User(msg.params[1])
620
- @whois_updates[user].merge!({
621
- :user => msg.params[2],
622
- :host => msg.params[3],
623
- :realname => msg.params[5],
624
- })
625
+ update_whois(user, {
626
+ :user => msg.params[2],
627
+ :host => msg.params[3],
628
+ :realname => msg.params[5],
629
+ })
625
630
  end
626
631
 
627
632
  def on_317(msg, events)
628
633
  # RPL_WHOISIDLE
629
634
  user = User(msg.params[1])
630
- @whois_updates[user].merge!({
631
- :idle => msg.params[2].to_i,
632
- :signed_on_at => Time.at(msg.params[3].to_i),
633
- })
635
+ update_whois(user, {
636
+ :idle => msg.params[2].to_i,
637
+ :signed_on_at => Time.at(msg.params[3].to_i),
638
+ })
634
639
  end
635
640
 
636
641
  def on_318(msg, events)
637
642
  # RPL_ENDOFWHOIS
638
643
  user = User(msg.params[1])
639
644
 
640
- if @whois_updates[user].empty? && !user.attr(:unknown?, true, true)
641
- user.end_of_whois(nil)
642
- else
643
- user.end_of_whois(@whois_updates[user])
645
+ if @whois_updates[user]
646
+ if @whois_updates[user].empty? && !user.attr(:unknown?, true, true)
647
+ user.end_of_whois(nil)
648
+ else
649
+ user.end_of_whois(@whois_updates[user])
650
+ end
644
651
  @whois_updates.delete user
645
652
  end
646
653
  end
@@ -815,10 +822,7 @@ module Cinch
815
822
 
816
823
  def on_401(msg, events)
817
824
  # ERR_NOSUCHNICK
818
- user = User(msg.params[1])
819
- user.sync(:unknown?, true, true)
820
- msg.user.online = false
821
- if @whois_updates.key?(user)
825
+ if user = @bot.user_list.find(msg.params[1])
822
826
  user.end_of_whois(nil, true)
823
827
  @whois_updates.delete user
824
828
  end
data/lib/cinch/message.rb CHANGED
@@ -231,7 +231,7 @@ module Cinch
231
231
  chantypes = @bot.irc.isupport["CHANTYPES"]
232
232
  if chantypes.include?(@params.first[0])
233
233
  @bot.channel_list.find_ensured(@params.first)
234
- elsif numeric_reply? and chantypes.include?(@params[1][0])
234
+ elsif numeric_reply? and @params.size > 1 and chantypes.include?(@params[1][0])
235
235
  @bot.channel_list.find_ensured(@params[1])
236
236
  end
237
237
  end
data/lib/cinch/user.rb CHANGED
@@ -365,6 +365,10 @@ module Cinch
365
365
  # @return [void]
366
366
  def update_nick(new_nick)
367
367
  @last_nick, @name = @name, new_nick
368
+ # Unsync authname because some networks tie authentication to
369
+ # the nick, so the user might not be authenticated anymore after
370
+ # changing his nick
371
+ unsync(:authname)
368
372
  @bot.user_list.update_nick(self)
369
373
  end
370
374
 
@@ -22,6 +22,7 @@ module Cinch
22
22
  # @return [User]
23
23
  # @see Bot#User
24
24
  def find_ensured(*args)
25
+ user, host = nil, nil
25
26
  case args.size
26
27
  when 1
27
28
  nick = args.first
@@ -29,12 +30,20 @@ module Cinch
29
30
  when 3
30
31
  nick = args[1]
31
32
  bargs = args
33
+ user, _, host = bargs
32
34
  else
33
35
  raise ArgumentError
34
36
  end
35
37
  downcased_nick = nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
36
38
  @mutex.synchronize do
37
- @cache[downcased_nick] ||= User.new(*bargs, @bot)
39
+ user_obj = @cache[downcased_nick] ||= User.new(*bargs, @bot)
40
+ if user && host
41
+ # Explicitly set user and host whenever we request a User
42
+ # object to update them on e.g. JOIN.
43
+ user_obj.sync(:user, user, true)
44
+ user_obj.sync(:host, host, true)
45
+ end
46
+ user_obj
38
47
  end
39
48
  end
40
49
 
data/lib/cinch/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Cinch
2
2
  # Version of the library
3
- VERSION = '2.0.10'
3
+ VERSION = '2.0.11'
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.0.10
4
+ version: 2.0.11
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: 2013-11-03 00:00:00.000000000 Z
12
+ date: 2013-12-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A simple, friendly DSL for creating IRC bots
15
15
  email: