X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Firc.rb;h=c57b252f58973801f7f5b8a6e234a56903c1185e;hb=b73f06958c304dc5bc82523765f893211785f2d0;hp=c893fc2728d22b0d44383f755970390fa4c7faa8;hpb=34ca2ba507e4246f1bc1851b04d2ecdffd433a19;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/irc.rb b/lib/rbot/irc.rb index c893fc27..c57b252f 100644 --- a/lib/rbot/irc.rb +++ b/lib/rbot/irc.rb @@ -273,7 +273,13 @@ class String # This method returns the Irc::Casemap whose name is the receiver # def to_irc_casemap - Irc::Casemap.get(self) rescue raise TypeError, "Unkown Irc::Casemap #{self.inspect}" + begin + Irc::Casemap.get(self) + rescue + # raise TypeError, "Unkown Irc::Casemap #{self.inspect}" + error "Unkown Irc::Casemap #{self.inspect} requested, defaulting to rfc1459" + Irc::Casemap.get('rfc1459') + end end # This method returns a string which is the downcased version of the @@ -1323,6 +1329,13 @@ module Irc # class Channel + # Return the non-prefixed part of a channel name. + # Also works with ## channels found on some networks + # (e.g. FreeNode) + def self.npname(str) + return str.to_s.sub(/^[&#+!]+/,'') + end + include ServerOrCasemap attr_reader :name, :topic, :mode, :users alias :to_s :name @@ -1512,7 +1525,6 @@ module Irc class Server attr_reader :hostname, :version, :usermodes, :chanmodes - alias :to_s :hostname attr_reader :supports, :capabilities attr_reader :channels, :users @@ -1543,6 +1555,10 @@ module Irc str << ">" end + def to_s + hostname.nil? ? "" : hostname + end + # Create a new Server, with all instance variables reset to nil (for # scalar variables), empty channel and user lists and @supports # initialized to the default values for all known supported features. @@ -1661,7 +1677,7 @@ module Irc def parse_isupport(line) debug "Parsing ISUPPORT #{line.inspect}" ar = line.split(' ') - reparse = "" + reparse = [] ar.each { |en| prekey, val = en.split('=', 2) if prekey =~ /^-(.*)/ @@ -1673,7 +1689,15 @@ module Irc case key when :casemapping noval_warn(key, val) { - @supports[key] = val.to_irc_casemap + if val == 'charset' + reparse << "CASEMAPPING=(charset)" + else + # TODO some servers offer non-standard CASEMAPPINGs in the form + # locale.charset[-options], which indicate an extended set of + # allowed characters (mostly for nicks). This might be supported + # with hooks for the unicode core module + @supports[key] = val.to_irc_casemap + end } when :chanlimit, :idchan, :maxlist, :targmax noval_warn(key, val) { @@ -1711,7 +1735,7 @@ module Irc @supports[key] = val when :maxchannels noval_warn(key, val) { - reparse += "CHANLIMIT=(chantypes):#{val} " + reparse << "CHANLIMIT=(chantypes):#{val} " } when :maxtargets noval_warn(key, val) { @@ -1752,8 +1776,12 @@ module Irc @supports[key] = val.nil? ? true : val end } - reparse.gsub!("(chantypes)",@supports[:chantypes]) - parse_isupport(reparse) unless reparse.empty? + unless reparse.empty? + reparse_str = reparse.join(" ") + reparse_str.gsub!("(chantypes)",@supports[:chantypes]) + reparse_str.gsub!("(charset)",@supports[:charset] || 'rfc1459') + parse_isupport(reparse_str) + end end # Returns the casemap of the server.