]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/irc.rb
Fix small typo in basics core botmodule
[user/henk/code/ruby/rbot.git] / lib / rbot / irc.rb
index 5d3b01ec1a1139551867b507fafaaa20c62390c3..8ef55712cf48affeb815482241a1635b3f26d51c 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
@@ -176,14 +183,18 @@ module Irc
     # @server (if possible) or at the @casemap otherwise\r
     #\r
     def casemap\r
-      @server.casemap rescue @casemap\r
+      return @server.casemap if defined?(@server) and @server\r
+      return @casemap\r
     end\r
 \r
     # Returns a hash with the current @server and @casemap as values of\r
     # :server and :casemap\r
     #\r
     def server_and_casemap\r
-      {:server => @server, :casemap => @casemap}\r
+      h = {}\r
+      h[:server] = @server if defined?(@server) and @server\r
+      h[:casemap] = @casemap if defined?(@casemap) and @casemap\r
+      return h\r
     end\r
 \r
     # We allow up/downcasing with a different casemap\r
@@ -531,10 +542,10 @@ module Irc
     #\r
     def inspect\r
       str = "<#{self.class}:#{'0x%x' % self.object_id}:"\r
-      str << " @server=#{@server}" if @server\r
+      str << " @server=#{@server}" if defined?(@server) and @server\r
       str << " @nick=#{@nick.inspect} @user=#{@user.inspect}"\r
-      str << " @host=#{@host.inspect} casemap=#{casemap.inspect}>"\r
-      str\r
+      str << " @host=#{@host.inspect} casemap=#{casemap.inspect}"\r
+      str << ">"\r
     end\r
 \r
     # Equality: two Netmasks are equal if they downcase to the same thing\r
@@ -612,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
@@ -770,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
@@ -1008,8 +1024,8 @@ module Irc
       str = "<#{self.class}:#{'0x%x' % self.object_id}:"\r
       str << " on server #{server}" if server\r
       str << " @name=#{@name.inspect} @topic=#{@topic.text.inspect}"\r
-      str << " @users=<#{@users.sort.join(', ')}>"\r
-      str\r
+      str << " @users=[#{@users.sort.join(', ')}]"\r
+      str << ">"\r
     end\r
 \r
     # Returns self\r
@@ -1154,8 +1170,8 @@ module Irc
       str = "<#{self.class}:#{'0x%x' % self.object_id}:"\r
       str << " @hostname=#{hostname}"\r
       str << " @channels=#{chans}"\r
-      str << " @users=#{users}>"\r
-      str\r
+      str << " @users=#{users}"\r
+      str << ">"\r
     end\r
 \r
     # Create a new Server, with all instance variables reset to nil (for\r
@@ -1176,7 +1192,7 @@ module Irc
     #\r
     def reset_capabilities\r
       @supports = {\r
-        :casemapping => 'rfc1459',\r
+        :casemapping => 'rfc1459'.to_irc_casemap,\r
         :chanlimit => {},\r
         :chanmodes => {\r
           :typea => nil, # Type A: address lists\r
@@ -1269,9 +1285,9 @@ module Irc
           key = prekey.downcase.to_sym\r
         end\r
         case key\r
-        when :casemapping, :network\r
+        when :casemapping\r
           noval_warn(key, val) {\r
-            @supports[key] = val\r
+            @supports[key] = val.to_irc_casemap\r
           }\r
         when :chanlimit, :idchan, :maxlist, :targmax\r
           noval_warn(key, val) {\r
@@ -1281,15 +1297,6 @@ module Irc
               @supports[key][k] = v.to_i\r
             }\r
           }\r
-        when :maxchannels\r
-          noval_warn(key, val) {\r
-            reparse += "CHANLIMIT=(chantypes):#{val} "\r
-          }\r
-        when :maxtargets\r
-          noval_warn(key, val) {\r
-            @supports[key]['PRIVMSG'] = val.to_i\r
-            @supports[key]['NOTICE'] = val.to_i\r
-          }\r
         when :chanmodes\r
           noval_warn(key, val) {\r
             groups = val.split(',')\r
@@ -1312,6 +1319,19 @@ module Irc
         when :invex\r
           val ||= 'I'\r
           @supports[key] = val\r
+        when :maxchannels\r
+          noval_warn(key, val) {\r
+            reparse += "CHANLIMIT=(chantypes):#{val} "\r
+          }\r
+        when :maxtargets\r
+          noval_warn(key, val) {\r
+            @supports[key]['PRIVMSG'] = val.to_i\r
+            @supports[key]['NOTICE'] = val.to_i\r
+          }\r
+        when :network\r
+          noval_warn(key, val) {\r
+            @supports[key] = val\r
+          }\r
         when :nicklen\r
           noval_warn(key, val) {\r
             @supports[key] = val.to_i\r
@@ -1498,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