X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Firc.rb;h=b8ca459304d453b6e8e183ed656b684a1e7da882;hb=9c50738a84bec26402902513a4cd21b54dcc0a80;hp=f3964d837695a5a68cdffcecbfc9b787d417710a;hpb=100f55b10d33f54cdddea52a3b256ca48a15d1d1;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/irc.rb b/lib/rbot/irc.rb index f3964d83..b8ca4593 100644 --- a/lib/rbot/irc.rb +++ b/lib/rbot/irc.rb @@ -461,6 +461,13 @@ class ArrayOf < Array } end + # We introduce the 'downcase' method, which maps downcase() to all the Array + # elements, properly failing when the elements don't have a downcase method + # + def downcase + self.map { |el| el.downcase } + end + # Modifying methods which we don't handle yet are made private # private :[]=, :collect!, :map!, :fill, :flatten! @@ -540,7 +547,7 @@ module Irc if self.class == Netmask return self if fits_with_server_and_casemap?(opts) end - return self.fullform.to_irc_netmask(server_and_casemap.merge(opts)) + return self.downcase.to_irc_netmask(opts) end # Converts the receiver into a User with the given (optional) @@ -684,7 +691,10 @@ module Irc end # We enhance the [] method by allowing it to pick an element that matches - # a given Netmask or String + # a given Netmask, a String or a Regexp + # TODO take into consideration the opportunity to use select() instead of + # find(), and/or a way to let the user choose which one to take (second + # argument?) # def [](*args) if args.length == 1 @@ -697,6 +707,10 @@ module Irc self.find { |mask| mask.matches?(args[0].to_irc_netmask(:casemap => mask.casemap)) } + when Regexp + self.find { |mask| + mask.fullform =~ args[0] + } else super(*args) end @@ -807,6 +821,21 @@ 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. # @@ -814,7 +843,7 @@ module Irc # def to_irc_user(opts={}) return self if fits_with_server_and_casemap?(opts) - return self.fullform.to_irc_user(server_and_casemap(opts)) + return self.full_downcase.to_irc_user(opts) end # We can replace everything at once with data from another User @@ -850,6 +879,13 @@ module Irc @element_class = User end + # Convenience method: convert the UserList to a list of nicks. The indices + # are preserved + # + def nicks + self.map { |user| user.nick } + end + end end @@ -1206,6 +1242,13 @@ module Irc super(Channel, ar) end + # Convenience method: convert the ChannelList to a list of channel names. + # The indices are preserved + # + def names + self.map { |chan| chan.name } + end + end end