From f3107a928f0459aa477a06ca72da2c659cccd68c Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 27 Feb 2015 18:45:37 -0800 Subject: [PATCH] Channel: allow adding an auto-rejoin delay via supybot.plugins.Channel.rejoinDelay Closes #1011. --- plugins/Channel/config.py | 5 ++++- plugins/Channel/plugin.py | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/plugins/Channel/config.py b/plugins/Channel/config.py index 19f7462be..8d57a5f13 100644 --- a/plugins/Channel/config.py +++ b/plugins/Channel/config.py @@ -51,6 +51,9 @@ conf.registerChannelValue(Channel, 'nicksInPrivate', registry.Boolean(True, _("""Determines whether the output of 'nicks' will be sent in private. This prevents mass-highlights of a channel's users, accidental or on purpose."""))) - +conf.registerChannelValue(Channel, 'rejoinDelay', + registry.NonNegativeInteger(0, _("""Determines how many seconds the bot will wait + before rejoining a channel if kicked and + supybot.plugins.Channel.alwaysRejoin is on."""))) # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/plugins/Channel/plugin.py b/plugins/Channel/plugin.py index 75834daa2..1f170362e 100644 --- a/plugins/Channel/plugin.py +++ b/plugins/Channel/plugin.py @@ -30,6 +30,7 @@ import sys import fnmatch +import time import supybot.conf as conf import supybot.ircdb as ircdb @@ -46,6 +47,7 @@ class Channel(callbacks.Plugin): """This plugin provides various commands for channel management, such as setting modes and channel-wide bans/ignores/capabilities. This is a core Supybot plugin that should not be removed!""" + def __init__(self, irc): self.__parent = super(Channel, self) self.__parent.__init__(irc) @@ -55,10 +57,18 @@ class Channel(callbacks.Plugin): channel = msg.args[0] if msg.args[1] == irc.nick: if self.registryValue('alwaysRejoin', channel): - self.log.info('Kicked from %s by %s. Rejoining.' % - (channel, msg.prefix)) + delay = self.registryValue('rejoinDelay', channel) networkGroup = conf.supybot.networks.get(irc.network) - irc.sendMsg(networkGroup.channels.join(channel)) + if delay: + def f(): + irc.sendMsg(networkGroup.channels.join(channel)) + schedule.addEvent(f, time.time() + delay) + self.log.info('Kicked from %s by %s. Rejoining after %s ' + 'seconds.', channel, msg.prefix, delay) + else: + self.log.info('Kicked from %s by %s. Rejoining.', + channel, msg.prefix) + irc.sendMsg(networkGroup.channels.join(channel)) else: self.log.info('Kicked from %s by %s. Not auto-rejoining.' % (channel, msg.prefix))