Network: Add @whowas. Closes GH-227.

This commit is contained in:
Valentin Lorentz 2013-05-18 14:46:58 +02:00
parent 6493be1f13
commit 9e1cf727e3
2 changed files with 51 additions and 13 deletions

View File

@ -29,6 +29,7 @@
###
import time
import functools
import supybot.conf as conf
import supybot.utils as utils
@ -149,11 +150,12 @@ class Network(callbacks.Plugin):
if (irc, nick) not in self._whois:
return
else:
self._whois[(irc, nick)][-1][msg.command] = msg
self._whois[(irc, nick)][2][msg.command] = msg
# These are all sent by a WHOIS response.
do301 = do311
do312 = do311
do314 = do311
do317 = do311
do319 = do311
do320 = do311
@ -163,9 +165,10 @@ class Network(callbacks.Plugin):
loweredNick = ircutils.toLower(nick)
if (irc, loweredNick) not in self._whois:
return
(replyIrc, replyMsg, d) = self._whois[(irc, loweredNick)]
hostmask = '@'.join(d['311'].args[2:4])
user = d['311'].args[-1]
(replyIrc, replyMsg, d, command) = self._whois[(irc, loweredNick)]
START_CODE = '311' if command == 'whois' else '314'
hostmask = '@'.join(d[START_CODE].args[2:4])
user = d[START_CODE].args[-1]
if '319' in d:
channels = d['319'].args[-1].split()
ops = []
@ -218,7 +221,10 @@ class Network(callbacks.Plugin):
else:
L.append(format(_('is on %L'), normal))
else:
L = [_('isn\'t on any non-secret channels')]
if command == 'whois':
L = [_('isn\'t on any non-secret channels')]
else:
L = []
channels = format('%L', L)
if '317' in d:
idle = utils.timeElapsed(d['317'].args[2])
@ -229,6 +235,8 @@ class Network(callbacks.Plugin):
signon = _('<unknown>')
if '312' in d:
server = d['312'].args[2]
if len(d['312']) > 3:
signoff = d['312'].args[3]
else:
server = _('<unknown>')
if '301' in d:
@ -242,22 +250,33 @@ class Network(callbacks.Plugin):
identify = ''
else:
identify = ''
s = _('%s (%s) has been%s on server %s since %s (idle for %s) and '
'%s.%s') % (user, hostmask, identify, server, signon, idle,
channels, away)
if command == 'whois':
s = _('%s (%s) has been%s on server %s since %s (idle for %s) and '
'%s.%s').decode('utf8') % (user, hostmask, identify, server,
signon, idle, channels, away)
else:
s = _('%s (%s) has been%s on server %s and disconnect on %s.') \
.decode('utf8') % \
(user, hostmask, identify, server, signoff)
replyIrc.reply(s)
del self._whois[(irc, loweredNick)]
do369 = do318
def do402(self, irc, msg):
nick = msg.args[1]
loweredNick = ircutils.toLower(nick)
if (irc, loweredNick) not in self._whois:
return
(replyIrc, replyMsg, d) = self._whois[(irc, loweredNick)]
(replyIrc, replyMsg, d, command) = self._whois[(irc, loweredNick)]
del self._whois[(irc, loweredNick)]
s = _('There is no %s on %s.') % (nick, irc.network)
if command == 'whois':
template = _('There is no %s on %s.')
else:
template = _('There was no %s on %s.')
s = template % (nick, irc.network)
replyIrc.reply(s)
do401 = do402
do406 = do402
@internationalizeDocstring
def whois(self, irc, msg, args, otherIrc, nick):
@ -272,9 +291,25 @@ class Network(callbacks.Plugin):
# giving the command. Yeah, it made me say wtf too.
nick = ircutils.toLower(nick)
otherIrc.queueMsg(ircmsgs.whois(nick, nick))
self._whois[(otherIrc, nick)] = (irc, msg, {})
self._whois[(otherIrc, nick)] = (irc, msg, {}, 'whois')
whois = wrap(whois, ['networkIrc', 'nick'])
@internationalizeDocstring
def whowas(self, irc, msg, args, otherIrc, nick):
"""[<network>] <nick>
Returns the WHOIS response <network> gives for <nick>. <network> is
only necessary if the network is different than the network the command
is sent on.
"""
# The double nick here is necessary because single-nick WHOIS only works
# if the nick is on the same server (*not* the same network) as the user
# giving the command. Yeah, it made me say wtf too.
nick = ircutils.toLower(nick)
otherIrc.queueMsg(ircmsgs.whowas(nick, nick))
self._whois[(otherIrc, nick)] = (irc, msg, {}, 'whowas')
whowas = wrap(whowas, ['networkIrc', 'nick'])
@internationalizeDocstring
def networks(self, irc, msg, args):
"""takes no arguments

View File

@ -38,6 +38,7 @@ object (which, as you'll read later, is quite...full-featured :))
import re
import sys
import time
import functools
import supybot.conf as conf
import supybot.utils as utils
@ -737,7 +738,7 @@ def who(hostmaskOrChannel, prefix='', msg=None):
return IrcMsg(prefix=prefix, command='WHO',
args=(hostmaskOrChannel,), msg=msg)
def whois(nick, mask='', prefix='', msg=None):
def _whois(COMMAND, nick, mask='', prefix='', msg=None):
"""Returns a WHOIS for nick."""
if conf.supybot.protocols.irc.strictRfc():
assert areNicks(nick), repr(nick)
@ -746,7 +747,9 @@ def whois(nick, mask='', prefix='', msg=None):
args = (nick,)
if mask:
args = (nick, mask)
return IrcMsg(prefix=prefix, command='WHOIS', args=args, msg=msg)
return IrcMsg(prefix=prefix, command=COMMAND, args=args, msg=msg)
whois = functools.partial(_whois, 'WHOIS')
whowas = functools.partial(_whois, 'WHOWAS')
def names(channel=None, prefix='', msg=None):
if conf.supybot.protocols.irc.strictRfc():