ddipaolo suggested switching from a tuple to a dictionary to make things more

intuitive (if we even decide to keep this format)
This commit is contained in:
James Vega 2003-11-06 18:31:56 +00:00
parent ac97573d92
commit ea81e966ff

View File

@ -483,28 +483,31 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
# 5) the word which describes what we are generating statistics about. # 5) the word which describes what we are generating statistics about.
# This will be used in the string from 4) # This will be used in the string from 4)
_mostDict = {'popular': _mostDict = {'popular':
("""SELECT key,requested_count FROM factoids WHERE {'sql':"""SELECT key,requested_count FROM factoids WHERE
requested_count > 0 ORDER by requested_count DESC requested_count > 0 ORDER by requested_count DESC
LIMIT %s""", LIMIT %s""",
'%s (%s)', 'format':'%s (%s)',
lambda c: [(t[0], t[1]) for t in c], 'genlist':lambda c: [(t[0], t[1]) for t in c],
'Top %s %s: %s', 'head':'Top %s %s: %s',
'factoid'), 'desc':'factoid'
},
'authored': 'authored':
("""SELECT count(key),created_by FROM factoids GROUP BY {'sql':"""SELECT count(key),created_by FROM factoids GROUP
created_by ORDER BY created_by DESC LIMIT %s""", BY created_by ORDER BY created_by DESC LIMIT %s""",
'%s (%s)', 'format':'%s (%s)',
lambda c: [(ircdb.users.getUser(t[1]).name, t[0]) for t 'genlist':lambda c: [(ircdb.users.getUser(t[1]).name,
in c], t[0]) for t in c],
'Top %s %s: %s', 'head':'Top %s %s: %s',
'author'), 'desc':'author'
},
'recent': 'recent':
("""SELECT key FROM factoids ORDER by created_at DESC LIMIT {'sql':"""SELECT key FROM factoids ORDER by created_at DESC
%s""", LIMIT %s""",
'%s', 'format':'%s',
lambda c: [t[0] for t in c], 'genlist':lambda c: [t[0] for t in c],
'%s latest %s: %s', 'head':'%s latest %s: %s',
'factoid') 'desc':'factoid'
}
} }
def most(self, irc, msg, args): def most(self, irc, msg, args):
"""<popular|authored|recent> """<popular|authored|recent>
@ -518,14 +521,15 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
if arg in self._mostDict: if arg in self._mostDict:
args = self._mostDict[arg] args = self._mostDict[arg]
cursor = self.db.cursor() cursor = self.db.cursor()
cursor.execute(args[0] % self._mostCount) cursor.execute(args['sql'] % self._mostCount)
if cursor.rowcount == 0: if cursor.rowcount == 0:
irc.reply(msg, 'I can\'t find any factoids.') irc.reply(msg, 'I can\'t find any factoids.')
else: 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) l = len(resp)
irc.reply(msg, args[3] % (l, utils.pluralize(l, args[4]), irc.reply(msg, args['head'] % (l, utils.pluralize(l,
utils.commaAndify(resp))) args['desc']), utils.commaAndify(resp)))
else: else:
raise callbacks.ArgumentError raise callbacks.ArgumentError