Changeset eebdc6973a6ab1089ed18c0ea02e72cd6e656120

Show
Ignore:
Timestamp:
08/10/08 03:47:13 (3 months ago)
Author:
Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
git-committer:
Giuseppe Bilotta <giuseppe.bilotta@gmail.com> 1218325633 +0200
git-parent:

[fa4a71c43227669b42b4b1c0a68be796091f3d1d]

git-author:
Giuseppe Bilotta <giuseppe.bilotta@gmail.com> 1218325412 +0200
Message:

+ handle WHOIS queries

The bot now exposes a whois(nick) method to make WHOIS queries to the
server. The extended syntax whois(nick, server) is also supported,
allowing another server to be queried (this is useful to retrieve info
which is only available on nick's server, such as idle time and signon
date).

Most if not all RFC-compliant replies are handled, although some of the
data received is currently ignored. Non-RFC extended replies such as
nickserv identification status are not hanlded yet, since they are
highly server-specific, both in numeric reply choice (e.g. 307 vs 320)
and in reply message syntax and meaning.

A new WhoisMessage? is also introduced, for plugin delegation. The source
is the originating server, the target is the user for which information
was requested. A #whois() method is provided holding all retrieved
information.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lib/rbot/irc.rb

    r2f2644f reebdc69  
    923923    alias :to_s :nick 
    924924 
    925     attr_accessor :real_name 
     925    attr_accessor :real_name, :idle_since, :signon 
    926926 
    927927    # Create a new IRC User from a given Netmask (or anything that can be converted 
     
    935935      @away = false 
    936936      @real_name = String.new 
     937      @idle_since = nil 
     938      @signon = nil 
    937939    end 
    938940 
  • lib/rbot/ircbot.rb

    r2bd4a7e reebdc69  
    699699      @plugins.delegate "modechange", m 
    700700    } 
     701    @client[:whois] = proc {|data| 
     702      source = data[:source] 
     703      target = server.get_user(data[:whois][:nick]) 
     704      m = WhoisMessage.new(self, server, source, target, data[:whois]) 
     705      @plugins.delegate "whois", m 
     706    } 
    701707    @client[:join] = proc {|data| 
    702708      m = JoinMessage.new(self, server, data[:source], data[:channel], data[:message]) 
     
    12101216  end 
    12111217 
     1218  # asking whois 
     1219  def whois(nick, target=nil) 
     1220    sendq "WHOIS #{target} #{nick}", nil, 0 
     1221  end 
     1222 
    12121223  # kicking a user 
    12131224  def kick(channel, user, msg) 
  • lib/rbot/message.rb

    r2d2e6d1 reebdc69  
    554554  end 
    555555 
     556  # class to manage WHOIS replies 
     557  class WhoisMessage < BasicUserMessage 
     558    attr_reader :whois 
     559    def initialize(bot, server, source, target, whois) 
     560      super(bot, server, source, target, "") 
     561      @address = (target == @bot.myself) 
     562      @whois = whois 
     563    end 
     564 
     565    def inspect 
     566      fields = ' whois=' << whois.inspect 
     567      super(fields) 
     568    end 
     569  end 
     570 
    556571  # class to manage NAME replies 
    557572  class NamesMessage < BasicUserMessage 
  • lib/rbot/rfc2812.rb

    rfa4a71c reebdc69  
    12891289        when RPL_ENDOFWHO 
    12901290          handle(:eowho, data) 
     1291        when RPL_WHOISUSER 
     1292          @whois ||= Hash.new 
     1293          @whois[:nick] = argv[1] 
     1294          @whois[:user] = argv[2] 
     1295          @whois[:host] = argv[3] 
     1296          @whois[:real_name] = argv[-1] 
     1297 
     1298          user = @server.get_user(@whois[:nick]) 
     1299          user.user = @whois[:user] 
     1300          user.host = @whois[:host] 
     1301          user.real_name = @whois[:real_name] 
     1302        when RPL_WHOISSERVER 
     1303          @whois ||= Hash.new 
     1304          @whois[:nick] = argv[1] 
     1305          @whois[:server] = argv[2] 
     1306          @whois[:server_info] = argv[-1] 
     1307          # TODO update user info 
     1308        when RPL_WHOISOPERATOR 
     1309          @whois ||= Hash.new 
     1310          @whois[:nick] = argv[1] 
     1311          @whois[:operator] = argv[-1] 
     1312          # TODO update user info 
     1313        when RPL_WHOISIDLE 
     1314          @whois ||= Hash.new 
     1315          @whois[:nick] = argv[1] 
     1316          user = @server.get_user(@whois[:nick]) 
     1317          @whois[:idle] = argv[2].to_i 
     1318          user.idle_since = Time.now - @whois[:idle] 
     1319          if argv[-1] == 'seconds idle, signon time' 
     1320            @whois[:signon] = Time.at(argv[3].to_i) 
     1321            user.signon = @whois[:signon] 
     1322          end 
     1323        when RPL_ENDOFWHOIS 
     1324          @whois ||= Hash.new 
     1325          @whois[:nick] = argv[1] 
     1326          data[:whois] = @whois.dup 
     1327          @whois.clear 
     1328          handle(:whois, data) 
     1329        when RPL_WHOISCHANNELS 
     1330          @whois ||= Hash.new 
     1331          @whois[:nick] = argv[1] 
     1332          @whois[:channels] = [] 
     1333          user = @server.get_user(@whois[:nick]) 
     1334          argv[-1].split.each do |prechan| 
     1335            pfx = prechan.scan(/[#{@server.supports[:prefix][:prefixes].join}]/) 
     1336            modes = pfx.map { |p| @server.mode_for_prefix p } 
     1337            chan = prechan[pfx.length..prechan.length] 
     1338 
     1339            channel = @server.get_channel(chan) 
     1340            if channel 
     1341              channel.add_user(user, :silent => true) 
     1342              modes.map { |mode| channel.mode[mode].set(user) } 
     1343            end 
     1344 
     1345            @whois[:channels] << [chan, modes] 
     1346          end 
    12911347        when RPL_CHANNELMODEIS 
    12921348          parse_mode(serverstring, argv[1..-1], data)