From b88b9614f606b1e5b61d041b20c1445014c21a59 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 8 Jul 2016 12:58:01 -0700 Subject: [PATCH] automode: join channels where automode is enabled (#264) Still a WIP: when automode is killed, it won't join any relay leaf channels. Perhaps Relay needs to learn how to queue channels for services bots when they join a remote channel, and then remove them when that channel is delinked, etc. --- plugins/automode.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/plugins/automode.py b/plugins/automode.py index c5abb09..ec4c1ac 100644 --- a/plugins/automode.py +++ b/plugins/automode.py @@ -6,7 +6,7 @@ import collections import threading import json -from pylinkirc import utils, conf +from pylinkirc import utils, conf, world from pylinkirc.log import log mydesc = ("The \x02Automode\x02 plugin provides simple channel ACL management by giving prefix modes " @@ -59,12 +59,30 @@ def scheduleExport(starting=False): def main(irc=None): """Main function, called during plugin loading at start.""" - # Load the relay links database. + # Load the automode database. loadDB() # Schedule periodic exports of the automode database. scheduleExport(starting=True) + # Queue joins to all channels where Automode has entries. + for entry in db: + netname, channel = entry.split('#', 1) + channel = '#' + channel + log.debug('automode: auto-joining %s on %s', channel, netname) + modebot.extra_channels[netname].add(channel) + + # This explicitly forces a join to connected networks (on plugin load, etc.). + mb_uid = modebot.uids.get(netname) + if netname in world.networkobjects and mb_uid in world.networkobjects[netname].users: + remoteirc = world.networkobjects[netname] + remoteirc.proto.join(mb_uid, channel) + + # Call a join hook manually so other plugins like relay can understand it. + remoteirc.callHooks([mb_uid, 'PYLINK_AUTOMODE_JOIN', {'channel': channel, 'users': [mb_uid], + 'modes': remoteirc.channels[channel].modes, + 'parse_as': 'JOIN'}]) + def die(sourceirc): """Saves the Automode database and quit.""" exportDB()