]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/irc.rb
Too much stuff was being sent with each line, go back to 400 bytes max
[user/henk/code/ruby/rbot.git] / lib / rbot / irc.rb
index 21c7226415e8519ddfd1aab2e2e8f07ac922f024..f2425d6a986b869a194722407297c2f05e35fac3 100644 (file)
@@ -84,11 +84,18 @@ module Irc
       @key.to_s\r
     end\r
 \r
+    # Two Casemaps are equal if they have the same upper and lower ranges\r
+    #\r
+    def ==(arg)\r
+      other = arg.to_irc_casemap\r
+      return self.upper == other.upper && self.lower == other.lower\r
+    end\r
+\r
     # Raise an error if _arg_ and self are not the same Casemap\r
     #\r
     def must_be(arg)\r
       other = arg.to_irc_casemap\r
-      raise "Casemap mismatch (#{self} != #{other})" unless self == other\r
+      raise "Casemap mismatch (#{self.inspect} != #{other.inspect})" unless self == other\r
       return true\r
     end\r
 \r
@@ -616,10 +623,15 @@ module Irc
     #\r
     def matches?(arg)\r
       cmp = arg.to_irc_netmask(:casemap => casemap)\r
+      debug "Matching #{self.fullform} against #{arg.fullform}"\r
       [:nick, :user, :host].each { |component|\r
         us = self.send(component).irc_downcase(casemap)\r
         them = cmp.send(component).irc_downcase(casemap)\r
-        raise NotImplementedError if us.has_irc_glob? && them.has_irc_glob?\r
+        if us.has_irc_glob? && them.has_irc_glob?\r
+          next if us == them\r
+          warn NotImplementedError\r
+          return false\r
+        end\r
         return false if us.has_irc_glob? && !them.has_irc_glob?\r
         return false unless us =~ them.to_irc_regexp\r
       }\r
@@ -774,14 +786,14 @@ module Irc
     def replace(other)\r
       case other\r
       when User\r
-        nick = other.nick\r
-        user = other.user\r
-        host = other.host\r
+        self.nick = other.nick\r
+        self.user = other.user\r
+        self.host = other.host\r
         @server = other.server\r
         @casemap = other.casemap unless @server\r
-        @away = other.away\r
+        @away = other.away?\r
       else\r
-        replace(other.to_irc_user(server_and_casemap))\r
+        self.replace(other.to_irc_user(server_and_casemap))\r
       end\r
     end\r
 \r
@@ -1282,7 +1294,7 @@ module Irc
             groups = val.split(',')\r
             groups.each { |g|\r
               k, v = g.split(':')\r
-              @supports[key][k] = v.to_i\r
+              @supports[key][k] = v.to_i || 0\r
             }\r
           }\r
         when :chanmodes\r
@@ -1313,8 +1325,8 @@ module Irc
           }\r
         when :maxtargets\r
           noval_warn(key, val) {\r
-            @supports[key]['PRIVMSG'] = val.to_i\r
-            @supports[key]['NOTICE'] = val.to_i\r
+            @supports[:targmax]['PRIVMSG'] = val.to_i\r
+            @supports[:targmax]['NOTICE'] = val.to_i\r
           }\r
         when :network\r
           noval_warn(key, val) {\r
@@ -1506,17 +1518,20 @@ module Irc
     def new_user(str, fails=true)\r
       tmp = str.to_irc_user(:server => self)\r
       old = get_user(tmp.nick)\r
+      # debug "Tmp: #{tmp.inspect}"\r
+      # debug "Old: #{old.inspect}"\r
       if old\r
         # debug "User already existed as #{old.inspect}"\r
         if tmp.known?\r
           if old.known?\r
+            # debug "Both were known"\r
             # Do not raise an error: things like Freenode change the hostname after identification\r
             warning "User #{tmp.nick} has inconsistent Netmasks! #{self} knows #{old.inspect} but access was tried with #{tmp.inspect}" if old != tmp\r
             raise "User #{tmp} already exists on server #{self}" if fails\r
           end\r
-          if old != tmp\r
+          if old.fullform.downcase != tmp.fullform.downcase\r
             old.replace(tmp)\r
-            # debug "User improved to #{old.inspect}"\r
+            # debug "Known user now #{old.inspect}"\r
           end\r
         end\r
         return old\r