diff --git a/plugins/Factoids/plugin.py b/plugins/Factoids/plugin.py index 3c6287dc9..98dfef394 100644 --- a/plugins/Factoids/plugin.py +++ b/plugins/Factoids/plugin.py @@ -801,7 +801,7 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler): _sqlTrans = utils.str.MultipleReplacer({'*': '%', '?': '_'}) @internationalizeDocstring def search(self, irc, msg, args, channel, optlist, globs): - """[] [--values] [--{regexp} ] [ ...] + """[] [--values] [--regexp ] [--author ] [ ...] Searches the keyspace for keys matching . If --regexp is given, its associated value is taken as a regexp and matched against the keys. @@ -810,6 +810,7 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler): if not optlist and not globs: raise callbacks.ArgumentError tables = ['keys'] + join_factoids = False formats = [] criteria = [] target = 'keys.key' @@ -818,19 +819,29 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler): for (option, arg) in optlist: if option == 'values': target = 'factoids.fact' - if 'factoids' not in tables: - tables.append('factoids') - tables.append('relations') - criteria.append('factoids.id=relations.fact_id AND keys.id=relations.key_id') + join_factoids = True elif option == 'regexp': criteria.append('%s(TARGET)' % predicateName) def p(s, r=arg): return int(bool(r.search(s))) db.create_function(predicateName, 1, p) predicateName += 'p' + elif option == 'author': + join_factoids = True + criteria.append('factoids.added_by=?') + formats.append(arg) for glob in globs: criteria.append('TARGET LIKE ?') formats.append(self._sqlTrans(glob)) + + if join_factoids: + if 'factoids' not in tables: + tables.append('factoids') + tables.append('relations') + criteria.append( + 'factoids.id=relations.fact_id AND keys.id=relations.key_id' + ) + cursor = db.cursor() sql = """SELECT keys.key FROM %s WHERE %s""" % \ (', '.join(tables), ' AND '.join(criteria)) @@ -861,7 +872,11 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler): s = format('%L', keys) irc.reply(s) search = wrap(search, ['channel', - getopts({'values': '', 'regexp': 'regexpMatcher'}), + getopts({ + 'values': '', + 'regexp': 'regexpMatcher', + 'author': 'somethingWithoutSpaces', + }), any('glob')]) diff --git a/plugins/Factoids/test.py b/plugins/Factoids/test.py index 129c38c30..1bf860ccf 100644 --- a/plugins/Factoids/test.py +++ b/plugins/Factoids/test.py @@ -112,6 +112,10 @@ class FactoidsTestCase(ChannelPluginTestCase): 'my primary author') self.assertRegexp('factoids search --values primary author', 'my primary author') + self.assertRegexp('factoids search --author test j*', + 'jamessan.*jemfinch') + self.assertRegexp('factoids search --author blahblah j*', + 'No keys matched that query.') def testWhatisOnNumbers(self): self.assertNotError('learn 911 is emergency number')