mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 19:22:45 +01:00
some enhancements Factoids.rank:
output options: plain key output, and alpha sorting for plain output. allow an optional argument for how many ranked facts to show.
This commit is contained in:
parent
7c3bc67c86
commit
8ed94257ba
@ -385,28 +385,56 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
alias = wrap(alias, ['channel', 'something', 'something', optional('int')])
|
alias = wrap(alias, ['channel', 'something', 'something', optional('int')])
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def rank(self, irc, msg, args, channel):
|
def rank(self, irc, msg, args, channel, optlist, number):
|
||||||
"""[<channel>]
|
"""[<channel>] [--plain] [--alpha] [<number>]
|
||||||
|
|
||||||
Returns a list of top-ranked factoid keys, sorted by usage count
|
Returns a list of top-ranked factoid keys, sorted by usage count
|
||||||
(rank). The number of factoid keys returned is set by the
|
(rank). If <number> is not provided, the default number of factoid keys
|
||||||
rankListLength registry value. <channel> is only necessary if the
|
returned is set by the rankListLength registry value.
|
||||||
message isn't sent in the channel itself.
|
|
||||||
|
If --plain option is given, rank numbers and usage counts are not
|
||||||
|
included in output.
|
||||||
|
|
||||||
|
If --alpha option is given in addition to --plain, keys are sorted
|
||||||
|
alphabetically, instead of by rank.
|
||||||
|
|
||||||
|
<channel> is only necessary if the message isn't sent in the channel
|
||||||
|
itself.
|
||||||
"""
|
"""
|
||||||
numfacts = self.registryValue('rankListLength', channel)
|
if not number:
|
||||||
|
number = self.registryValue('rankListLength', channel)
|
||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT keys.key, relations.usage_count
|
cursor.execute("""SELECT keys.key, relations.usage_count
|
||||||
FROM keys, relations
|
FROM keys, relations
|
||||||
WHERE relations.key_id=keys.id
|
WHERE relations.key_id=keys.id
|
||||||
ORDER BY relations.usage_count DESC
|
ORDER BY relations.usage_count DESC
|
||||||
LIMIT ?""", (numfacts,))
|
LIMIT ?""", (number,))
|
||||||
factkeys = cursor.fetchall()
|
factkeys = cursor.fetchall()
|
||||||
s = [ "#%d %s (%d)" % (i+1, key[0], key[1]) for i, key in enumerate(factkeys) ]
|
plain=False
|
||||||
|
alpha=False
|
||||||
|
for (option, arg) in optlist:
|
||||||
|
if option == 'plain':
|
||||||
|
plain = True
|
||||||
|
elif option =='alpha':
|
||||||
|
alpha = True
|
||||||
|
if plain:
|
||||||
|
s = [ "%s" % (key[0],) for i, key in enumerate(factkeys) ]
|
||||||
|
if alpha:
|
||||||
|
s.sort()
|
||||||
|
else:
|
||||||
|
s = [ "#%d %s (%d)" % (i+1, key[0], key[1]) for i, key in enumerate(factkeys) ]
|
||||||
irc.reply(", ".join(s))
|
irc.reply(", ".join(s))
|
||||||
|
<<<<<<< HEAD
|
||||||
rank = wrap(rank, ['channel'])
|
rank = wrap(rank, ['channel'])
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
|
=======
|
||||||
|
rank = wrap(rank, ['channel',
|
||||||
|
getopts({'plain': '', 'alpha': '',}),
|
||||||
|
optional('int')])
|
||||||
|
|
||||||
|
>>>>>>> f1517a7... some enhancements Factoids.rank:
|
||||||
def lock(self, irc, msg, args, channel, key):
|
def lock(self, irc, msg, args, channel, key):
|
||||||
"""[<channel>] <key>
|
"""[<channel>] <key>
|
||||||
|
|
||||||
|
@ -189,6 +189,11 @@ class FactoidsTestCase(ChannelPluginTestCase):
|
|||||||
self.assertRegexp('factoids rank', '#1 foo \(0\), #2 moo \(0\)')
|
self.assertRegexp('factoids rank', '#1 foo \(0\), #2 moo \(0\)')
|
||||||
self.assertRegexp('whatis moo', '.*cow.*')
|
self.assertRegexp('whatis moo', '.*cow.*')
|
||||||
self.assertRegexp('factoids rank', '#1 moo \(1\), #2 foo \(0\)')
|
self.assertRegexp('factoids rank', '#1 moo \(1\), #2 foo \(0\)')
|
||||||
|
self.assertRegexp('factoids rank 1', '#1 moo \(1\)')
|
||||||
|
self.assertNotRegexp('factoids rank 1', 'foo')
|
||||||
|
self.assertRegexp('factoids rank --plain', 'moo, foo')
|
||||||
|
self.assertRegexp('factoids rank --plain --alpha', 'foo, moo')
|
||||||
|
self.assertResponse('factoids rank --plain 1', 'moo')
|
||||||
|
|
||||||
def testQuoteHandling(self):
|
def testQuoteHandling(self):
|
||||||
self.assertNotError('learn foo as "\\"bar\\""')
|
self.assertNotError('learn foo as "\\"bar\\""')
|
||||||
|
Loading…
Reference in New Issue
Block a user