mirror of
https://github.com/jlu5/PyLink.git
synced 2025-02-25 01:40:38 +01:00
relay: remove service bots joined persistently when the home network disconnects
This commit is contained in:
parent
aa4cedd945
commit
fc275cfdca
@ -1988,20 +1988,35 @@ def handle_disconnect(irc, numeric, command, args):
|
|||||||
# Announce the disconnects to every leaf channel where the disconnected network is the owner
|
# Announce the disconnects to every leaf channel where the disconnected network is the owner
|
||||||
announcement = conf.conf.get('relay', {}).get('disconnect_announcement')
|
announcement = conf.conf.get('relay', {}).get('disconnect_announcement')
|
||||||
log.debug('(%s) relay: last connection successful: %s', irc.name, args.get('was_successful'))
|
log.debug('(%s) relay: last connection successful: %s', irc.name, args.get('was_successful'))
|
||||||
if announcement and args.get('was_successful'):
|
if args.get('was_successful'):
|
||||||
for chanpair, entrydata in db.items():
|
for chanpair, entrydata in db.items():
|
||||||
log.debug('(%s) relay: Looking up %s', irc.name, chanpair)
|
|
||||||
if chanpair[0] == irc.name:
|
if chanpair[0] == irc.name:
|
||||||
for leaf in entrydata['links']:
|
for leaf in entrydata['links']:
|
||||||
log.debug('(%s) relay: Announcing disconnect to %s%s', irc.name,
|
|
||||||
leaf[0], leaf[1])
|
|
||||||
remoteirc = world.networkobjects.get(leaf[0])
|
remoteirc = world.networkobjects.get(leaf[0])
|
||||||
if remoteirc and remoteirc.connected.is_set():
|
if remoteirc and remoteirc.connected.is_set():
|
||||||
text = string.Template(announcement).safe_substitute(
|
if announcement:
|
||||||
{'homenetwork': irc.name, 'homechannel': chanpair[1],
|
log.debug('(%s) relay: Announcing disconnect to %s%s', irc.name,
|
||||||
|
leaf[0], leaf[1])
|
||||||
|
text = string.Template(announcement).safe_substitute({
|
||||||
|
'homenetwork': irc.name, 'homechannel': chanpair[1],
|
||||||
'network': remoteirc.name, 'channel': leaf[1]})
|
'network': remoteirc.name, 'channel': leaf[1]})
|
||||||
remoteirc.msg(leaf[1], text, loopback=False)
|
remoteirc.msg(leaf[1], text, loopback=False)
|
||||||
|
|
||||||
|
# Also remove any services bots that joined because of relay.
|
||||||
|
for sname, sbot in world.services.items():
|
||||||
|
if sname == 'pylink':
|
||||||
|
# We always keep the relay service on the channel
|
||||||
|
# for consistency.
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
sbot.remove_persistent_channel(remoteirc, 'relay', leaf[1],
|
||||||
|
part_reason=CHANNEL_DELINKED_PARTMSG)
|
||||||
|
except KeyError:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
log.debug('(%s) Removed service %r from %s%s as the home network disconnected',
|
||||||
|
irc.name, sname, leaf[0], leaf[1])
|
||||||
|
|
||||||
utils.add_hook(handle_disconnect, "PYLINK_DISCONNECT")
|
utils.add_hook(handle_disconnect, "PYLINK_DISCONNECT")
|
||||||
|
|
||||||
def nick_collide(irc, target):
|
def nick_collide(irc, target):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user