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

automode: also rejoin DB channels on reload

This commit is contained in:
James Lu 2018-05-05 21:10:08 -07:00
parent bf4863eb6d
commit 8aa67b93fa

View File

@ -26,6 +26,20 @@ db = datastore.store
default_permissions = {"$ircop": ['automode.manage.relay_owned', 'automode.sync.relay_owned',
'automode.list']}
def _join_db_channels(irc):
"""
Joins the Automode service client to channels on the current network in its DB.
"""
if not irc.connected.is_set():
log.debug('(%s) _join_db_channels: aborting, network not ready yet', irc.name)
return
for entry in db:
netname, channel = entry.split('#', 1)
channel = '#' + channel
if netname == irc.name:
modebot.add_persistent_channel(irc, 'automode', channel)
def main(irc=None):
"""Main function, called during plugin loading at start."""
@ -35,6 +49,10 @@ def main(irc=None):
# Register our permissions.
permissions.add_default_permissions(default_permissions)
if irc: # After initial startup
for ircobj in world.networkobjects.values():
_join_db_channels(ircobj)
def die(irc=None):
"""Saves the Automode database and quit."""
datastore.die()
@ -115,15 +133,8 @@ def match(irc, channel, uids=None):
def handle_endburst(irc, source, command, args):
"""ENDBURST hook handler - used to join the Automode service to channels where it has entries."""
if source != irc.uplink:
return
for entry in db:
netname, channel = entry.split('#', 1)
channel = '#' + channel
if netname == irc.name:
modebot.add_persistent_channel(irc, 'automode', channel)
if source == irc.uplink:
_join_db_channels(irc)
utils.add_hook(handle_endburst, 'ENDBURST')
def handle_join(irc, source, command, args):