# This module defines the fundamental building blocks for IRC
#
# Author:: Giuseppe Bilotta (giuseppe.bilotta@gmail.com)
-# Copyright:: Copyright (c) 2006 Giuseppe Bilotta
-# License:: GPLv2
require 'singleton'
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
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.
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.
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
#
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
}
# Flags
- @mode = {}
+ @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