From ea81e966ff45e6b439ab4dbbe4d29fa4734c41fe Mon Sep 17 00:00:00 2001 From: James Vega Date: Thu, 6 Nov 2003 18:31:56 +0000 Subject: [PATCH] ddipaolo suggested switching from a tuple to a dictionary to make things more intuitive (if we even decide to keep this format) --- plugins/MoobotFactoids.py | 52 +++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/plugins/MoobotFactoids.py b/plugins/MoobotFactoids.py index 5157d6f80..b38a0b034 100644 --- a/plugins/MoobotFactoids.py +++ b/plugins/MoobotFactoids.py @@ -483,28 +483,31 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): # 5) the word which describes what we are generating statistics about. # This will be used in the string from 4) _mostDict = {'popular': - ("""SELECT key,requested_count FROM factoids WHERE - requested_count > 0 ORDER by requested_count DESC - LIMIT %s""", - '%s (%s)', - lambda c: [(t[0], t[1]) for t in c], - 'Top %s %s: %s', - 'factoid'), + {'sql':"""SELECT key,requested_count FROM factoids WHERE + requested_count > 0 ORDER by requested_count DESC + LIMIT %s""", + 'format':'%s (%s)', + 'genlist':lambda c: [(t[0], t[1]) for t in c], + 'head':'Top %s %s: %s', + 'desc':'factoid' + }, 'authored': - ("""SELECT count(key),created_by FROM factoids GROUP BY - created_by ORDER BY created_by DESC LIMIT %s""", - '%s (%s)', - lambda c: [(ircdb.users.getUser(t[1]).name, t[0]) for t - in c], - 'Top %s %s: %s', - 'author'), + {'sql':"""SELECT count(key),created_by FROM factoids GROUP + BY created_by ORDER BY created_by DESC LIMIT %s""", + 'format':'%s (%s)', + 'genlist':lambda c: [(ircdb.users.getUser(t[1]).name, + t[0]) for t in c], + 'head':'Top %s %s: %s', + 'desc':'author' + }, 'recent': - ("""SELECT key FROM factoids ORDER by created_at DESC LIMIT - %s""", - '%s', - lambda c: [t[0] for t in c], - '%s latest %s: %s', - 'factoid') + {'sql':"""SELECT key FROM factoids ORDER by created_at DESC + LIMIT %s""", + 'format':'%s', + 'genlist':lambda c: [t[0] for t in c], + 'head':'%s latest %s: %s', + 'desc':'factoid' + } } def most(self, irc, msg, args): """ @@ -518,14 +521,15 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): if arg in self._mostDict: args = self._mostDict[arg] cursor = self.db.cursor() - cursor.execute(args[0] % self._mostCount) + cursor.execute(args['sql'] % self._mostCount) if cursor.rowcount == 0: irc.reply(msg, 'I can\'t find any factoids.') else: - resp = [args[1] % t for t in args[2](cursor.fetchall())] + resp = [args['format'] % t for t in args['genlist']( + cursor.fetchall())] l = len(resp) - irc.reply(msg, args[3] % (l, utils.pluralize(l, args[4]), - utils.commaAndify(resp))) + irc.reply(msg, args['head'] % (l, utils.pluralize(l, + args['desc']), utils.commaAndify(resp))) else: raise callbacks.ArgumentError