3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 13:09:23 +01:00

commands: rework showuser to better handle duplicate nicks

This is freely allowed on Discord, for example.
This commit is contained in:
James Lu 2019-06-16 11:14:33 -07:00
parent fc4a16eda1
commit fe95a4a571

View File

@ -32,20 +32,8 @@ def status(irc, source, args):
irc.reply('Operator access: \x02%s\x02' % bool(irc.is_oper(source))) irc.reply('Operator access: \x02%s\x02' % bool(irc.is_oper(source)))
_none = '\x1D(none)\x1D' _none = '\x1D(none)\x1D'
@utils.add_cmd def _do_showuser(irc, source, u):
def showuser(irc, source, args): """Helper function for showuser."""
"""<user>
Shows information about <user>."""
permissions.check_permissions(irc, source, ['commands.showuser'])
try:
target = args[0]
except IndexError:
irc.error("Not enough arguments. Needs 1: nick.")
return
u = irc.nick_to_uid(target) or target
# Some protocol modules store UIDs as ints; make sure we check for that. # Some protocol modules store UIDs as ints; make sure we check for that.
try: try:
int_u = int(u) int_u = int(u)
@ -60,7 +48,7 @@ def showuser(irc, source, args):
verbose = irc.is_oper(source) or u == source verbose = irc.is_oper(source) or u == source
if u not in irc.users: if u not in irc.users:
irc.error('Unknown user %r.' % target) irc.error('Unknown user %r.' % u)
return return
f = lambda s: irc.reply(s, private=True) f = lambda s: irc.reply(s, private=True)
@ -89,6 +77,22 @@ def showuser(irc, source, args):
f('\x02PyLink identification\x02: %s; \x02Services account\x02: %s; \x02Away status\x02: %s' % \ f('\x02PyLink identification\x02: %s; \x02Services account\x02: %s; \x02Away status\x02: %s' % \
((userobj.account or _none), (userobj.services_account or _none), userobj.away or _none)) ((userobj.account or _none), (userobj.services_account or _none), userobj.away or _none))
@utils.add_cmd
def showuser(irc, source, args):
"""<user>
Shows information about <user>."""
permissions.check_permissions(irc, source, ['commands.showuser'])
try:
target = args[0]
except IndexError:
irc.error("Not enough arguments. Needs 1: nick.")
return
users = irc.nick_to_uid(target, multi=True) or [target]
for user in users:
_do_showuser(irc, source, user)
@utils.add_cmd @utils.add_cmd
def showchan(irc, source, args): def showchan(irc, source, args):