AutoMode: Dismiss auto-op/halfop/voice if the user already has it.

This commit is contained in:
Valentin Lorentz 2012-08-27 15:42:08 +02:00
parent 0c6320e9c1
commit 17227a6829

View File

@ -58,8 +58,14 @@ class AutoMode(callbacks.Plugin):
if self.registryValue(type, channel): if self.registryValue(type, channel):
self.log.info('Scheduling auto-%s of %s in %s.', self.log.info('Scheduling auto-%s of %s in %s.',
type, msg.prefix, channel) 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) 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. raise Continue # Even if fallthrough, let's only do one.
elif not fallthrough: elif not fallthrough:
self.log.debug('%s has %s, but supybot.plugins.AutoMode.%s' self.log.debug('%s has %s, but supybot.plugins.AutoMode.%s'
@ -68,9 +74,12 @@ class AutoMode(callbacks.Plugin):
raise Continue raise Continue
except KeyError: except KeyError:
pass pass
def schedule_msg(msg): def schedule_msg(msg, dismiss):
def f(): def f():
if not dismiss():
irc.queueMsg(msg) irc.queueMsg(msg)
else:
self.log.info('Dismissing auto-mode for ProgVal.')
delay = self.registryValue('delay', channel) delay = self.registryValue('delay', channel)
if delay: if delay:
schedule.addEvent(f, time.time() + delay) schedule.addEvent(f, time.time() + delay)