mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Updated for the new registry dealio.
This commit is contained in:
parent
28a79d4591
commit
201f11cc94
@ -49,8 +49,10 @@ import utils
|
||||
import ircdb
|
||||
import ircutils
|
||||
import privmsgs
|
||||
import registry
|
||||
import callbacks
|
||||
import configurable
|
||||
|
||||
import Owner
|
||||
|
||||
try:
|
||||
import sqlite
|
||||
@ -58,27 +60,26 @@ except ImportError:
|
||||
raise callbacks.Error, 'You need to have PySQLite installed to use this ' \
|
||||
'plugin. Download it at <http://pysqlite.sf.net/>'
|
||||
|
||||
class Factoids(plugins.ChannelDBHandler,
|
||||
callbacks.Privmsg,
|
||||
configurable.Mixin):
|
||||
configurables = configurable.Dictionary(
|
||||
[('learn-separator', configurable.NoSpacesStrType, 'as',
|
||||
"""Determines what separator must be used in the learn command.
|
||||
Defaults to 'as' -- learn <key> as <value>. Users might feel more
|
||||
comfortable with 'is' or something else, so it's configurable."""),
|
||||
('show-factoid-if-only-one-match', configurable.BoolType, True,
|
||||
"""Determines whether the bot will reply with the single matching
|
||||
factoid if only one factoid matches when using the search command.
|
||||
"""),]
|
||||
)
|
||||
|
||||
conf.registerPlugin('Factoids')
|
||||
|
||||
conf.registerChannelValue(conf.supybot.plugins.Factoids, 'learnSeparator',
|
||||
registry.String('as', """Determines what separator must be used in the
|
||||
learn command. Defaults to 'as' -- learn <key> as <value>. Users might
|
||||
feel more comfortable with 'is' or something else, so it's
|
||||
configurable."""))
|
||||
conf.registerChannelValue(conf.supybot.plugins.Factoids,
|
||||
'showFactoidIfOnlyOneMatch', registry.Boolean(True, """Determines whether
|
||||
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):
|
||||
callbacks.Privmsg.__init__(self)
|
||||
configurable.Mixin.__init__(self)
|
||||
plugins.ChannelDBHandler.__init__(self)
|
||||
|
||||
def die(self):
|
||||
callbacks.Privmsg.die(self)
|
||||
configurable.Mixin.die(self)
|
||||
plugins.ChannelDBHandler.die(self)
|
||||
|
||||
def makeDb(self, filename):
|
||||
@ -117,7 +118,8 @@ class Factoids(plugins.ChannelDBHandler,
|
||||
"""
|
||||
channel = privmsgs.getChannel(msg, args)
|
||||
try:
|
||||
separator = self.configurables.get('learn-separator', channel)
|
||||
separator = conf.supybot.plugins.Factoids. \
|
||||
learnSeparator.get(channel)()
|
||||
i = args.index(separator)
|
||||
except ValueError:
|
||||
raise callbacks.ArgumentError
|
||||
@ -405,7 +407,7 @@ class Factoids(plugins.ChannelDBHandler,
|
||||
if cursor.rowcount == 0:
|
||||
irc.reply('No keys matched that query.')
|
||||
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]])
|
||||
elif cursor.rowcount > 100:
|
||||
irc.reply('More than 100 keys matched that query; '
|
||||
|
@ -121,21 +121,28 @@ if sqlite is not None:
|
||||
self.assertNotError('learn foo as bar')
|
||||
self.assertNotRegexp('info foo', '2 factoids')
|
||||
|
||||
def testConfigurable(self):
|
||||
def testLearnSeparator(self):
|
||||
self.assertError('learn foo is bar')
|
||||
self.assertNotError('learn foo as bar')
|
||||
self.assertRegexp('whatis foo', 'bar')
|
||||
self.assertNotError('factoids config learn-separator is')
|
||||
self.assertError('learn bar as baz')
|
||||
self.assertNotError('learn bar is baz')
|
||||
self.assertRegexp('whatis bar', 'baz')
|
||||
try:
|
||||
conf.supybot.plugins.Factoids.learnSeparator.setValue('is')
|
||||
self.assertError('learn bar as baz')
|
||||
self.assertNotError('learn bar is 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/')
|
||||
q = 'factoids config show-factoid-if-only-one-match Off'
|
||||
self.assertNotError(q)
|
||||
m2 = self.assertNotError('factoids search m/foo/')
|
||||
self.failUnless(m1.args[1].startswith(m2.args[1]))
|
||||
try:
|
||||
conf.supybot.plugins.Factoids. \
|
||||
showFactoidIfOnlyOneMatch.setValue(False)
|
||||
m2 = self.assertNotError('factoids search m/foo/')
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user