From a6583efc83ef1a00b7a82cb3b1346ed545408f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eli=C3=A1n=20Hanisch?= Date: Sat, 16 Oct 2010 01:20:53 -0300 Subject: [PATCH] If a user is removed with a reason that includes a factoid, show the factoid in private. (LP: #210769) --- Encyclopedia/config.py | 3 +++ Encyclopedia/plugin.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Encyclopedia/config.py b/Encyclopedia/config.py index b68b1b0..12e8b64 100644 --- a/Encyclopedia/config.py +++ b/Encyclopedia/config.py @@ -179,6 +179,9 @@ conf.registerChannelValue(Encyclopedia, 'ignores', conf.registerChannelValue(Encyclopedia, 'privateNotFound', registry.Boolean(False, "If set to True, send notfoundmsg in private rather than in the channel")) +conf.registerChannelValue(Encyclopedia, 'forcedFactoid', + registry.Boolean(False, "If True, factoids in kick's reason will be sent to the user in private")) + conf.registerGlobalValue(Encyclopedia, 'curStable', registry.String('Lucid', "Current stable release")) diff --git a/Encyclopedia/plugin.py b/Encyclopedia/plugin.py index cd79c63..e22f820 100644 --- a/Encyclopedia/plugin.py +++ b/Encyclopedia/plugin.py @@ -544,6 +544,39 @@ class Encyclopedia(callbacks.Plugin): for r in ret[1:]: queue(irc, target, r) + def doPart(self, irc, msg): + if not msg.args[1].startswith('requested by'): + return + + #self.log.debug('msg: %s', msg.args) + channel, reason = msg.args + reason = reason[reason.find('(')+1:-1] # get the text between () + self._forcedFactoid(irc, channel, msg.nick, reason) + + def doKick(self, irc, msg): + #self.log.debug('msg: %s', msg.args) + channel, nick, reason = msg.args + self._forcedFactoid(irc, channel, nick, reason) + + def _forcedFactoid(self, irc, channel, nick, reason): + if not self.registryValue('forcedFactoid', channel): + return + + prefix = self.registryValue('prefixchar', channel) + if prefix not in reason: + # no factoid in reason + return + + # get the factoid name, only the first if more than one. + factoid = reason[reason.find(prefix):].split()[0].strip(prefix) + L = self.factoid_lookup(factoid, channel, False) + if not L: + return + + s = L[0] + msg = ircmsgs.privmsg(nick, s) + irc.queueMsg(msg) + def factoid_edit(self, text, channel, editor): db = self.get_db(channel) cs = db.cursor()