3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-02-02 23:54:08 +01:00

relay: implement LINKED <netname> to filter by network

Closes #227.
This commit is contained in:
James Lu 2016-05-21 22:55:06 -07:00
parent e498a0cace
commit 03790b5939

View File

@ -1487,9 +1487,9 @@ def delink(irc, source, args):
@utils.add_cmd @utils.add_cmd
def linked(irc, source, args): def linked(irc, source, args):
"""takes no arguments. """[<network>]
Returns a list of channels shared across the relay.""" Returns a list of channels shared across the relay. If <network> is given, filters output to channels linked to the given network."""
# Only show remote networks that are marked as connected. # Only show remote networks that are marked as connected.
remote_networks = [netname for netname, ircobj in world.networkobjects.copy().items() remote_networks = [netname for netname, ircobj in world.networkobjects.copy().items()
@ -1503,9 +1503,22 @@ def linked(irc, source, args):
s = 'Connected networks: \x02%s\x02 %s' % (irc.name, ' '.join(remote_networks)) s = 'Connected networks: \x02%s\x02 %s' % (irc.name, ' '.join(remote_networks))
irc.msg(source, s) irc.msg(source, s)
net = ''
try:
net = args[0]
except:
pass
else:
irc.msg(source, "Showing channels linked to %s:" % net)
# Sort the list of shared channels when displaying # Sort the list of shared channels when displaying
for k, v in sorted(db.items()): for k, v in sorted(db.items()):
# Skip if we're filtering by network and the network given isn't relayed
# to the channel.
if net and not (net == k[0] or net in [link[0] for link in v['links']]):
continue
# Bold each network/channel name pair # Bold each network/channel name pair
s = '\x02%s%s\x02 ' % k s = '\x02%s%s\x02 ' % k
remoteirc = world.networkobjects.get(k[0]) remoteirc = world.networkobjects.get(k[0])