From 8aa67b93fa99d4b0996c72982adbeed29322a500 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 5 May 2018 21:10:08 -0700 Subject: [PATCH] automode: also rejoin DB channels on reload --- plugins/automode.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/plugins/automode.py b/plugins/automode.py index d1d329c..1a69c44 100644 --- a/plugins/automode.py +++ b/plugins/automode.py @@ -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):