mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Update to use the registry
This commit is contained in:
parent
7336a4c9ad
commit
2f3ad5893c
@ -42,13 +42,14 @@ __revision__ = "$Id$"
|
|||||||
|
|
||||||
import plugins
|
import plugins
|
||||||
|
|
||||||
|
import registry
|
||||||
|
|
||||||
import conf
|
import conf
|
||||||
import utils
|
import utils
|
||||||
import plugins
|
import plugins
|
||||||
import ircutils
|
import ircutils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
import callbacks
|
||||||
import configurable
|
|
||||||
|
|
||||||
|
|
||||||
def configure(onStart, afterConnect, advanced):
|
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 'supybot sees such a URL, he will parse the web page for'
|
||||||
print 'information and reply with the results.\n'
|
print 'information and reply with the results.\n'
|
||||||
if yn('Do you want the Ebay snarfer enabled by default?') == 'y':
|
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):
|
class EbayError(callbacks.Error):
|
||||||
pass
|
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
|
Module for eBay stuff. Currently contains a URL snarfer and a command to
|
||||||
get info about an auction.
|
get info about an auction.
|
||||||
"""
|
"""
|
||||||
threaded = True
|
threaded = True
|
||||||
regexps = ['ebaySnarfer']
|
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):
|
def __init__(self):
|
||||||
configurable.Mixin.__init__(self)
|
|
||||||
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
configurable.Mixin.die(self)
|
|
||||||
callbacks.PrivmsgCommandAndRegexp.die(self)
|
callbacks.PrivmsgCommandAndRegexp.die(self)
|
||||||
|
|
||||||
_reopts = re.I | re.S
|
_reopts = re.I | re.S
|
||||||
@ -129,7 +128,7 @@ class Ebay(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
|||||||
def ebaySnarfer(self, irc, msg, match):
|
def ebaySnarfer(self, irc, msg, match):
|
||||||
r"http://cgi\.ebay\.(?:com(?:.au)?|ca|co.uk)/(?:.*?/)?(?:ws/)?" \
|
r"http://cgi\.ebay\.(?:com(?:.au)?|ca|co.uk)/(?:.*?/)?(?:ws/)?" \
|
||||||
r"eBayISAPI\.dll\?ViewItem(?:&item=\d+|&category=\d+)+"
|
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
|
return
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
try:
|
try:
|
||||||
|
@ -41,13 +41,14 @@ import re
|
|||||||
import sets
|
import sets
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
|
import registry
|
||||||
|
|
||||||
import conf
|
import conf
|
||||||
import utils
|
import utils
|
||||||
import plugins
|
import plugins
|
||||||
import ircutils
|
import ircutils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
import callbacks
|
||||||
import configurable
|
|
||||||
|
|
||||||
|
|
||||||
def configure(onStart, afterConnect, advanced):
|
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 'supybot sees such a URL, he will parse the web page for'
|
||||||
print 'information and reply with the results.\n'
|
print 'information and reply with the results.\n'
|
||||||
if yn('Do you want the Gameknot stats snarfer enabled by default?')==\
|
if yn('Do you want the Gameknot stats snarfer enabled by default?')==\
|
||||||
'n':
|
'y':
|
||||||
onStart.append('Gameknot toggle stat off')
|
conf.supybot.plugins.Gameknot.statSnarfer.setValue(True)
|
||||||
if yn('Do you want the Gameknot Game links snarfer enabled by '
|
if yn('Do you want the Gameknot Game links snarfer enabled by '
|
||||||
'default?') == 'n':
|
'default?') == 'y':
|
||||||
onStart.append('Gameknot toggle stat off')
|
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
|
threaded = True
|
||||||
regexps = ['gameknotSnarfer', 'gameknotStatsSnarfer']
|
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'<font color="#FFFF33">(\d+)</font>')
|
_gkrating = re.compile(r'<font color="#FFFF33">(\d+)</font>')
|
||||||
_gkgames = re.compile(r's:</td><td class=sml>(\d+)</td></tr>')
|
_gkgames = re.compile(r's:</td><td class=sml>(\d+)</td></tr>')
|
||||||
_gkrecord = re.compile(r'"#FFFF00">(\d+)[^"]+"#FFFF00">(\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<name>.*?)</span>')
|
_gkteam = re.compile(r'Team:(<.*?>)+(?P<name>.*?)</span>')
|
||||||
_gkseen = re.compile(r'(seen on GK:\s+([^[]+ago)|.*?is hiding.*?)')
|
_gkseen = re.compile(r'(seen on GK:\s+([^[]+ago)|.*?is hiding.*?)')
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
configurable.Mixin.__init__(self)
|
|
||||||
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
configurable.Mixin.die(self)
|
|
||||||
callbacks.PrivmsgCommandAndRegexp.die(self)
|
callbacks.PrivmsgCommandAndRegexp.die(self)
|
||||||
|
|
||||||
def getStats(self, name):
|
def getStats(self, name):
|
||||||
@ -181,7 +179,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
|||||||
_gkReason = re.compile(r'won\s+\(\S+\s+(\S+)\)')
|
_gkReason = re.compile(r'won\s+\(\S+\s+(\S+)\)')
|
||||||
def gameknotSnarfer(self, irc, msg, match):
|
def gameknotSnarfer(self, irc, msg, match):
|
||||||
r"http://(?:www\.)?gameknot\.com/chess\.pl\?bd=\d+(&r=\d+)?"
|
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
|
return
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
fd = urllib2.urlopen(url)
|
fd = urllib2.urlopen(url)
|
||||||
@ -244,7 +242,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
|||||||
|
|
||||||
def gameknotStatsSnarfer(self, irc, msg, match):
|
def gameknotStatsSnarfer(self, irc, msg, match):
|
||||||
r"http://gameknot\.com/stats\.pl\?([^&]+)"
|
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
|
return
|
||||||
name = match.group(1)
|
name = match.group(1)
|
||||||
s = self.getStats(name)
|
s = self.getStats(name)
|
||||||
|
@ -41,7 +41,7 @@ if network:
|
|||||||
self.assertError('auction foobar')
|
self.assertError('auction foobar')
|
||||||
|
|
||||||
def testSnarfer(self):
|
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'
|
self.assertRegexp('http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem'
|
||||||
'&category=176&item=3053767552',
|
'&category=176&item=3053767552',
|
||||||
r'.*Cisco NP-4T.*Serial Module.*US \$74\.95.*')
|
r'.*Cisco NP-4T.*Serial Module.*US \$74\.95.*')
|
||||||
@ -64,11 +64,11 @@ if network:
|
|||||||
r'88-89 CRX amber')
|
r'88-89 CRX amber')
|
||||||
|
|
||||||
def testConfigSnarfer(self):
|
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/'
|
self.assertNoResponse('http://cgi.ebay.com/ebaymotors/ws/'
|
||||||
'eBayISAPI.dll?ViewItem&item=2439393310&'
|
'eBayISAPI.dll?ViewItem&item=2439393310&'
|
||||||
'category=33708')
|
'category=33708')
|
||||||
self.assertNotError('ebay config auction-snarfer on')
|
conf.supybot.plugins.Ebay.auctionSnarfer.setValue(True)
|
||||||
self.assertNotError('http://cgi.ebay.com/ebaymotors/ws/'
|
self.assertNotError('http://cgi.ebay.com/ebaymotors/ws/'
|
||||||
'eBayISAPI.dll?ViewItem&item=2439393310&'
|
'eBayISAPI.dll?ViewItem&item=2439393310&'
|
||||||
'category=33708')
|
'category=33708')
|
||||||
|
@ -42,6 +42,7 @@ if network:
|
|||||||
self.assertNotError('gkstats Strike')
|
self.assertNotError('gkstats Strike')
|
||||||
|
|
||||||
def testUrlSnarfer(self):
|
def testUrlSnarfer(self):
|
||||||
|
conf.supybot.plugins.Gameknot.gameSnarfer.setValue(True)
|
||||||
self.assertNotError('http://gameknot.com/chess.pl?bd=1019508')
|
self.assertNotError('http://gameknot.com/chess.pl?bd=1019508')
|
||||||
self.assertNotError('here\'s a link: '
|
self.assertNotError('here\'s a link: '
|
||||||
'http://gameknot.com/chess.pl?bd=1077350&r=394 '
|
'http://gameknot.com/chess.pl?bd=1077350&r=394 '
|
||||||
@ -52,22 +53,24 @@ if network:
|
|||||||
self.nick)
|
self.nick)
|
||||||
|
|
||||||
def testStatsUrlSnarfer(self):
|
def testStatsUrlSnarfer(self):
|
||||||
|
conf.supybot.plugins.Gameknot.statSnarfer.setValue(True)
|
||||||
self.assertNotError('http://gameknot.com/stats.pl?ironchefchess')
|
self.assertNotError('http://gameknot.com/stats.pl?ironchefchess')
|
||||||
self.assertRegexp('http://gameknot.com/stats.pl?ddipaolo&1',
|
self.assertRegexp('http://gameknot.com/stats.pl?ddipaolo&1',
|
||||||
r'^[^&]+$')
|
r'^[^&]+$')
|
||||||
|
|
||||||
def testConfig(self):
|
def testConfig(self):
|
||||||
self.assertNotError('gameknot config game-snarfer off')
|
conf.supybot.plugins.Gameknot.gameSnarfer.setValue(False)
|
||||||
self.assertNotError('gameknot config stats-snarfer off')
|
conf.supybot.plugins.Gameknot.statSnarfer.setValue(False)
|
||||||
self.assertNoResponse('http://gameknot.com/stats.pl?ironchefchess')
|
self.assertNoResponse('http://gameknot.com/stats.pl?ironchefchess')
|
||||||
self.assertNoResponse('http://gameknot.com/chess.pl?bd=907498')
|
self.assertNoResponse('http://gameknot.com/chess.pl?bd=907498')
|
||||||
self.assertNotError('gameknot config game-snarfer on')
|
conf.supybot.plugins.Gameknot.gameSnarfer.setValue(True)
|
||||||
self.assertNotError('gameknot config stats-snarfer on')
|
conf.supybot.plugins.Gameknot.statSnarfer.setValue(True)
|
||||||
self.assertNotError('http://gameknot.com/stats.pl?ironchefchess')
|
self.assertNotError('http://gameknot.com/stats.pl?ironchefchess')
|
||||||
self.assertNotError('http://gameknot.com/chess.pl?bd=907498')
|
self.assertNotError('http://gameknot.com/chess.pl?bd=907498')
|
||||||
|
|
||||||
|
|
||||||
def testSnarfer(self):
|
def testSnarfer(self):
|
||||||
|
conf.supybot.plugins.Gameknot.gameSnarfer.setValue(True)
|
||||||
# This game expired.
|
# This game expired.
|
||||||
## self.assertRegexp('http://gameknot.com/chess.pl?bd=907498',
|
## self.assertRegexp('http://gameknot.com/chess.pl?bd=907498',
|
||||||
## '\x02ddipaolo\x0f won')
|
## '\x02ddipaolo\x0f won')
|
||||||
|
Loading…
Reference in New Issue
Block a user