Changeset eebdc6973a6ab1089ed18c0ea02e72cd6e656120
- 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
| r2f2644f |
reebdc69 |
|
| 923 | 923 | alias :to_s :nick |
|---|
| 924 | 924 | |
|---|
| 925 | | attr_accessor :real_name |
|---|
| | 925 | attr_accessor :real_name, :idle_since, :signon |
|---|
| 926 | 926 | |
|---|
| 927 | 927 | # Create a new IRC User from a given Netmask (or anything that can be converted |
|---|
| … | … | |
| 935 | 935 | @away = false |
|---|
| 936 | 936 | @real_name = String.new |
|---|
| | 937 | @idle_since = nil |
|---|
| | 938 | @signon = nil |
|---|
| 937 | 939 | end |
|---|
| 938 | 940 | |
|---|
| r2bd4a7e |
reebdc69 |
|
| 699 | 699 | @plugins.delegate "modechange", m |
|---|
| 700 | 700 | } |
|---|
| | 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 | } |
|---|
| 701 | 707 | @client[:join] = proc {|data| |
|---|
| 702 | 708 | m = JoinMessage.new(self, server, data[:source], data[:channel], data[:message]) |
|---|
| … | … | |
| 1210 | 1216 | end |
|---|
| 1211 | 1217 | |
|---|
| | 1218 | # asking whois |
|---|
| | 1219 | def whois(nick, target=nil) |
|---|
| | 1220 | sendq "WHOIS #{target} #{nick}", nil, 0 |
|---|
| | 1221 | end |
|---|
| | 1222 | |
|---|
| 1212 | 1223 | # kicking a user |
|---|
| 1213 | 1224 | def kick(channel, user, msg) |
|---|
| r2d2e6d1 |
reebdc69 |
|
| 554 | 554 | end |
|---|
| 555 | 555 | |
|---|
| | 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 | |
|---|
| 556 | 571 | # class to manage NAME replies |
|---|
| 557 | 572 | class NamesMessage < BasicUserMessage |
|---|
| rfa4a71c |
reebdc69 |
|
| 1289 | 1289 | when RPL_ENDOFWHO |
|---|
| 1290 | 1290 | 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 |
|---|
| 1291 | 1347 | when RPL_CHANNELMODEIS |
|---|
| 1292 | 1348 | parse_mode(serverstring, argv[1..-1], data) |
|---|