Fix bug #1087369, WordStats is case sensitive

This commit is contained in:
James Vega 2004-12-18 04:06:53 +00:00
parent dc408473db
commit cd4f073ad5
2 changed files with 21 additions and 10 deletions

View File

@ -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
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] += 1
self[channel, id][word] += count
filename = conf.supybot.directories.data.dirize('WordStats.db')

View File

@ -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: