From 17227a68298f3b9f93502db90c6d6e1ad11f80ce Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 27 Aug 2012 15:42:08 +0200 Subject: [PATCH] AutoMode: Dismiss auto-op/halfop/voice if the user already has it. --- plugins/AutoMode/plugin.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/AutoMode/plugin.py b/plugins/AutoMode/plugin.py index e2c0c1650..d527f4c1d 100644 --- a/plugins/AutoMode/plugin.py +++ b/plugins/AutoMode/plugin.py @@ -58,8 +58,14 @@ class AutoMode(callbacks.Plugin): if self.registryValue(type, channel): self.log.info('Scheduling auto-%s of %s in %s.', type, msg.prefix, channel) + def dismiss(): + """Determines whether or not a mode has already + been applied.""" + l = getattr(irc.state.channels[channel], type+'s') + return (msg.nick in l) msgmaker = getattr(ircmsgs, type) - schedule_msg(msgmaker(channel, msg.nick)) + schedule_msg(msgmaker(channel, msg.nick), + dismiss) raise Continue # Even if fallthrough, let's only do one. elif not fallthrough: self.log.debug('%s has %s, but supybot.plugins.AutoMode.%s' @@ -68,9 +74,12 @@ class AutoMode(callbacks.Plugin): raise Continue except KeyError: pass - def schedule_msg(msg): + def schedule_msg(msg, dismiss): def f(): - irc.queueMsg(msg) + if not dismiss(): + irc.queueMsg(msg) + else: + self.log.info('Dismissing auto-mode for ProgVal.') delay = self.registryValue('delay', channel) if delay: schedule.addEvent(f, time.time() + delay)