mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
* Fixed some quoting issues in list*. Adopted the practice of repr()'ing all
factoid keys before displaying them (idea stolen from searchfactoids in Factoids). Also fixed them in the tests as well as adding a test to insure that it's done right. * Added the listkeys and listvalues commands.
This commit is contained in:
parent
fafa01659c
commit
ea024def78
@ -397,6 +397,73 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
"""
|
"""
|
||||||
self._lock(irc, msg, args, False)
|
self._lock(irc, msg, args, False)
|
||||||
|
|
||||||
|
def listauth(self, irc, msg, args):
|
||||||
|
"""<author name>
|
||||||
|
|
||||||
|
Lists the keys of the factoids with the given author. Note that if an
|
||||||
|
author has an integer name, you'll have to use that author's id to use
|
||||||
|
this function (so don't use integer usernames!).
|
||||||
|
"""
|
||||||
|
author = privmsgs.getArgs(args, needed=1)
|
||||||
|
try:
|
||||||
|
id = ircdb.users.getUserId(author)
|
||||||
|
except KeyError:
|
||||||
|
irc.error(msg, "No such user: %s" % author)
|
||||||
|
return
|
||||||
|
cursor = self.db.cursor()
|
||||||
|
cursor.execute("""SELECT key FROM factoids
|
||||||
|
WHERE created_by = %s
|
||||||
|
ORDER BY key""", id)
|
||||||
|
if cursor.rowcount == 0:
|
||||||
|
irc.reply(msg, "No factoids by %s found." % author)
|
||||||
|
return
|
||||||
|
keys = [repr(tup[0]) for tup in cursor.fetchall()]
|
||||||
|
s = "Author search for %s (%d found): %s" % \
|
||||||
|
(author, len(keys), utils.commaAndify(keys))
|
||||||
|
irc.reply(msg, s)
|
||||||
|
|
||||||
|
_sqlTrans = string.maketrans('*?', '%_')
|
||||||
|
def listkeys(self, irc, msg, args):
|
||||||
|
"""<glob>
|
||||||
|
|
||||||
|
Lists the keys of the factoids whose key matches the provided glob.
|
||||||
|
"""
|
||||||
|
glob = privmsgs.getArgs(args, needed=1)
|
||||||
|
cursor = self.db.cursor()
|
||||||
|
cursor.execute("""SELECT key FROM factoids
|
||||||
|
WHERE key LIKE %s
|
||||||
|
ORDER BY key""",
|
||||||
|
glob.translate(self._sqlTrans))
|
||||||
|
if cursor.rowcount == 0:
|
||||||
|
irc.reply(msg, "No keys matching %r found." % glob)
|
||||||
|
return
|
||||||
|
keys = [repr(tup[0]) for tup in cursor.fetchall()]
|
||||||
|
s = "Key search for %r (%d found): %s" % \
|
||||||
|
(glob, len(keys), utils.commaAndify(keys))
|
||||||
|
irc.reply(msg, s)
|
||||||
|
|
||||||
|
def listvalues(self, irc, msg, args):
|
||||||
|
"""<glob>
|
||||||
|
|
||||||
|
|
||||||
|
Lists the keys of the factoids whose value matches the provided glob.
|
||||||
|
"""
|
||||||
|
glob = privmsgs.getArgs(args, needed=1)
|
||||||
|
cursor = self.db.cursor()
|
||||||
|
cursor.execute("""SELECT key FROM factoids
|
||||||
|
WHERE fact LIKE %s
|
||||||
|
ORDER BY key""",
|
||||||
|
glob.translate(self._sqlTrans))
|
||||||
|
if cursor.rowcount == 0:
|
||||||
|
irc.reply(msg, "No values matching %r found." % glob)
|
||||||
|
return
|
||||||
|
keys = [repr(tup[0]) for tup in cursor.fetchall()]
|
||||||
|
s = "Value search for %r (%d found): %s" % \
|
||||||
|
(glob, len(keys), utils.commaAndify(keys))
|
||||||
|
irc.reply(msg, s)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Class = MoobotFactoids
|
Class = MoobotFactoids
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
@ -121,33 +121,40 @@ if sqlite is not None:
|
|||||||
self.assertError('moo =~ s/moo/')
|
self.assertError('moo =~ s/moo/')
|
||||||
|
|
||||||
def testListkeys(self):
|
def testListkeys(self):
|
||||||
self.assertResponse('listkeys *', 'No keys found matching \'*\'.')
|
self.assertResponse('listkeys *', 'No keys matching \'*\' found.')
|
||||||
self.assertNotError('moo is <reply>moo')
|
self.assertNotError('moo is <reply>moo')
|
||||||
self.assertResponse('listkeys moo', 'Key search for \'moo\' '
|
self.assertResponse('listkeys moo', 'Key search for \'moo\' '
|
||||||
'(1 found): moo')
|
'(1 found): \'moo\'')
|
||||||
self.assertResponse('listkeys foo', 'No keys found matching '
|
self.assertResponse('listkeys foo', 'No keys matching \'foo\' '
|
||||||
'\'foo\'.')
|
'found.')
|
||||||
# Throw in a bunch more
|
# Throw in a bunch more
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
self.assertNotError('moo%s is <reply>moo' % i)
|
self.assertNotError('moo%s is <reply>moo' % i)
|
||||||
self.assertRegexp('listkeys moo', '^Key search for \'moo\' '
|
self.assertRegexp('listkeys moo*', '^Key search for \'moo\*\' '
|
||||||
'(11 found): (moo\d*, )+ and moo9$')
|
'\(11 found\): (\'moo\d*\', )+and \'moo9\'$')
|
||||||
self.assertRegexp('listkeys *', '^Key search for \'*\' '
|
self.assertNotError('foo is bar')
|
||||||
'(12 found): foo, (moo\d*, )+ and moo9$')
|
self.assertRegexp('listkeys *', '^Key search for \'\*\' '
|
||||||
|
'\(12 found\): \'foo\', (\'moo\d*\', )+and '
|
||||||
|
'\'moo9\'$')
|
||||||
|
# Check quoting
|
||||||
|
self.assertNotError('foo\' is bar')
|
||||||
|
self.assertResponse('listkeys foo*', 'Key search for \'foo*\' '
|
||||||
|
'(2 found): \'foo\' and "foo\'"')
|
||||||
|
|
||||||
def testListvalues(self):
|
def testListvalues(self):
|
||||||
self.assertNotError('moo is <reply>moo')
|
self.assertNotError('moo is moo')
|
||||||
self.assertResponse('listvalues moo', 'Value search for \'moo\' '
|
self.assertResponse('listvalues moo', 'Value search for \'moo\' '
|
||||||
'(1 found): moo')
|
'(1 found): \'moo\'')
|
||||||
|
|
||||||
def testListauth(self):
|
def testListauth(self):
|
||||||
self.assertNotError('moo is <reply>moo')
|
self.assertNotError('moo is <reply>moo')
|
||||||
self.assertResponse('listauth tester', 'Author search for tester '
|
self.assertResponse('listauth tester', 'Author search for tester '
|
||||||
'(1 found): moo')
|
'(1 found): \'moo\'')
|
||||||
|
self.assertError('listauth moo')
|
||||||
|
|
||||||
class DunnoTestCase(PluginTestCase, PluginDocumentation):
|
# class DunnoTestCase(PluginTestCase, PluginDocumentation):
|
||||||
plugins = ('MiscCommands', 'MoobotFactoids', 'UserCommands')
|
# plugins = ('MiscCommands', 'MoobotFactoids', 'UserCommands')
|
||||||
def testDunno(self):
|
# def testDunno(self):
|
||||||
self.assertNotError('apfasdfjoia') # Should say a dunno, no error
|
# self.assertNotError('apfasdfjoia') # Should say a dunno, no error
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
Reference in New Issue
Block a user