Converted to Configurable.

This commit is contained in:
Jeremy Fincher 2003-11-08 08:12:25 +00:00
parent 3ed58d9115
commit f2d3e99346
2 changed files with 9 additions and 14 deletions

View File

@ -70,15 +70,16 @@ def configure(onStart, afterConnect, advanced):
from questions import expect, anything, something, yn from questions import expect, anything, something, yn
onStart.append('load Python') onStart.append('load Python')
class Python(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable): class Python(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
modulechars = '%s%s%s' % (string.ascii_letters, string.digits, '_.') modulechars = '%s%s%s' % (string.ascii_letters, string.digits, '_.')
threaded = True threaded = True
regexps = ['aspnRecipes'] regexps = ['aspnRecipes']
toggles = plugins.ToggleDictionary({'ASPN' : True}) configurables = plugins.ConfigurableDictionary(
[('aspn-snarfer', plugins.ConfigurableTypes.bool, True,
def __init__(self): """Determines whether the ASPN Python recipe snarfer is enabled. If
callbacks.PrivmsgCommandAndRegexp.__init__(self) so, it will message the channel with the name of the recipe when it
plugins.Toggleable.__init__(self) sees an ASPN Python recipe link on the channel.""")]
)
def pydoc(self, irc, msg, args): def pydoc(self, irc, msg, args):
"""<python function> """<python function>
@ -174,7 +175,7 @@ class Python(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
_bold = lambda self, g: (ircutils.bold(g[0]),) + g[1:] _bold = lambda self, g: (ircutils.bold(g[0]),) + g[1:]
def aspnRecipes(self, irc, msg, match): def aspnRecipes(self, irc, msg, match):
r"http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/\d+" r"http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/\d+"
if not self.toggles.get('ASPN', channel=msg.args[0]): if not self.configurables.get('aspn-snarfer', channel=msg.args[0]):
return return
url = match.group(0) url = match.group(0)
fd = urllib2.urlopen(url) fd = urllib2.urlopen(url)
@ -188,6 +189,7 @@ class Python(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
if resp: if resp:
#debug.printf('; '.join(resp)) #debug.printf('; '.join(resp))
irc.reply(msg, '; '.join(resp), prefixName = False) irc.reply(msg, '; '.join(resp), prefixName = False)
aspnRecipes = privmsgs.urlSnarfer(aspnRecipes)
Class = Python Class = Python

View File

@ -59,13 +59,6 @@ class PythonTestCase(PluginTestCase, PluginDocumentation):
def testAspnRecipes(self): def testAspnRecipes(self):
self.assertRegexp('http://aspn.activestate.com/ASPN/Cookbook/Python/'\ self.assertRegexp('http://aspn.activestate.com/ASPN/Cookbook/Python/'\
'Recipe/230113', 'Implementation of sets using sorted lists') 'Recipe/230113', 'Implementation of sets using sorted lists')
def testToggle(self):
self.assertHelp('python toggle')
self.assertRegexp('python toggle aspn', '\(aspn: (?:Off|On)\)')
self.assertRegexp('python toggle aspn off', '\(aspn: Off\)')
self.assertRegexp('python toggle aspn off', '\(aspn: Off\)')
self.assertRegexp('python toggle aspn on', '\(aspn: On\)')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: