From 84396cad9973f327320b9fd23ca08fca318b38f5 Mon Sep 17 00:00:00 2001 From: jkhsjdhjs Date: Sun, 8 Dec 2019 22:04:04 +0000 Subject: [PATCH] quotes: add global searching --- bot/quotes.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bot/quotes.py b/bot/quotes.py index c78c337..948d95b 100644 --- a/bot/quotes.py +++ b/bot/quotes.py @@ -90,7 +90,8 @@ class Quotes(DatabasePlugin): else: query = None index = args.get('') - where = '' + where = [] + values = [] # search query support if cmd or index and not is_int(index): @@ -113,11 +114,13 @@ class Quotes(DatabasePlugin): else: quote = ' '.join(quote) - values = [nick] + if nick != 'search' or not query: + where.append('nick ILIKE %s') + values.append(nick) if query: + where.append('item ILIKE \'%%\' || %s || \'%%\'') values.append(query) - where = 'AND item ILIKE \'%%\' || %s || \'%%\'' if index: index = parse_int(index) @@ -148,14 +151,13 @@ class Quotes(DatabasePlugin): FROM ranked_quotes WHERE - nick ILIKE %s {where} ORDER BY {order} LIMIT 1 {offset} - '''.format(where=where, order=order, offset=offset), values) + '''.format(where=' AND '.join(where), order=order, offset=offset), values) result = self.cur.fetchone() if result: