From 76554dccd19134829777f07c452ab5773826fa84 Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 12 Jul 2016 21:53:15 -0700 Subject: [PATCH] automode: refactor to send only one MODE per channel (#275) --- plugins/automode.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/plugins/automode.py b/plugins/automode.py index bbe7f5b..e766c18 100644 --- a/plugins/automode.py +++ b/plugins/automode.py @@ -204,7 +204,7 @@ def save(irc, source, args): reply(irc, 'Done.') modebot.add_cmd(save) -def match(irc, channel, uid): +def match(irc, channel, uid=None): """ Automode matcher engine. """ @@ -216,17 +216,22 @@ def match(irc, channel, uid): # Check every mask defined in the channel ACL. outgoing_modes = [] - for mask, modes in dbentry.items(): - if irc.matchHost(mask, uid): - # User matched a mask. Filter the mode list given to only those that are valid - # prefix mode characters. - outgoing_modes += [('+'+mode, uid) for mode in modes if mode in irc.prefixmodes] - log.debug("(%s) automode: Filtered mode list of %s to %s (protocol:%s)", - irc.name, modes, outgoing_modes, irc.protoname) - # If the Automode bot is missing, send the mode through the PyLink server. - if modebot_uid not in irc.users: - modebot_uid = irc.sid + # If a UID is given, match that. Otherwise, match all users in the given channel. + uids = [uid] if uid else irc.channels[channel].users + + for mask, modes in dbentry.items(): + for uid in uids: + if irc.matchHost(mask, uid): + # User matched a mask. Filter the mode list given to only those that are valid + # prefix mode characters. + outgoing_modes += [('+'+mode, uid) for mode in modes if mode in irc.prefixmodes] + log.debug("(%s) automode: Filtered mode list of %s to %s (protocol:%s)", + irc.name, modes, outgoing_modes, irc.protoname) + + # If the Automode bot is missing, send the mode through the PyLink server. + if modebot_uid not in irc.users: + modebot_uid = irc.sid irc.proto.mode(modebot_uid, channel, outgoing_modes) @@ -245,8 +250,7 @@ def syncacc(irc, source, args): reply(irc, "Error: Invalid arguments given. Needs 1: channel.") return - for user in irc.channels[channel].users: - match(irc, channel, user) + match(irc, channel) reply(irc, 'Done.') @@ -284,10 +288,8 @@ def handle_join(irc, source, command, args): ACL. """ channel = irc.toLower(args['channel']) + match(irc, channel, source) - # Iterate over all the joining UIDs: - for uid in args['users']: - match(irc, channel, uid) utils.add_hook(handle_join, 'JOIN') utils.add_hook(handle_join, 'PYLINK_RELAY_JOIN') # Handle the relay version of join utils.add_hook(handle_join, 'PYLINK_SERVICE_JOIN') # And the version for service bots