mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 22:24:20 +01:00
Added an addword test and fixed the wordstats failures.
This commit is contained in:
parent
5081016c2f
commit
1a4780b854
@ -39,6 +39,7 @@ import re
|
|||||||
import sets
|
import sets
|
||||||
import time
|
import time
|
||||||
import getopt
|
import getopt
|
||||||
|
import string
|
||||||
|
|
||||||
import sqlite
|
import sqlite
|
||||||
|
|
||||||
@ -151,6 +152,8 @@ class ChannelDB(callbacks.Privmsg,plugins.Toggleable,plugins.ChannelDBHandler):
|
|||||||
self._updatePrivmsgStats(msg)
|
self._updatePrivmsgStats(msg)
|
||||||
self._updateWordStats(msg)
|
self._updateWordStats(msg)
|
||||||
|
|
||||||
|
_alphanumeric = string.ascii_letters + string.digits
|
||||||
|
_nonAlphanumeric = string.ascii.translate(string.ascii, _alphanumeric)
|
||||||
def _updateWordStats(self, msg):
|
def _updateWordStats(self, msg):
|
||||||
try:
|
try:
|
||||||
if self.outFiltering:
|
if self.outFiltering:
|
||||||
@ -163,6 +166,7 @@ class ChannelDB(callbacks.Privmsg,plugins.Toggleable,plugins.ChannelDBHandler):
|
|||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
words = s.lower().split()
|
words = s.lower().split()
|
||||||
|
words = [s.strip(self._nonAlphanumeric) for s in words]
|
||||||
criteria = ['word=%s'] * len(words)
|
criteria = ['word=%s'] * len(words)
|
||||||
criterion = ' OR '.join(criteria)
|
criterion = ' OR '.join(criteria)
|
||||||
cursor.execute("SELECT id, word FROM words WHERE %s"%criterion, *words)
|
cursor.execute("SELECT id, word FROM words WHERE %s"%criterion, *words)
|
||||||
@ -447,8 +451,8 @@ class ChannelDB(callbacks.Privmsg,plugins.Toggleable,plugins.ChannelDBHandler):
|
|||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
word = privmsgs.getArgs(args)
|
word = privmsgs.getArgs(args)
|
||||||
word = word.strip()
|
word = word.strip()
|
||||||
if len(word.split()) > 1:
|
if word.strip(self._nonAlphanumeric) != word:
|
||||||
irc.error(msg, 'You can\'t have spaces in <word>.')
|
irc.error(msg, '<word> must not contain non-alphanumeric chars.')
|
||||||
return
|
return
|
||||||
word = word.lower()
|
word = word.lower()
|
||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
|
@ -121,5 +121,9 @@ if sqlite is not None:
|
|||||||
self.assertResponse('wordstats foo heh',
|
self.assertResponse('wordstats foo heh',
|
||||||
'foo has said \'heh\' 4 times.')
|
'foo has said \'heh\' 4 times.')
|
||||||
|
|
||||||
|
def testAddword(self):
|
||||||
|
self.assertError('addword lol!')
|
||||||
|
self.assertNotError('addword lolz0r')
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user