]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/irc.rb
utils: htmlinfo filtering doc cleanups
[user/henk/code/ruby/rbot.git] / lib / rbot / irc.rb
index 72579b1967ce6c07b442c5ab559391940cb84d39..81ea43c657255b72c3d8c83df403f5ac71ebc2b0 100644 (file)
@@ -4,6 +4,8 @@
 #   Channels is the User on (of those the client is on too)?
 #   We may want this so that when a User leaves all Channels and he hasn't
 #   sent us privmsgs, we know we can remove him from the Server @users list
+#   FIXME for the time being, we do it with a method that scans the server
+#   (if defined), so the method is slow and should not be used frequently.
 # * Maybe ChannelList and UserList should be HashesOf instead of ArrayOf?
 #   See items marked as TODO Ho.
 #   The framework to do this is now in place, thanks to the new [] method
@@ -127,7 +129,7 @@ module Irc
     include Singleton
 
     def initialize
-      super('rfc1459', "\x41-\x5e", "\x61-\x7e")
+      super('rfc1459', "\x41-\x5a\x7b-\x7e", "\x61-\x7a\x5b-\x5e")
     end
 
   end
@@ -139,7 +141,7 @@ module Irc
     include Singleton
 
     def initialize
-      super('strict-rfc1459', "\x41-\x5d", "\x61-\x7d")
+      super('strict-rfc1459', "\x41-\x5a\x7b-\x7d", "\x61-\x7a\x5b-\x5d")
     end
 
   end
@@ -493,8 +495,8 @@ class Regexp
   HEX_DIGITS = /#{HEX_DIGIT}+/
   HEX_OCTET = /#{HEX_DIGIT}#{HEX_DIGIT}?/
   DEC_OCTET = /[01]?\d?\d|2[0-4]\d|25[0-5]/
-  DEC_IP_ADDR = /#{DEC_OCTET}.#{DEC_OCTET}.#{DEC_OCTET}.#{DEC_OCTET}/
-  HEX_IP_ADDR = /#{HEX_OCTET}.#{HEX_OCTET}.#{HEX_OCTET}.#{HEX_OCTET}/
+  DEC_IP_ADDR = /#{DEC_OCTET}\.#{DEC_OCTET}\.#{DEC_OCTET}\.#{DEC_OCTET}/
+  HEX_IP_ADDR = /#{HEX_OCTET}\.#{HEX_OCTET}\.#{HEX_OCTET}\.#{HEX_OCTET}/
   IP_ADDR = /#{DEC_IP_ADDR}|#{HEX_IP_ADDR}/
 
   # IPv6, from Resolv::IPv6, without the \A..\z anchors
@@ -922,7 +924,7 @@ module Irc
   class User < Netmask
     alias :to_s :nick
 
-    attr_accessor :real_name
+    attr_accessor :real_name, :idle_since, :signon
 
     # Create a new IRC User from a given Netmask (or anything that can be converted
     # into a Netmask) provided that the given Netmask does not have globs.
@@ -934,6 +936,8 @@ module Irc
       raise ArgumentError, "#{str.inspect} must not have globs (unescaped * or ?)" if host.has_irc_glob? && host != "*"
       @away = false
       @real_name = String.new
+      @idle_since = nil
+      @signon = nil
     end
 
     # The nick of a User may be changed freely, but it must not contain glob patterns.
@@ -1039,6 +1043,14 @@ module Irc
         raise "Can't resolve channel #{channel}"
       end
     end
+
+    def channels
+      if @server
+        @server.channels.select { |ch| ch.has_user?(self) }
+      else
+        Array.new
+      end
+    end
   end
 
 
@@ -1101,6 +1113,16 @@ module Irc
 
     end
 
+    # Hash of modes. Subclass of Hash that defines any? and all?
+    # to check if boolean modes (Type D) are set
+    class ModeHash < Hash
+      def any?(*ar)
+        !!ar.find { |m| s = m.to_sym ; self[s] && self[s].set? }
+      end
+      def all?(*ar)
+        !ar.find { |m| s = m.to_sym ; !(self[s] && self[s].set?) }
+      end
+    end
 
     # Channel modes of type A manipulate lists
     #
@@ -1289,12 +1311,15 @@ module Irc
     include ServerOrCasemap
     attr_reader :name, :topic, :mode, :users
     alias :to_s :name
+    attr_accessor :creation_time, :url
 
     def inspect
       str = self.__to_s__[0..-2]
       str << " on server #{server}" if server
       str << " @name=#{@name.inspect} @topic=#{@topic.text.inspect}"
       str << " @users=[#{user_nicks.sort.join(', ')}]"
+      str << " (created on #{creation_time})" if creation_time
+      str << " (URL #{url})" if url
       str << ">"
     end
 
@@ -1357,15 +1382,13 @@ module Irc
       }
 
       # Flags
-      @mode = {}
-      class << @mode
-        def any?(*ar)
-          !!ar.find { |m| s = m.to_sym ; self[s] && self[s].set? }
-        end
-        def all?(*ar)
-          !ar.find { |m| s = m.to_sym ; !(self[s] && self[s].set?) }
-        end
-      end
+      @mode = ModeHash.new
+
+      # creation time, only on some networks
+      @creation_time = nil
+
+      # URL, only on some networks
+      @url = nil
     end
 
     # Removes a user from the channel