mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Fix some bugs in the Factoids conversion.
This commit is contained in:
parent
6b38346b5a
commit
979cbd551d
@ -64,7 +64,13 @@ def getFactoid(irc, msg, args, state):
|
|||||||
state.args.append(' '.join(key))
|
state.args.append(' '.join(key))
|
||||||
state.args.append(' '.join(value))
|
state.args.append(' '.join(value))
|
||||||
|
|
||||||
|
def getFactoidId(irc, msg, args, state):
|
||||||
|
Type = 'key id'
|
||||||
|
p = lambda i: i > 0
|
||||||
|
callConverter('int', irc, msg, args, state, Type, p)
|
||||||
|
|
||||||
addConverter('factoid', getFactoid)
|
addConverter('factoid', getFactoid)
|
||||||
|
addConverter('factoidId', getFactoidId)
|
||||||
|
|
||||||
class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
||||||
def makeDb(self, filename):
|
def makeDb(self, filename):
|
||||||
@ -133,7 +139,8 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
LIMIT 20""", key)
|
LIMIT 20""", key)
|
||||||
return [t[0] for t in cursor.fetchall()]
|
return [t[0] for t in cursor.fetchall()]
|
||||||
|
|
||||||
def _replyFactoids(self, irc, channel, key, factoids, number=0, error=True):
|
def _replyFactoids(self, irc, channel, key, factoids,
|
||||||
|
number=0, error=True):
|
||||||
if factoids:
|
if factoids:
|
||||||
if number:
|
if number:
|
||||||
try:
|
try:
|
||||||
@ -157,7 +164,7 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
elif error:
|
elif error:
|
||||||
irc.error('No factoid matches that key.')
|
irc.error('No factoid matches that key.')
|
||||||
|
|
||||||
def tokenizedCommand(self, irc, msg, tokens):
|
def invalidCommand(self, irc, msg, tokens):
|
||||||
if irc.isChannel(msg.args[0]):
|
if irc.isChannel(msg.args[0]):
|
||||||
channel = msg.args[0]
|
channel = msg.args[0]
|
||||||
if self.registryValue('replyWhenInvalidCommand', channel):
|
if self.registryValue('replyWhenInvalidCommand', channel):
|
||||||
@ -174,7 +181,8 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
"""
|
"""
|
||||||
factoids = self._lookupFactoid(channel, key)
|
factoids = self._lookupFactoid(channel, key)
|
||||||
self._replyFactoids(irc, channel, key, factoids, number)
|
self._replyFactoids(irc, channel, key, factoids, number)
|
||||||
whatis = wrap(whatis, ['channel', reverse(optional('int', 0)), 'text'])
|
whatis = wrap(whatis, ['channel',
|
||||||
|
reverse(optional('factoidId', 0)), 'text'])
|
||||||
|
|
||||||
def lock(self, irc, msg, args, channel, key):
|
def lock(self, irc, msg, args, channel, key):
|
||||||
"""[<channel>] <key>
|
"""[<channel>] <key>
|
||||||
@ -233,7 +241,7 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
if number is not None:
|
if number is not None:
|
||||||
results = cursor.fetchall()
|
results = cursor.fetchall()
|
||||||
try:
|
try:
|
||||||
(_, id) = results[number]
|
(_, id) = results[number-1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.error('Invalid factoid number.')
|
irc.error('Invalid factoid number.')
|
||||||
return
|
return
|
||||||
@ -247,7 +255,7 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
cursor.rowcount)
|
cursor.rowcount)
|
||||||
forget = wrap(forget, ['channel',
|
forget = wrap(forget, ['channel',
|
||||||
reverse(optional(first(('literal', '*'),
|
reverse(optional(first(('literal', '*'),
|
||||||
'id'))),
|
'factoidId'))),
|
||||||
'text'])
|
'text'])
|
||||||
|
|
||||||
def random(self, irc, msg, args, channel):
|
def random(self, irc, msg, args, channel):
|
||||||
@ -328,7 +336,7 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
db.commit()
|
db.commit()
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
change = wrap(change, ['channel', 'something',
|
change = wrap(change, ['channel', 'something',
|
||||||
('id', 'key id'), 'regexpReplacer'])
|
'factoidId', 'regexpReplacer'])
|
||||||
|
|
||||||
_sqlTrans = string.maketrans('*?', '%_')
|
_sqlTrans = string.maketrans('*?', '%_')
|
||||||
def search(self, irc, msg, args, channel, optlist, globs):
|
def search(self, irc, msg, args, channel, optlist, globs):
|
||||||
|
@ -127,16 +127,18 @@ if sqlite:
|
|||||||
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')
|
||||||
|
orig = conf.supybot.plugins.Factoids.learnSeparator()
|
||||||
try:
|
try:
|
||||||
conf.supybot.plugins.Factoids.learnSeparator.setValue('is')
|
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:
|
finally:
|
||||||
conf.supybot.plugins.Factoids.learnSeparator.setValue('as')
|
conf.supybot.plugins.Factoids.learnSeparator.setValue(orig)
|
||||||
|
|
||||||
def testShowFactoidIfOnlyOneMatch(self):
|
def testShowFactoidIfOnlyOneMatch(self):
|
||||||
m1 = self.assertNotError('factoids search m/foo|bar/')
|
m1 = self.assertNotError('factoids search m/foo|bar/')
|
||||||
|
orig = conf.supybot.plugins.Factoids.showFactoidIfOnlyOneMatch()
|
||||||
try:
|
try:
|
||||||
conf.supybot.plugins.Factoids. \
|
conf.supybot.plugins.Factoids. \
|
||||||
showFactoidIfOnlyOneMatch.setValue(False)
|
showFactoidIfOnlyOneMatch.setValue(False)
|
||||||
@ -144,11 +146,18 @@ if sqlite:
|
|||||||
self.failUnless(m1.args[1].startswith(m2.args[1]))
|
self.failUnless(m1.args[1].startswith(m2.args[1]))
|
||||||
finally:
|
finally:
|
||||||
conf.supybot.plugins.Factoids. \
|
conf.supybot.plugins.Factoids. \
|
||||||
showFactoidIfOnlyOneMatch.setValue(True)
|
showFactoidIfOnlyOneMatch.setValue(orig)
|
||||||
|
|
||||||
def testInvalidCommand(self):
|
def testInvalidCommand(self):
|
||||||
self.assertNotError('learn foo as bar')
|
orig = conf.supybot.plugins.Factoids.replyWhenInvalidCommand()
|
||||||
self.assertRegexp('foo', 'bar')
|
try:
|
||||||
|
conf.supybot.plugins.Factoids.\
|
||||||
|
replyWhenInvalidCommand.setValue(True)
|
||||||
|
self.assertNotError('learn foo as bar')
|
||||||
|
self.assertRegexp('foo', 'bar')
|
||||||
|
finally:
|
||||||
|
conf.supybot.plugins.Factoids.\
|
||||||
|
replyWhenInvalidCommand.setValue(orig)
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||||
|
Loading…
Reference in New Issue
Block a user