]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/irc.rb
reaction: fix trigger regex to work with non-alphanumeric start/end.
[user/henk/code/ruby/rbot.git] / lib / rbot / irc.rb
index 23bd9e0da2b922df16ea8b3fdb5104da321fab1e..9a9998e7f391ce6c12a48b2c892d03063bc61c6f 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
 
 require 'singleton'
 
+# The following monkeypatch is to fix a bug in Singleton where marshaling would
+# fail when trying to restore a marshaled Singleton due to _load being declared
+# private.
+module ::Singleton
+  public :_dump
+end
+
+class << Singleton
+  module SingletonClassMethods
+    public :_load
+  end
+end
+
 class Object
 
   # We extend the Object class with a method that
@@ -31,7 +46,7 @@ class Object
 
   # We alias the to_s method to __to_s__ to make
   # it accessible in all classes
-  alias :__to_s__ :to_s 
+  alias :__to_s__ :to_s
 end
 
 # The Irc module is used to keep all IRC-related classes
@@ -127,7 +142,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 +154,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
@@ -540,7 +555,7 @@ class Regexp
     GEN_HOST = /#{HOSTNAME}|#{HOSTADDR}/
 
     # # FreeNode network replaces the host of affiliated users with
-    # # 'virtual hosts' 
+    # # 'virtual hosts'
     # # FIXME we need the true syntax to match it properly ...
     # PDPC_HOST_PART = /[0-9A-Za-z.-]+/
     # PDPC_HOST = /#{PDPC_HOST_PART}(?:\/#{PDPC_HOST_PART})+/
@@ -548,7 +563,7 @@ class Regexp
     # # NOTE: the final optional and non-greedy dot is needed because some
     # # servers (e.g. FreeNode) send the hostname of the services as "services."
     # # which is not RFC compliant, but sadly done.
-    # GEN_HOST_EXT = /#{PDPC_HOST}|#{GEN_HOST}\.??/ 
+    # GEN_HOST_EXT = /#{PDPC_HOST}|#{GEN_HOST}\.??/
 
     # Sadly, different networks have different, RFC-breaking ways of cloaking
     # the actualy host address: see above for an example to handle FreeNode.
@@ -922,7 +937,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 +949,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 +1056,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
 
 
@@ -1338,7 +1363,7 @@ module Irc
     # Adds a user to the channel
     #
     def add_user(user, opts={})
-      silent = opts.fetch(:silent, false) 
+      silent = opts.fetch(:silent, false)
       if has_user?(user)
         warn "Trying to add user #{user} to channel #{self} again" unless silent
       else