diff --git a/plugins/Gameknot.py b/plugins/Gameknot.py index 922d7c878..b6c7c21e8 100644 --- a/plugins/Gameknot.py +++ b/plugins/Gameknot.py @@ -69,6 +69,11 @@ example = utils.wrapLines(""" class Gameknot(callbacks.PrivmsgCommandAndRegexp): threaded = True regexps = sets.Set(['gameknotSnarfer', 'gameknotStatsSnarfer']) + + def __init__(self): + callbacks.PrivmsgCommandAndRegexp.__init__(self) + self.snarfer = True + _gkrating = re.compile(r'(\d+)') _gkgames = re.compile(r's:  (\d+)') _gkrecord = re.compile(r'"#FFFF00">(\d+)[^"]+"#FFFF00">(\d+)[^"]+'\ @@ -141,6 +146,18 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp): name = privmsgs.getArgs(args) irc.reply(msg, self.getStats(name)) + def togglesnarfer(self, irc, msg, args): + """takes no argument + + Disables the snarfer that responds to all Sourceforge Tracker links + """ + self.snarfer = not self.snarfer + if self.snarfer: + irc.reply(msg, '%s (Snarfer is enabled)' % conf.replySuccess) + else: + irc.reply(msg, '%s (Snarfer is disabled)' % conf.replySuccess) + togglesnarfer=privmsgs.checkCapability(togglesnarfer, 'admin') + _gkPlayer = re.compile(r"popd\('(Rating[^']+)'\).*?>([^<]+)<") _gkRating = re.compile(r": (\d+)[^:]+:
(\d+)[^,]+, (\d+)[^,]+, (\d+)") _gkGameTitle = re.compile(r"

(.*?)\s* \s*\(started") @@ -148,6 +165,8 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp): _gkReason = re.compile(r'won\s+\(\S+\s+(\S+)\)') def gameknotSnarfer(self, irc, msg, match): r"http://(?:www\.)?gameknot\.com/chess\.pl\?bd=\d+(&r=\d+)?" + if not self.snarfer: + return #debug.printf('Got a GK URL from %s' % msg.prefix) url = match.group(0) fd = urllib2.urlopen(url) @@ -192,12 +211,15 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp): (gameTitle, wName, wStats, bName, bStats, toMove) irc.reply(msg, s, prefixName=False) except ValueError: - irc.error(msg,'That doesn\'t appear to be a proper Gameknot game.') + irc.error(msg,'That doesn\'t appear to be a proper Gameknot game.'\ + ' (%s)' % conf.replyPossibleBug) except Exception, e: irc.error(msg, debug.exnToString(e)) def gameknotStatsSnarfer(self, irc, msg, match): r"http://gameknot\.com/stats\.pl\?([^&]+)" + if not self.snarfer: + return name = match.group(1) s = self.getStats(name) irc.reply(msg, s, prefixName=False) diff --git a/plugins/Google.py b/plugins/Google.py index 0288a063d..e9116892d 100644 --- a/plugins/Google.py +++ b/plugins/Google.py @@ -150,15 +150,17 @@ class Google(callbacks.PrivmsgCommandAndRegexp): irc.reply(msg, conf.replySuccess) licensekey = privmsgs.checkCapability(licensekey, 'admin') - def disablesnarfer(self, irc, msg, args): + def togglesnarfer(self, irc, msg, args): """takes no argument - Disables the snarfer that responds to all messages that begin with - 'google' + Disables the snarfer that responds to all Sourceforge Tracker links """ - self.snarfer = False - irc.reply(msg, conf.replySuccess) - disablesnarfer=privmsgs.checkCapability(disablesnarfer, 'admin') + self.snarfer = not self.snarfer + if self.snarfer: + irc.reply(msg, '%s (Snarfer is enabled)' % conf.replySuccess) + else: + irc.reply(msg, '%s (Snarfer is disabled)' % conf.replySuccess) + togglesnarfer=privmsgs.checkCapability(togglesnarfer, 'admin') def google(self, irc, msg, args): """ [--{language,restrict}=] [--{notsafe,similar}] @@ -267,10 +269,9 @@ class Google(callbacks.PrivmsgCommandAndRegexp): data = search(searchString, safeSearch=1) if data.results: url = data.results[0].URL - irc.queueMsg(ircmsgs.privmsg(ircutils.replyTo(msg), url)) + irc.reply(msg, url) else: - irc.queueMsg(ircmsgs.privmsg(ircutils.replyTo(msg), - 'No results for "%s"' % searchString)) + irc.reply(msg, 'No results for "%s"' % searchString) _ggThread = re.compile(r'
Subject: ([^<]+)
') _ggGroup = re.compile(r'Newsgroups: ]+>([^<]+)') @@ -297,11 +298,11 @@ class Google(callbacks.PrivmsgCommandAndRegexp): mThread = self._ggThread.search(text) mGroup = self._ggGroup.search(text) if mThread and mGroup: - irc.queueMsg(ircmsgs.privmsg(ircutils.replyTo(msg), - 'Google Groups: %s, %s' % (mGroup.group(1), mThread.group(1)))) + irc.reply(msg, 'Google Groups: %s, %s' % (mGroup.group(1), + mThread.group(1)), prefixName = False) else: - irc.queueMsg(ircmsgs.privmsg(msg.args[0], - 'That doesn\'t appear to be a proper Google Groups page.')) + irc.error(msg, 'That doesn\'t appear to be a proper '\ + 'Google Groups page. (%s)' % conf.replyPossibleBug) Class = Google diff --git a/plugins/Sf.py b/plugins/Sourceforge.py similarity index 95% rename from plugins/Sf.py rename to plugins/Sourceforge.py index 8d56a1fbd..256111506 100644 --- a/plugins/Sf.py +++ b/plugins/Sourceforge.py @@ -53,7 +53,7 @@ def configure(onStart, afterConnect, advanced): # like to be run when the bot is started; append to afterConnect the # commands you would like to be run when the bot has finished connecting. from questions import expect, anything, something, yn - onStart.append('load Sf') + onStart.append('load Sourceforge') example = utils.wrapLines(""" <@jamessan|work> @bugs @@ -69,7 +69,7 @@ in 0.71, Bug #820961: dock icon doesn't show up with..., Bug #820879: Cannot con < supybot> jamessan|work: Improve CLI interface """) -class Sf(callbacks.PrivmsgCommandAndRegexp): +class Sourceforge(callbacks.PrivmsgCommandAndRegexp): """ Module for Sourceforge stuff. Currently contains commands to query a project's most recent bugs and rfes. @@ -117,14 +117,17 @@ class Sf(callbacks.PrivmsgCommandAndRegexp): matches.append((item[0], utils.htmlToText(item[2]))) return matches - def disablesfsnarfer(self, irc, msg, args): + def togglesnarfer(self, irc, msg, args): """takes no argument Disables the snarfer that responds to all Sourceforge Tracker links """ - self.snarfer = False - irc.reply(msg, conf.replySuccess) - disablesfsnarfer=privmsgs.checkCapability(disablesfsnarfer,'admin') + self.snarfer = not self.snarfer + if self.snarfer: + irc.reply(msg, '%s (Snarfer is enabled)' % conf.replySuccess) + else: + irc.reply(msg, '%s (Snarfer is disabled)' % conf.replySuccess) + togglesnarfer=privmsgs.checkCapability(togglesnarfer,'admin') _bugLink = re.compile(r'"([^"]+)">Bugs') def bugs(self, irc, msg, args): @@ -263,13 +266,13 @@ class Sf(callbacks.PrivmsgCommandAndRegexp): pass linktype = utils.depluralize(linktype) irc.reply(msg, '%s #%s: %s' % (ircutils.bold(linktype), - ircutils.bold(num), '; '.join(resp))) + ircutils.bold(num), '; '.join(resp)), prefixName = False) except AttributeError, e: irc.error(msg, 'That doesn\'t appear to be a proper Sourceforge '\ - 'Tracker page.') + 'Tracker page. (%s)' % conf.replyPossibleBug) except Exception, e: irc.error(msg, debug.exnToString(e)) -Class = Sf +Class = Sourceforge # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/src/conf.py b/src/conf.py index 83ba6a5e3..2897141d4 100644 --- a/src/conf.py +++ b/src/conf.py @@ -137,6 +137,9 @@ replyNotRegistered = 'You must be registered to use this command.' replyInvalidArgument = 'I can\'t send \\r, \\n, or \\0 (\\x00).' replyRequiresPrivacy = 'That can\'t be done in a channel.' replyEvalNotAllowed = 'You must enable conf.allowEval for that to work.' +replyPossibleBug = 'This may be a bug. If you think it is, please file a bug'\ + 'report at http://sourceforge.net/tracker/?func=add&group_id=58965&'\ + 'atid=489447' ### # errorReplyPrivate: True if errors should be reported privately so as not to diff --git a/test/test_Sf.py b/test/test_Sourceforge.py similarity index 95% rename from test/test_Sf.py rename to test/test_Sourceforge.py index aa7ae4c51..e80eb590e 100644 --- a/test/test_Sf.py +++ b/test/test_Sourceforge.py @@ -34,7 +34,7 @@ import re from test import * class SfTest(PluginTestCase, PluginDocumentation): - plugins = ('Sf',) + plugins = ('Sourceforge',) def testBugs(self): self.assertNotError('bugs') self.assertResponse('bugs alkjfi83fa8', 'Can\'t find the "Bugs" link.') @@ -107,9 +107,13 @@ class SfTest(PluginTestCase, PluginDocumentation): self.assertRegexp('http://sourceforge.net/tracker/index.php?'\ 'func=detail&aid=540223&group_id=235&atid=300235', r';.*Status.*: \w+;') - self.assertNotError('disablesfsnarfer') + self.assertNotError('togglesnarfer') self.assertNoResponse('http://sourceforge.net/tracker/index.php?'\ 'func=detail&aid=540223&group_id=235&atid=300235') + self.assertNotError('togglesnarfer') + self.assertRegexp('http://sourceforge.net/tracker/index.php?'\ + 'func=detail&aid=540223&group_id=235&atid=300235', + r';.*Status.*: \w+;') # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: