From 0aa0919fdbfa148dfbb5961f14f27e41085959b4 Mon Sep 17 00:00:00 2001 From: Dmitry Kim Date: Sat, 22 Sep 2007 13:31:20 +0000 Subject: + (irc) generalize() method for Netmask class --- lib/rbot/irc.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib/rbot') diff --git a/lib/rbot/irc.rb b/lib/rbot/irc.rb index 371762cb..2a4642a2 100644 --- a/lib/rbot/irc.rb +++ b/lib/rbot/irc.rb @@ -751,6 +751,26 @@ module Irc return @nick.has_irc_glob? || @user.has_irc_glob? || @host.has_irc_glob? end + def generalize + u = user.dup + unless u.has_irc_glob? + u.sub!(/^[in]=/, '=') or u.sub!(/^\W(\w+)/, '\1') + u = '*' + u + end + + h = host.dup + unless h.has_irc_glob? + if h.include? '/' + h.sub!(/x-\w+$/, 'x-*') + else + h.match(/^[^\.]+\.[^\.]+$/) or + h.sub!(/^(\d+\.\d+\.\d+\.)\d+$/, '\1*') or + h.sub!(/^[^\.]+\./, '*.') + end + end + return Netmask.new("*!#{u}@#{h}", server_and_casemap) + end + # This method is used to match the current Netmask against another one # # The method returns true if each component of the receiver matches the -- cgit v1.2.3