From cd4f073ad558f0c29e77cb185cd73a629a1978e8 Mon Sep 17 00:00:00 2001 From: James Vega Date: Sat, 18 Dec 2004 04:06:53 +0000 Subject: [PATCH] Fix bug #1087369, WordStats is case sensitive --- plugins/WordStats.py | 20 ++++++++++---------- test/test_WordStats.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/plugins/WordStats.py b/plugins/WordStats.py index 1667b99e9..799defd43 100644 --- a/plugins/WordStats.py +++ b/plugins/WordStats.py @@ -158,19 +158,19 @@ class WordStatsDB(plugins.ChannelUserDB): id = ircdb.users.getUserId(msg.prefix) except KeyError: return - msgwords = [s.strip(nonAlphaNumeric) for s in text.split()] + msgwords = [s.strip(nonAlphaNumeric).lower() for s in text.split()] if channel not in self.channelWords: self.channelWords[channel] = {} for word in self.channelWords[channel]: - word = word.lower() - for msgword in msgwords: - if msgword == word: - self.channelWords[channel][word] += 1 - if (channel, id) not in self: - self[channel, id] = {} - if word not in self[channel, id]: - self[channel, id][word] = 0 - self[channel, id][word] += 1 + lword = word.lower() + count = msgwords.count(lword) + if count: + self.channelWords[channel][word] += count + if (channel, id) not in self: + self[channel, id] = {} + if word not in self[channel, id]: + self[channel, id][word] = 0 + self[channel, id][word] += count filename = conf.supybot.directories.data.dirize('WordStats.db') diff --git a/test/test_WordStats.py b/test/test_WordStats.py index dd038e657..3c0d226dd 100644 --- a/test/test_WordStats.py +++ b/test/test_WordStats.py @@ -191,5 +191,16 @@ class WordStatsTestCase(ChannelPluginTestCase): finally: conf.supybot.plugins.WordStats.ignoreQueries.setValue(original) + def testWordStatsCaseInsensitive(self): + self.assertNotError('add lol') + self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lOL', + prefix=self.prefix)) + self.assertRegexp('wordstats foo', r'[\'"]lol[\'"]: 2') + self.assertNotError('add MOO') + self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'mOo', + prefix=self.prefix)) + self.assertRegexp('wordstats foo', + r'(lol|MOO)[\'"]: 2 and [\'"](lol|MOO)[\'"]: 2') + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: