From 2f3ad5893c6f8a01addc0ba16aeb36dd921c00ea Mon Sep 17 00:00:00 2001 From: James Vega Date: Wed, 21 Jan 2004 02:19:47 +0000 Subject: [PATCH] Update to use the registry --- plugins/Ebay.py | 21 ++++++++++----------- plugins/Gameknot.py | 38 ++++++++++++++++++-------------------- test/test_Ebay.py | 6 +++--- test/test_Gameknot.py | 11 +++++++---- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/plugins/Ebay.py b/plugins/Ebay.py index 8969ecea8..941ac6954 100644 --- a/plugins/Ebay.py +++ b/plugins/Ebay.py @@ -42,13 +42,14 @@ __revision__ = "$Id$" import plugins +import registry + import conf import utils import plugins import ircutils import privmsgs import callbacks -import configurable def configure(onStart, afterConnect, advanced): @@ -63,29 +64,27 @@ def configure(onStart, afterConnect, advanced): print 'supybot sees such a URL, he will parse the web page for' print 'information and reply with the results.\n' if yn('Do you want the Ebay snarfer enabled by default?') == 'y': - onStart.append('Ebay config auction-snarfer on') + conf.supybot.plugins.Ebay.auctionSnarfer.setValue(True) class EbayError(callbacks.Error): pass -class Ebay(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin): +conf.registerPlugin('Ebay') +conf.registerChannelValue(conf.supybot.plugins.Ebay, 'auctionSnarfer', + registry.Boolean(False, """Determines whether the bot will automatically + 'snarf' Ebay auction URLs and print information about them.""")) + +class Ebay(callbacks.PrivmsgCommandAndRegexp): """ Module for eBay stuff. Currently contains a URL snarfer and a command to get info about an auction. """ threaded = True regexps = ['ebaySnarfer'] - configurables = configurable.Dictionary( - [('auction-snarfer', configurable.BoolType, False, - """Determines whether the bot will automatically 'snarf' Ebay auction - URLs and print information about them.""")] - ) def __init__(self): - configurable.Mixin.__init__(self) callbacks.PrivmsgCommandAndRegexp.__init__(self) def die(self): - configurable.Mixin.die(self) callbacks.PrivmsgCommandAndRegexp.die(self) _reopts = re.I | re.S @@ -129,7 +128,7 @@ class Ebay(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin): def ebaySnarfer(self, irc, msg, match): r"http://cgi\.ebay\.(?:com(?:.au)?|ca|co.uk)/(?:.*?/)?(?:ws/)?" \ r"eBayISAPI\.dll\?ViewItem(?:&item=\d+|&category=\d+)+" - if not self.configurables.get('auction-snarfer', channel=msg.args[0]): + if not self.registryValue('auctionSnarfer', msg.args[0]): return url = match.group(0) try: diff --git a/plugins/Gameknot.py b/plugins/Gameknot.py index 10abe0e01..25578ac2f 100644 --- a/plugins/Gameknot.py +++ b/plugins/Gameknot.py @@ -41,13 +41,14 @@ import re import sets import urllib2 +import registry + import conf import utils import plugins import ircutils import privmsgs import callbacks -import configurable def configure(onStart, afterConnect, advanced): @@ -63,26 +64,25 @@ def configure(onStart, afterConnect, advanced): print 'supybot sees such a URL, he will parse the web page for' print 'information and reply with the results.\n' if yn('Do you want the Gameknot stats snarfer enabled by default?')==\ - 'n': - onStart.append('Gameknot toggle stat off') + 'y': + conf.supybot.plugins.Gameknot.statSnarfer.setValue(True) if yn('Do you want the Gameknot Game links snarfer enabled by ' - 'default?') == 'n': - onStart.append('Gameknot toggle stat off') + 'default?') == 'y': + conf.supybot.plugins.Gameknot.gameSnarfer.setValue(True) +conf.registerPlugin('Gameknot') +conf.registerChannelValue(conf.supybot.plugins.Gameknot, 'gameSnarfer', + registry.Boolean(False, """Determines whether the game URL snarfer is + enabled. If so, the bot will reply to the channel with a summary of the + game data when it sees a Gameknot game link on the channel.""")) +conf.registerChannelValue(conf.supybot.plugins.Gameknot, 'statSnarfer', + registry.Boolean(False, """Determines whether the stats URL snarfer is + enabled. If so, the bot will reply to the channel with a summary of the + stats of any player whose stats URL is seen on the channel.""")) -class Gameknot(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin): +class Gameknot(callbacks.PrivmsgCommandAndRegexp): threaded = True regexps = ['gameknotSnarfer', 'gameknotStatsSnarfer'] - configurables = configurable.Dictionary( - [('game-snarfer', configurable.BoolType, True, - """Determines whether the game URL snarfer is active; if so, the bot - will reply to the channel with a summary of the game data when it - sees a Gameknot game on the channel."""), - ('stats-snarfer', configurable.BoolType, True, - """Determines whether the stats URL snarfer is active; if so, the bot - will reply to the channel with a summary of the stats of any player - whose stats URL is seen on the channel.""")] - ) _gkrating = re.compile(r'(\d+)') _gkgames = re.compile(r's:(\d+)') _gkrecord = re.compile(r'"#FFFF00">(\d+)[^"]+"#FFFF00">(\d+)[^"]+' @@ -90,11 +90,9 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin): _gkteam = re.compile(r'Team:(<.*?>)+(?P.*?)') _gkseen = re.compile(r'(seen on GK:\s+([^[]+ago)|.*?is hiding.*?)') def __init__(self): - configurable.Mixin.__init__(self) callbacks.PrivmsgCommandAndRegexp.__init__(self) def die(self): - configurable.Mixin.die(self) callbacks.PrivmsgCommandAndRegexp.die(self) def getStats(self, name): @@ -181,7 +179,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin): _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.configurables.get('game-snarfer', channel=msg.args[0]): + if not self.registryValue('gameSnarfer', msg.args[0]): return url = match.group(0) fd = urllib2.urlopen(url) @@ -244,7 +242,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin): def gameknotStatsSnarfer(self, irc, msg, match): r"http://gameknot\.com/stats\.pl\?([^&]+)" - if not self.configurables.get('stats-snarfer', channel=msg.args[0]): + if not self.registryValue('statSnarfer', msg.args[0]): return name = match.group(1) s = self.getStats(name) diff --git a/test/test_Ebay.py b/test/test_Ebay.py index e054726bb..e5dfe8590 100644 --- a/test/test_Ebay.py +++ b/test/test_Ebay.py @@ -41,7 +41,7 @@ if network: self.assertError('auction foobar') def testSnarfer(self): - self.assertNotError('ebay config auction-snarfer on') + conf.supybot.plugins.Ebay.auctionSnarfer.setValue(True) self.assertRegexp('http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem' '&category=176&item=3053767552', r'.*Cisco NP-4T.*Serial Module.*US \$74\.95.*') @@ -64,11 +64,11 @@ if network: r'88-89 CRX amber') def testConfigSnarfer(self): - self.assertNotError('ebay config auction-snarfer off') + conf.supybot.plugins.Ebay.auctionSnarfer.setValue(False) self.assertNoResponse('http://cgi.ebay.com/ebaymotors/ws/' 'eBayISAPI.dll?ViewItem&item=2439393310&' 'category=33708') - self.assertNotError('ebay config auction-snarfer on') + conf.supybot.plugins.Ebay.auctionSnarfer.setValue(True) self.assertNotError('http://cgi.ebay.com/ebaymotors/ws/' 'eBayISAPI.dll?ViewItem&item=2439393310&' 'category=33708') diff --git a/test/test_Gameknot.py b/test/test_Gameknot.py index 725a8513c..4221e7166 100644 --- a/test/test_Gameknot.py +++ b/test/test_Gameknot.py @@ -42,6 +42,7 @@ if network: self.assertNotError('gkstats Strike') def testUrlSnarfer(self): + conf.supybot.plugins.Gameknot.gameSnarfer.setValue(True) self.assertNotError('http://gameknot.com/chess.pl?bd=1019508') self.assertNotError('here\'s a link: ' 'http://gameknot.com/chess.pl?bd=1077350&r=394 ' @@ -52,22 +53,24 @@ if network: self.nick) def testStatsUrlSnarfer(self): + conf.supybot.plugins.Gameknot.statSnarfer.setValue(True) self.assertNotError('http://gameknot.com/stats.pl?ironchefchess') self.assertRegexp('http://gameknot.com/stats.pl?ddipaolo&1', r'^[^&]+$') def testConfig(self): - self.assertNotError('gameknot config game-snarfer off') - self.assertNotError('gameknot config stats-snarfer off') + conf.supybot.plugins.Gameknot.gameSnarfer.setValue(False) + conf.supybot.plugins.Gameknot.statSnarfer.setValue(False) self.assertNoResponse('http://gameknot.com/stats.pl?ironchefchess') self.assertNoResponse('http://gameknot.com/chess.pl?bd=907498') - self.assertNotError('gameknot config game-snarfer on') - self.assertNotError('gameknot config stats-snarfer on') + conf.supybot.plugins.Gameknot.gameSnarfer.setValue(True) + conf.supybot.plugins.Gameknot.statSnarfer.setValue(True) self.assertNotError('http://gameknot.com/stats.pl?ironchefchess') self.assertNotError('http://gameknot.com/chess.pl?bd=907498') def testSnarfer(self): + conf.supybot.plugins.Gameknot.gameSnarfer.setValue(True) # This game expired. ## self.assertRegexp('http://gameknot.com/chess.pl?bd=907498', ## '\x02ddipaolo\x0f won')