mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-20 01:19:26 +01:00
Network: Add @whowas. Closes GH-227.
This commit is contained in:
parent
6493be1f13
commit
9e1cf727e3
@ -29,6 +29,7 @@
|
|||||||
###
|
###
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
import functools
|
||||||
|
|
||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
@ -149,11 +150,12 @@ class Network(callbacks.Plugin):
|
|||||||
if (irc, nick) not in self._whois:
|
if (irc, nick) not in self._whois:
|
||||||
return
|
return
|
||||||
else:
|
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.
|
# These are all sent by a WHOIS response.
|
||||||
do301 = do311
|
do301 = do311
|
||||||
do312 = do311
|
do312 = do311
|
||||||
|
do314 = do311
|
||||||
do317 = do311
|
do317 = do311
|
||||||
do319 = do311
|
do319 = do311
|
||||||
do320 = do311
|
do320 = do311
|
||||||
@ -163,9 +165,10 @@ class Network(callbacks.Plugin):
|
|||||||
loweredNick = ircutils.toLower(nick)
|
loweredNick = ircutils.toLower(nick)
|
||||||
if (irc, loweredNick) not in self._whois:
|
if (irc, loweredNick) not in self._whois:
|
||||||
return
|
return
|
||||||
(replyIrc, replyMsg, d) = self._whois[(irc, loweredNick)]
|
(replyIrc, replyMsg, d, command) = self._whois[(irc, loweredNick)]
|
||||||
hostmask = '@'.join(d['311'].args[2:4])
|
START_CODE = '311' if command == 'whois' else '314'
|
||||||
user = d['311'].args[-1]
|
hostmask = '@'.join(d[START_CODE].args[2:4])
|
||||||
|
user = d[START_CODE].args[-1]
|
||||||
if '319' in d:
|
if '319' in d:
|
||||||
channels = d['319'].args[-1].split()
|
channels = d['319'].args[-1].split()
|
||||||
ops = []
|
ops = []
|
||||||
@ -218,7 +221,10 @@ class Network(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
L.append(format(_('is on %L'), normal))
|
L.append(format(_('is on %L'), normal))
|
||||||
else:
|
else:
|
||||||
|
if command == 'whois':
|
||||||
L = [_('isn\'t on any non-secret channels')]
|
L = [_('isn\'t on any non-secret channels')]
|
||||||
|
else:
|
||||||
|
L = []
|
||||||
channels = format('%L', L)
|
channels = format('%L', L)
|
||||||
if '317' in d:
|
if '317' in d:
|
||||||
idle = utils.timeElapsed(d['317'].args[2])
|
idle = utils.timeElapsed(d['317'].args[2])
|
||||||
@ -229,6 +235,8 @@ class Network(callbacks.Plugin):
|
|||||||
signon = _('<unknown>')
|
signon = _('<unknown>')
|
||||||
if '312' in d:
|
if '312' in d:
|
||||||
server = d['312'].args[2]
|
server = d['312'].args[2]
|
||||||
|
if len(d['312']) > 3:
|
||||||
|
signoff = d['312'].args[3]
|
||||||
else:
|
else:
|
||||||
server = _('<unknown>')
|
server = _('<unknown>')
|
||||||
if '301' in d:
|
if '301' in d:
|
||||||
@ -242,22 +250,33 @@ class Network(callbacks.Plugin):
|
|||||||
identify = ''
|
identify = ''
|
||||||
else:
|
else:
|
||||||
identify = ''
|
identify = ''
|
||||||
|
if command == 'whois':
|
||||||
s = _('%s (%s) has been%s on server %s since %s (idle for %s) and '
|
s = _('%s (%s) has been%s on server %s since %s (idle for %s) and '
|
||||||
'%s.%s') % (user, hostmask, identify, server, signon, idle,
|
'%s.%s').decode('utf8') % (user, hostmask, identify, server,
|
||||||
channels, away)
|
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)
|
replyIrc.reply(s)
|
||||||
del self._whois[(irc, loweredNick)]
|
del self._whois[(irc, loweredNick)]
|
||||||
|
do369 = do318
|
||||||
|
|
||||||
def do402(self, irc, msg):
|
def do402(self, irc, msg):
|
||||||
nick = msg.args[1]
|
nick = msg.args[1]
|
||||||
loweredNick = ircutils.toLower(nick)
|
loweredNick = ircutils.toLower(nick)
|
||||||
if (irc, loweredNick) not in self._whois:
|
if (irc, loweredNick) not in self._whois:
|
||||||
return
|
return
|
||||||
(replyIrc, replyMsg, d) = self._whois[(irc, loweredNick)]
|
(replyIrc, replyMsg, d, command) = self._whois[(irc, loweredNick)]
|
||||||
del 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)
|
replyIrc.reply(s)
|
||||||
do401 = do402
|
do401 = do402
|
||||||
|
do406 = do402
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def whois(self, irc, msg, args, otherIrc, nick):
|
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.
|
# giving the command. Yeah, it made me say wtf too.
|
||||||
nick = ircutils.toLower(nick)
|
nick = ircutils.toLower(nick)
|
||||||
otherIrc.queueMsg(ircmsgs.whois(nick, 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'])
|
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
|
@internationalizeDocstring
|
||||||
def networks(self, irc, msg, args):
|
def networks(self, irc, msg, args):
|
||||||
"""takes no arguments
|
"""takes no arguments
|
||||||
|
@ -38,6 +38,7 @@ object (which, as you'll read later, is quite...full-featured :))
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import functools
|
||||||
|
|
||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
@ -737,7 +738,7 @@ def who(hostmaskOrChannel, prefix='', msg=None):
|
|||||||
return IrcMsg(prefix=prefix, command='WHO',
|
return IrcMsg(prefix=prefix, command='WHO',
|
||||||
args=(hostmaskOrChannel,), msg=msg)
|
args=(hostmaskOrChannel,), msg=msg)
|
||||||
|
|
||||||
def whois(nick, mask='', prefix='', msg=None):
|
def _whois(COMMAND, nick, mask='', prefix='', msg=None):
|
||||||
"""Returns a WHOIS for nick."""
|
"""Returns a WHOIS for nick."""
|
||||||
if conf.supybot.protocols.irc.strictRfc():
|
if conf.supybot.protocols.irc.strictRfc():
|
||||||
assert areNicks(nick), repr(nick)
|
assert areNicks(nick), repr(nick)
|
||||||
@ -746,7 +747,9 @@ def whois(nick, mask='', prefix='', msg=None):
|
|||||||
args = (nick,)
|
args = (nick,)
|
||||||
if mask:
|
if mask:
|
||||||
args = (nick, 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):
|
def names(channel=None, prefix='', msg=None):
|
||||||
if conf.supybot.protocols.irc.strictRfc():
|
if conf.supybot.protocols.irc.strictRfc():
|
||||||
|
Loading…
Reference in New Issue
Block a user