X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Firc.rb;h=0edfb35a4de903f0bfc57acf72670789d95dd473;hb=08b62fa4b33ef08ddc2a98651438546529b6c449;hp=f34c8f9b4afa5ff0cd4e8a6374b45b5dd315246b;hpb=0d528d46751585eae11510a772b77d241f3c7777;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/irc.rb b/lib/rbot/irc.rb index f34c8f9b..0edfb35a 100644 --- a/lib/rbot/irc.rb +++ b/lib/rbot/irc.rb @@ -639,21 +639,38 @@ module Irc ret << "@" << host unless host == "*" return ret end + def fullform "#{nick}!#{user}@#{host}" end + # This method downcases the fullform of the netmask. While this may not be + # significantly different from the #downcase() method provided by the + # ServerOrCasemap mixin, it's significantly different for Netmask + # subclasses such as User whose simple downcasing uses the nick only. + # + def full_irc_downcase(cmap=casemap) + self.fullform.irc_downcase(cmap) + end + + # full_downcase() will return the fullform downcased according to the + # User's own casemap + # + def full_downcase + self.full_irc_downcase + end + # Converts the receiver into a Netmask with the given (optional) # server/casemap association. We return self unless a conversion # is needed (different casemap/server) # - # Subclasses of Netmask will return a new Netmask + # Subclasses of Netmask will return a new Netmask, using full_downcase # def to_irc_netmask(opts={}) if self.class == Netmask return self if fits_with_server_and_casemap?(opts) end - return self.downcase.to_irc_netmask(opts) + return self.full_downcase.to_irc_netmask(opts) end # Converts the receiver into a User with the given (optional) @@ -927,21 +944,6 @@ module Irc end end - # Users can be either simply downcased (their nick only) - # or fully downcased: this will return the fullform downcased - # according to the given casemap. - # - def full_irc_downcase(cmap=casemap) - self.fullform.irc_downcase(cmap) - end - - # full_downcase() will return the fullform downcased according to the - # User's own casemap - # - def full_downcase - self.full_irc_downcase - end - # Since to_irc_user runs the same checks on server and channel as # to_irc_netmask, we just try that and return self if it works. # @@ -968,6 +970,35 @@ module Irc end end + def modes_on(channel) + case channel + when Channel + channel.modes_of(self) + else + return @server.channel(channel).modes_of(self) if @server + raise "Can't resolve channel #{channel}" + end + end + + def is_op?(channel) + case channel + when Channel + channel.has_op?(self) + else + return @server.channel(channel).has_op?(self) if @server + raise "Can't resolve channel #{channel}" + end + end + + def is_voice?(channel) + case channel + when Channel + channel.has_voice?(self) + else + return @server.channel(channel).has_voice?(self) if @server + raise "Can't resolve channel #{channel}" + end + end end @@ -1334,6 +1365,21 @@ module Irc @mode[sym.to_sym] = kl.new(self) end + def modes_of(user) + l = [] + @mode.map { |s, m| + l << s if (m.class <= UserMode and m.list[user]) + } + l + end + + def has_op?(user) + @mode.has_key?(:o) and @mode[:o].list[user] + end + + def has_voice?(user) + @mode.has_key?(:v) and @mode[:v].list[user] + end end