Updated for the new registry dealio.

This commit is contained in:
Jeremy Fincher 2004-01-20 12:27:48 +00:00
parent 28a79d4591
commit 201f11cc94
2 changed files with 37 additions and 28 deletions

View File

@ -49,8 +49,10 @@ import utils
import ircdb import ircdb
import ircutils import ircutils
import privmsgs import privmsgs
import registry
import callbacks import callbacks
import configurable
import Owner
try: try:
import sqlite import sqlite
@ -58,27 +60,26 @@ except ImportError:
raise callbacks.Error, 'You need to have PySQLite installed to use this ' \ raise callbacks.Error, 'You need to have PySQLite installed to use this ' \
'plugin. Download it at <http://pysqlite.sf.net/>' 'plugin. Download it at <http://pysqlite.sf.net/>'
class Factoids(plugins.ChannelDBHandler,
callbacks.Privmsg, conf.registerPlugin('Factoids')
configurable.Mixin):
configurables = configurable.Dictionary( conf.registerChannelValue(conf.supybot.plugins.Factoids, 'learnSeparator',
[('learn-separator', configurable.NoSpacesStrType, 'as', registry.String('as', """Determines what separator must be used in the
"""Determines what separator must be used in the learn command. learn command. Defaults to 'as' -- learn <key> as <value>. Users might
Defaults to 'as' -- learn <key> as <value>. Users might feel more feel more comfortable with 'is' or something else, so it's
comfortable with 'is' or something else, so it's configurable."""), configurable."""))
('show-factoid-if-only-one-match', configurable.BoolType, True, conf.registerChannelValue(conf.supybot.plugins.Factoids,
"""Determines whether the bot will reply with the single matching 'showFactoidIfOnlyOneMatch', registry.Boolean(True, """Determines whether
factoid if only one factoid matches when using the search command. the bot will reply with the single matching factoid if only one factoid
"""),] matches when using the search command."""))
)
class Factoids(plugins.ChannelDBHandler, callbacks.Privmsg):
def __init__(self): def __init__(self):
callbacks.Privmsg.__init__(self) callbacks.Privmsg.__init__(self)
configurable.Mixin.__init__(self)
plugins.ChannelDBHandler.__init__(self) plugins.ChannelDBHandler.__init__(self)
def die(self): def die(self):
callbacks.Privmsg.die(self) callbacks.Privmsg.die(self)
configurable.Mixin.die(self)
plugins.ChannelDBHandler.die(self) plugins.ChannelDBHandler.die(self)
def makeDb(self, filename): def makeDb(self, filename):
@ -117,7 +118,8 @@ class Factoids(plugins.ChannelDBHandler,
""" """
channel = privmsgs.getChannel(msg, args) channel = privmsgs.getChannel(msg, args)
try: try:
separator = self.configurables.get('learn-separator', channel) separator = conf.supybot.plugins.Factoids. \
learnSeparator.get(channel)()
i = args.index(separator) i = args.index(separator)
except ValueError: except ValueError:
raise callbacks.ArgumentError raise callbacks.ArgumentError
@ -405,7 +407,7 @@ class Factoids(plugins.ChannelDBHandler,
if cursor.rowcount == 0: if cursor.rowcount == 0:
irc.reply('No keys matched that query.') irc.reply('No keys matched that query.')
elif cursor.rowcount == 1 and \ elif cursor.rowcount == 1 and \
self.configurables.get('show-factoid-if-only-one-match',channel): conf.supybot.plugins.Factoids.showFactoidIfOnlyOneMatch.get(channel)():
self.whatis(irc, msg, [cursor.fetchone()[0]]) self.whatis(irc, msg, [cursor.fetchone()[0]])
elif cursor.rowcount > 100: elif cursor.rowcount > 100:
irc.reply('More than 100 keys matched that query; ' irc.reply('More than 100 keys matched that query; '

View File

@ -121,21 +121,28 @@ if sqlite is not None:
self.assertNotError('learn foo as bar') self.assertNotError('learn foo as bar')
self.assertNotRegexp('info foo', '2 factoids') self.assertNotRegexp('info foo', '2 factoids')
def testConfigurable(self): def testLearnSeparator(self):
self.assertError('learn foo is bar') self.assertError('learn foo is bar')
self.assertNotError('learn foo as bar') self.assertNotError('learn foo as bar')
self.assertRegexp('whatis foo', 'bar') self.assertRegexp('whatis foo', 'bar')
self.assertNotError('factoids config learn-separator is') try:
conf.supybot.plugins.Factoids.learnSeparator.setValue('is')
self.assertError('learn bar as baz') self.assertError('learn bar as baz')
self.assertNotError('learn bar is baz') self.assertNotError('learn bar is baz')
self.assertRegexp('whatis bar', 'baz') self.assertRegexp('whatis bar', 'baz')
finally:
conf.supybot.plugins.Factoids.learnSeparator.setValue('as')
# show-factoid-if-only-one-match def testShowFactoidIfOnlyOneMatch(self):
m1 = self.assertNotError('factoids search m/foo|bar/') m1 = self.assertNotError('factoids search m/foo|bar/')
q = 'factoids config show-factoid-if-only-one-match Off' try:
self.assertNotError(q) conf.supybot.plugins.Factoids. \
showFactoidIfOnlyOneMatch.setValue(False)
m2 = self.assertNotError('factoids search m/foo/') m2 = self.assertNotError('factoids search m/foo/')
self.failUnless(m1.args[1].startswith(m2.args[1])) self.failUnless(m1.args[1].startswith(m2.args[1]))
finally:
conf.supybot.plugins.Factoids. \
showFactoidIfOnlyOneMatch.setValue(True)
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: