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

Merge relay showchan/showuser info into commands.py

This makes error handling easier and is needed to support duplicate nicks anyways.
This commit is contained in:
James Lu 2019-06-16 11:22:09 -07:00
parent dfc4e4954a
commit 0836845ff9
2 changed files with 38 additions and 67 deletions

View File

@ -77,6 +77,35 @@ def _do_showuser(irc, source, u):
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))
# Show relay user data if available
relay = world.plugins.get('relay')
if relay:
try:
userpair = relay.get_orig_user(irc, u) or (irc.name, u)
remoteusers = relay.relayusers[userpair].items()
except KeyError:
pass
else:
nicks = []
if remoteusers:
# Display all of the user's relay subclients, if there are any
nicks.append('%s:\x02%s\x02' % (userpair[0],
world.networkobjects[userpair[0]].users[userpair[1]].nick))
for r in remoteusers:
remotenet, remoteuser = r
remoteirc = world.networkobjects[remotenet]
nicks.append('%s:\x02%s\x02' % (remotenet, remoteirc.users[remoteuser].nick))
irc.reply("\x02Relay nicks\x02: %s" % ', '.join(nicks), private=True)
if verbose:
# Show the relay channels the user is in, if applicable
relaychannels = []
for ch in irc.users[u].channels:
relayentry = relay.get_relay(irc, ch)
if relayentry:
relaychannels.append(''.join(relayentry))
if relaychannels and verbose:
irc.reply("\x02Relay channels\x02: %s" % ' '.join(relaychannels), private=True)
@utils.add_cmd @utils.add_cmd
def showuser(irc, source, args): def showuser(irc, source, args):
"""<user> """<user>
@ -147,6 +176,15 @@ def showchan(irc, source, args):
f('\x02User list\x02: %s' % ' '.join(nicklist)) f('\x02User list\x02: %s' % ' '.join(nicklist))
# Show relay info, if applicable
relay = world.plugins.get('relay')
if relay:
relayentry = relay.get_relay(irc, channel)
if relayentry:
relays = ['\x02%s\x02' % ''.join(relayentry)]
relays += [''.join(link) for link in relay.db[relayentry]['links']]
f('\x02Relayed channels:\x02 %s' % (' '.join(relays)))
@utils.add_cmd @utils.add_cmd
def version(irc, source, args): def version(irc, source, args):
"""takes no arguments. """takes no arguments.

View File

@ -2709,73 +2709,6 @@ def linkacl(irc, source, args):
else: else:
irc.error('Unknown subcommand %r: valid ones are ALLOW, DENY, and LIST.' % cmd) irc.error('Unknown subcommand %r: valid ones are ALLOW, DENY, and LIST.' % cmd)
@utils.add_cmd
def showuser(irc, source, args):
"""<user>
Shows relay data about the given user. This supplements the 'showuser' command in the 'commands' plugin, which provides more general information."""
try:
target = args[0]
except IndexError:
# No errors here; showuser from the commands plugin already does this
# for us.
return
u = irc.nick_to_uid(target)
if u:
irc.reply("Showing relay information on user \x02%s\x02:" % irc.users[u].nick, private=True)
try:
userpair = get_orig_user(irc, u) or (irc.name, u)
remoteusers = relayusers[userpair].items()
except KeyError:
pass
else:
nicks = []
if remoteusers:
nicks.append('%s:\x02%s\x02' % (userpair[0],
world.networkobjects[userpair[0]].users[userpair[1]].nick))
for r in remoteusers:
remotenet, remoteuser = r
remoteirc = world.networkobjects[remotenet]
nicks.append('%s:\x02%s\x02' % (remotenet, remoteirc.users[remoteuser].nick))
irc.reply("\x02Relay nicks\x02: %s" % ', '.join(nicks), private=True)
relaychannels = []
for ch in irc.users[u].channels:
relay = get_relay(irc, ch)
if relay:
relaychannels.append(''.join(relay))
if relaychannels and (irc.is_oper(source) or u == source):
irc.reply("\x02Relay channels\x02: %s" % ' '.join(relaychannels), private=True)
@utils.add_cmd
def showchan(irc, source, args):
"""<user>
Shows relay data about the given channel. This supplements the 'showchan' command in the 'commands' plugin, which provides more general information."""
try:
channel = irc.to_lower(args[0])
except IndexError:
return
if channel not in irc.channels:
return
f = lambda s: irc.reply(s, private=True)
c = irc.channels[channel]
# Only show verbose info if caller is oper or is in the target channel.
verbose = source in c.users or irc.is_oper(source)
secret = ('s', None) in c.modes
if secret and not verbose:
# Hide secret channels from normal users.
return
else:
relayentry = get_relay(irc, channel)
if relayentry:
relays = ['\x02%s\x02' % ''.join(relayentry)]
relays += [''.join(link) for link in db[relayentry]['links']]
f('\x02Relayed channels:\x02 %s' % (' '.join(relays)))
@utils.add_cmd @utils.add_cmd
def save(irc, source, args): def save(irc, source, args):
"""takes no arguments. """takes no arguments.