mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 22:24:20 +01:00
Added RFE #852937.
This commit is contained in:
parent
d4442a04ff
commit
f8ea57b05f
@ -1,3 +1,5 @@
|
|||||||
|
* Added a ranking to ChannelDB.wordstats.
|
||||||
|
|
||||||
* Added 'roulette' command to Fun plugin.
|
* Added 'roulette' command to Fun plugin.
|
||||||
|
|
||||||
* Added a Channel.lobotomies command to list the channels in which
|
* Added a Channel.lobotomies command to list the channels in which
|
||||||
|
@ -536,6 +536,7 @@ class ChannelDB(plugins.ChannelDBHandler,
|
|||||||
cursor.execute("""SELECT word FROM words
|
cursor.execute("""SELECT word FROM words
|
||||||
WHERE word=%s""", arg1)
|
WHERE word=%s""", arg1)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
|
# It was a user.
|
||||||
try:
|
try:
|
||||||
id = ircdb.users.getUserId(arg1)
|
id = ircdb.users.getUserId(arg1)
|
||||||
except KeyError: # Maybe it was a nick. Check the hostmask.
|
except KeyError: # Maybe it was a nick. Check the hostmask.
|
||||||
@ -556,31 +557,45 @@ class ChannelDB(plugins.ChannelDBHandler,
|
|||||||
username = ircdb.users.getUser(id).name
|
username = ircdb.users.getUser(id).name
|
||||||
irc.error(msg, '%r has no wordstats' % username)
|
irc.error(msg, '%r has no wordstats' % username)
|
||||||
return
|
return
|
||||||
l = [('%r: %s' % (word, count)) for \
|
L = [('%r: %s' % (word, count)) for \
|
||||||
(word, count) in cursor.fetchall()]
|
(word, count) in cursor.fetchall()]
|
||||||
irc.reply(msg, utils.commaAndify(l))
|
irc.reply(msg, utils.commaAndify(L))
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
# It's a word, not a user
|
# It's a word, not a user
|
||||||
word = arg1
|
word = arg1
|
||||||
cursor.execute("""SELECT word_stats.count,
|
cursor.execute("""SELECT word_stats.count,
|
||||||
word_stats.user_id
|
word_stats.user_id
|
||||||
FROM words, word_stats
|
FROM words, word_stats
|
||||||
WHERE words.word=%s
|
WHERE words.word=%s AND
|
||||||
AND words.id=word_stats.word_id
|
words.id=word_stats.word_id
|
||||||
ORDER BY word_stats.count DESC
|
ORDER BY word_stats.count DESC""", word)
|
||||||
LIMIT 3""", word)
|
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error(msg, 'No one has said %r' % word)
|
irc.error(msg, 'No one has said %r' % word)
|
||||||
return
|
return
|
||||||
results = cursor.fetchall()
|
results = cursor.fetchall()
|
||||||
s = 'Top %s: ' % utils.nItems(cursor.rowcount,
|
ers = '%rer' % word
|
||||||
'%rer' % word)
|
ret = 'Top %s: ' % utils.nItems(cursor.rowcount, ers)
|
||||||
l = []
|
L = []
|
||||||
for (count, id) in results:
|
for (count, id) in results[:3]:
|
||||||
username = ircdb.users.getUser(id).name
|
username = ircdb.users.getUser(id).name
|
||||||
l.append('%s: %s' % (username, count))
|
L.append('%s: %s' % (username, count))
|
||||||
s += utils.commaAndify(l)
|
try:
|
||||||
irc.reply(msg, s)
|
id = ircdb.users.getUserId(msg.prefix)
|
||||||
|
rank = 1
|
||||||
|
for (_, userId) in results:
|
||||||
|
if userId == id:
|
||||||
|
s = 'You are ranked %s out of %s %rers.' % \
|
||||||
|
(rank, len(L), utils.nItems(rank, ers))
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
rank += 1
|
||||||
|
else:
|
||||||
|
s = 'You have not said %r' % word
|
||||||
|
ret = '%s %s. %s' % (ret, utils.commaAndify(L), s)
|
||||||
|
except KeyError:
|
||||||
|
ret = '%s %s.' % utils.commaAndify(L)
|
||||||
|
irc.reply(msg, ret)
|
||||||
|
|
||||||
Class = ChannelDB
|
Class = ChannelDB
|
||||||
|
|
||||||
|
@ -118,18 +118,18 @@ if sqlite is not None:
|
|||||||
_ = self.irc.takeMsg()
|
_ = self.irc.takeMsg()
|
||||||
_ = self.irc.takeMsg()
|
_ = self.irc.takeMsg()
|
||||||
self.assertNotError('addword lol')
|
self.assertNotError('addword lol')
|
||||||
self.assertResponse('wordstats lol', 'Top 1 \'lol\'er: foo: 1')
|
self.assertRegexp('wordstats lol', 'foo: 1')
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol',
|
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol',
|
||||||
prefix=userPrefix1))
|
prefix=userPrefix1))
|
||||||
self.assertResponse('wordstats lol', 'Top 2 \'lol\'ers: %s: 5 '
|
self.assertRegexp('wordstats lol',
|
||||||
'and foo: 2' % userNick1)
|
'2.*%s: 5.*foo: 2' % userNick1)
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol',
|
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol',
|
||||||
prefix=userPrefix2))
|
prefix=userPrefix2))
|
||||||
self.assertResponse('wordstats lol', 'Top 3 \'lol\'ers: %s: 10, '
|
self.assertRegexp('wordstats lol',
|
||||||
'%s: 5, and foo: 3' % (\
|
'3.*%s: 10.*%s: 5.*foo: 3' %
|
||||||
userNick2, userNick1))
|
(userNick2, userNick1))
|
||||||
|
|
||||||
def testWordStatsUserWord(self):
|
def testWordStatsUserWord(self):
|
||||||
self.assertNotError('addword lol')
|
self.assertNotError('addword lol')
|
||||||
|
Loading…
Reference in New Issue
Block a user