From cd025be24ac14dc74b6019b9e7126e3768c3fd01 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 26 Oct 2010 08:46:10 +0200 Subject: [PATCH] MegaHAL: Don't learn private messages. Issue S-fr#3 --- plugins/MegaHAL/plugin.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/MegaHAL/plugin.py b/plugins/MegaHAL/plugin.py index dd97011b3..cd77849ae 100644 --- a/plugins/MegaHAL/plugin.py +++ b/plugins/MegaHAL/plugin.py @@ -33,7 +33,6 @@ import os import sys import random import supybot.conf as conf -import mh_python as megahal import supybot.utils as utils from cStringIO import StringIO from supybot.commands import * @@ -41,6 +40,14 @@ import supybot.plugins as plugins import supybot.ircutils as ircutils import supybot.callbacks as callbacks +try: + import mh_python as megahal +except ImportError: + raise callbacks.Error, 'You need to have MegaHAL installed to use this ' \ + 'plugin. Download it at ' \ + '' \ + 'or with ' + try: from supybot.i18n import PluginInternationalization from supybot.i18n import internationalizeDocstring @@ -102,6 +109,8 @@ class MegaHAL(callbacks.Plugin): megahal.learn(msg) def doPrivmsg(self, irc, msg): + if not msg.args[0].startswith('#'): # It is a private message + return message = msg.args[1] if message.startswith(irc.nick) or re.match('\W.*', message): @@ -110,8 +119,13 @@ class MegaHAL(callbacks.Plugin): probability = self.registryValue('answer.probability', msg.args[0]) self._response(message, probability, irc.reply) - + def invalidCommand(self, irc, msg, tokens): + if not msg.args[0].startswith('#'): # It is a private message + # Actually, we would like to answer, but : + # 1) It may be a mistyped identify command (or whatever) + # 2) MegaHAL can't reply without learning + return message = msg.args[1] usedToStartWithNick = False if message.startswith(message):