]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/rfc2812.rb
test: fix shadowed test method
[user/henk/code/ruby/rbot.git] / lib / rbot / rfc2812.rb
index ee0d08d605d40781c40b0e3e656d4d82a0a68e43..0839d1d52593db514d4458a92c19b57c4c6c7b1a 100644 (file)
@@ -6,6 +6,9 @@
 # This module defines the Irc::Client class, a class that can handle and
 # dispatch messages based on RFC 2821 (Internet Relay Chat: Client Protocol)
 
+class ServerMessageParseError < ServerError
+end
+
 module Irc
   # - The server sends Replies 001 to 004 to a user upon
   #   successful registration.
@@ -946,6 +949,9 @@ module Irc
   ERR_NOSERVICEHOST=492
   RPL_DATASTR=290
 
+  # A structure to hold LIST data, in the Irc namespace
+  ListData = Struct.new :channel, :users, :topic
+
   # Implements RFC 2812 and prior IRC RFCs.
   #
   # Clients should register Proc{}s to handle the various server events, and
@@ -967,6 +973,9 @@ module Irc
       # This is used by some messages to build lists of users that
       # will be delegated when the ENDOF... message is received
       @tmpusers = []
+
+      # Same as above, just for bans
+      @tmpbans = []
     end
 
     # Clear the server and reset the user
@@ -1027,7 +1036,7 @@ module Irc
       data[:serverstring] = serverstring
 
       unless serverstring.chomp =~ /^(:(\S+)\s)?(\S+)(\s(.*))?$/
-        raise "Unparseable Server Message!!!: #{serverstring.inspect}"
+        raise ServerMessageParseError, (serverstring.chomp rescue serverstring)
       end
 
       prefix, command, params = $2, $3, $5
@@ -1180,6 +1189,17 @@ module Irc
           data[:users] = @tmpusers
           handle(:names, data)
           @tmpusers = Array.new
+        when RPL_BANLIST
+          data[:channel] = @server.channel(argv[1])
+          data[:mask] = argv[2]
+          data[:by] = argv[3]
+          data[:at] = argv[4]
+          @tmpbans << data
+        when RPL_ENDOFBANLIST
+          data[:channel] = @server.channel(argv[1])
+          data[:bans] = @tmpbans
+          handle(:banlist, data)
+          @tmpbans = Array.new
         when RPL_LUSERCLIENT
           # ":There are <integer> users and <integer>
           # services on <integer> servers"
@@ -1317,7 +1337,7 @@ module Irc
         when RPL_WHOISCHANNELS
           @whois ||= Hash.new
           @whois[:nick] = argv[1]
-          @whois[:channels] = []
+          @whois[:channels] ||= []
           user = @server.user(@whois[:nick])
           argv[-1].split.each do |prechan|
             pfx = prechan.scan(/[#{@server.supports[:prefix][:prefixes].join}]/)
@@ -1330,6 +1350,18 @@ module Irc
 
             @whois[:channels] << [chan, modes]
           end
+        when RPL_LISTSTART
+          # ignore
+        when RPL_LIST
+          @list ||= Hash.new
+          chan = argv[1]
+          users = argv[2]
+          topic = argv[3]
+          @list[chan] = ListData.new(chan, users, topic)
+        when RPL_LISTEND
+          @list ||= Hash.new
+          data[:list] = @list
+          handle(:list, data)
         when RPL_CHANNELMODEIS
           parse_mode(serverstring, argv[1..-1], data)
           handle(:mode, data)
@@ -1344,17 +1376,19 @@ module Irc
           data[:channel].url=data[:url].dup
           handle(:channel_url, data)
         when ERR_NOSUCHNICK
-          data[:nick] = argv[1]
-          if user = @server.get_user(data[:nick])
+          data[:target] = argv[1]
+          data[:message] = argv[2]
+          handle(:nosuchtarget, data)
+          if user = @server.get_user(data[:target])
             @server.delete_user(user)
           end
-          handle(:nosuchnick, data)
         when ERR_NOSUCHCHANNEL
-          data[:channel] = argv[1]
-          if channel = @server.get_channel(data[:channel])
+          data[:target] = argv[1]
+          data[:message] = argv[2]
+          handle(:nosuchtarget, data)
+          if channel = @server.get_channel(data[:target])
             @server.delete_channel(channel)
           end
-          handle(:nosuchchannel, data)
         else
           warning "Unknown message #{serverstring.inspect}"
           handle(:unknown, data)