mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 14:14:37 +01:00
Updated Wordstats plugin to allow removal of tracked words.
This commit is contained in:
parent
f14f3efd4c
commit
823c91ff44
@ -1,3 +1,5 @@
|
|||||||
|
* Updated WordStats to allow removing of tracked words.
|
||||||
|
|
||||||
* Updated Seen.seen to accept no arguments and return the last
|
* Updated Seen.seen to accept no arguments and return the last
|
||||||
message spoken by anyone.
|
message spoken by anyone.
|
||||||
|
|
||||||
|
@ -133,6 +133,15 @@ class WordStatsDB(plugins.ChannelUserDB):
|
|||||||
if channel == chan:
|
if channel == chan:
|
||||||
if word not in d:
|
if word not in d:
|
||||||
d[word] = 0
|
d[word] = 0
|
||||||
|
|
||||||
|
def delWord(self, channel, word):
|
||||||
|
word = word.lower()
|
||||||
|
if word in self.channelWords[channel]:
|
||||||
|
del self.channelWords[channel][word]
|
||||||
|
for ((chan, id), d) in self.iteritems():
|
||||||
|
if channel == chan:
|
||||||
|
if word in d:
|
||||||
|
del d[word]
|
||||||
|
|
||||||
def addMsg(self, msg):
|
def addMsg(self, msg):
|
||||||
assert msg.command == 'PRIVMSG'
|
assert msg.command == 'PRIVMSG'
|
||||||
@ -191,6 +200,27 @@ class WordStats(callbacks.Privmsg):
|
|||||||
self.db.addWord(channel, word)
|
self.db.addWord(channel, word)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
|
|
||||||
|
def remove(self, irc, msg, args):
|
||||||
|
"""[<channel>] <word>
|
||||||
|
|
||||||
|
Removes <word> from the list of words being tracked. If <channel> is
|
||||||
|
not specified, uses current channel.
|
||||||
|
"""
|
||||||
|
channel = privmsgs.getChannel(msg, args)
|
||||||
|
word = privmsgs.getArgs(args)
|
||||||
|
words = self.db.getWords(channel)
|
||||||
|
if words:
|
||||||
|
if word in words:
|
||||||
|
self.db.delWord(channel, word)
|
||||||
|
irc.replySuccess()
|
||||||
|
else:
|
||||||
|
irc.error('%r doesn\'t look like a word I am keeping stats '
|
||||||
|
'on.' % word)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
irc.error('I am not currently keeping any word stats.')
|
||||||
|
return
|
||||||
|
|
||||||
def wordstats(self, irc, msg, args):
|
def wordstats(self, irc, msg, args):
|
||||||
"""[<channel>] [<user>] [<word>]
|
"""[<channel>] [<user>] [<word>]
|
||||||
|
|
||||||
@ -280,10 +310,15 @@ class WordStats(callbacks.Privmsg):
|
|||||||
try:
|
try:
|
||||||
L = ['%r: %s' % (word, count)
|
L = ['%r: %s' % (word, count)
|
||||||
for (word,count) in self.db.getUserWordCounts(channel,id)]
|
for (word,count) in self.db.getUserWordCounts(channel,id)]
|
||||||
L.sort()
|
if L:
|
||||||
irc.reply(utils.commaAndify(L))
|
L.sort()
|
||||||
|
irc.reply(utils.commaAndify(L))
|
||||||
|
else:
|
||||||
|
irc.error('%r doesn\'t look like a word I\'m keeping stats'
|
||||||
|
' on or a user in my database.' % user)
|
||||||
|
return
|
||||||
except KeyError:
|
except KeyError:
|
||||||
irc.reply('I have no word stats for that person.')
|
irc.error('I have no word stats for that person.')
|
||||||
Class = WordStats
|
Class = WordStats
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
@ -142,6 +142,18 @@ if sqlite is not None:
|
|||||||
def testAddword(self):
|
def testAddword(self):
|
||||||
self.assertError('add lol!')
|
self.assertError('add lol!')
|
||||||
self.assertNotError('add lolz0r')
|
self.assertNotError('add lolz0r')
|
||||||
|
self.assertRegexp('wordstats lolz0r', r'1 \'lolz0r\' seen')
|
||||||
|
|
||||||
|
def testRemoveword(self):
|
||||||
|
self.assertError('wordstats remove foo')
|
||||||
|
self.assertNotError('wordstats add foo')
|
||||||
|
self.assertRegexp('wordstats foo', r'1 \'foo\' seen')
|
||||||
|
self.assertRegexp('wordstats foo', r'2 \'foo\'s seen')
|
||||||
|
self.assertNotError('wordstats remove foo')
|
||||||
|
self.assertRegexp('wordstats foo', r'doesn\'t look like a word I')
|
||||||
|
# Verify that we aren't keeping results from before
|
||||||
|
self.assertNotError('add foo')
|
||||||
|
self.assertRegexp('wordstats foo', r'1 \'foo\' seen')
|
||||||
|
|
||||||
def testWordStatsRankingDisplay(self):
|
def testWordStatsRankingDisplay(self):
|
||||||
self.assertNotError('add lol')
|
self.assertNotError('add lol')
|
||||||
|
Loading…
Reference in New Issue
Block a user