mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 22:24:20 +01:00
Added RFE #900293.
This commit is contained in:
parent
b15b85ea7c
commit
1cb8cd0933
@ -1,3 +1,7 @@
|
|||||||
|
* Added supybot.plugins.WordStats.ignoreQueries, which, when
|
||||||
|
true, makes the bot ignore queries (and not increment its word
|
||||||
|
statistics).
|
||||||
|
|
||||||
* Added the LogToIrc plugin, for sending logs to an IRC
|
* Added the LogToIrc plugin, for sending logs to an IRC
|
||||||
channel or nick. Useful for traceback notification and whatnot.
|
channel or nick. Useful for traceback notification and whatnot.
|
||||||
|
|
||||||
|
@ -51,11 +51,13 @@ import registry
|
|||||||
import callbacks
|
import callbacks
|
||||||
|
|
||||||
conf.registerPlugin('WordStats')
|
conf.registerPlugin('WordStats')
|
||||||
conf.registerChannelValue(conf.supybot.plugins.WordStats,
|
conf.registerChannelValue(conf.supybot.plugins.WordStats, 'rankingDisplay',
|
||||||
'rankingDisplay',
|
|
||||||
registry.PositiveInteger(3, """Determines the maximum number of top users
|
registry.PositiveInteger(3, """Determines the maximum number of top users
|
||||||
to show for a given wordstat when someone requests the wordstats for a
|
to show for a given wordstat when someone requests the wordstats for a
|
||||||
particular word."""))
|
particular word."""))
|
||||||
|
conf.registerChannelValue(conf.supybot.plugins.WordStats, 'ignoreQueries',
|
||||||
|
registry.Boolean(False, """Determines whether the bot will ignore words
|
||||||
|
said in a channel if they're in a wordstats query (command)."""))
|
||||||
|
|
||||||
nonAlphaNumeric = filter(lambda s: not s.isalnum(), string.ascii)
|
nonAlphaNumeric = filter(lambda s: not s.isalnum(), string.ascii)
|
||||||
|
|
||||||
@ -143,14 +145,16 @@ class WordStatsDB(plugins.ChannelUserDB):
|
|||||||
|
|
||||||
def addMsg(self, msg):
|
def addMsg(self, msg):
|
||||||
assert msg.command == 'PRIVMSG'
|
assert msg.command == 'PRIVMSG'
|
||||||
|
(channel, text) = msg.args
|
||||||
|
if not ircutils.isChannel(channel):
|
||||||
|
return
|
||||||
|
text = text.strip().lower()
|
||||||
|
if not text:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
id = ircdb.users.getUserId(msg.prefix)
|
id = ircdb.users.getUserId(msg.prefix)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return
|
return
|
||||||
(channel, text) = msg.args
|
|
||||||
text = text.strip().lower()
|
|
||||||
if not ircutils.isChannel(channel) or not text:
|
|
||||||
return
|
|
||||||
msgwords = [s.strip(nonAlphaNumeric) for s in text.split()]
|
msgwords = [s.strip(nonAlphaNumeric) for s in text.split()]
|
||||||
if channel not in self.channelWords:
|
if channel not in self.channelWords:
|
||||||
self.channelWords[channel] = {}
|
self.channelWords[channel] = {}
|
||||||
@ -172,6 +176,7 @@ class WordStats(callbacks.Privmsg):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
self.db = WordStatsDB(filename)
|
self.db = WordStatsDB(filename)
|
||||||
|
self.queried = False
|
||||||
world.flushers.append(self.db.flush)
|
world.flushers.append(self.db.flush)
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
@ -181,7 +186,17 @@ class WordStats(callbacks.Privmsg):
|
|||||||
callbacks.Privmsg.die(self)
|
callbacks.Privmsg.die(self)
|
||||||
|
|
||||||
def doPrivmsg(self, irc, msg):
|
def doPrivmsg(self, irc, msg):
|
||||||
|
# This depends on the fact that it's called after the command.
|
||||||
|
try:
|
||||||
|
channel = msg.args[0]
|
||||||
|
if ircutils.isChannel(channel):
|
||||||
|
if not (self.queried and
|
||||||
|
self.registryValue('ignoreQueries', channel)):
|
||||||
self.db.addMsg(msg)
|
self.db.addMsg(msg)
|
||||||
|
else:
|
||||||
|
self.log.debug('Queried and ignoring.')
|
||||||
|
finally:
|
||||||
|
self.queried = False
|
||||||
|
|
||||||
def add(self, irc, msg, args):
|
def add(self, irc, msg, args):
|
||||||
"""[<channel>] <word>
|
"""[<channel>] <word>
|
||||||
@ -196,6 +211,7 @@ class WordStats(callbacks.Privmsg):
|
|||||||
irc.error('<word> must not contain non-alphanumeric chars.')
|
irc.error('<word> must not contain non-alphanumeric chars.')
|
||||||
return
|
return
|
||||||
self.db.addWord(channel, word)
|
self.db.addWord(channel, word)
|
||||||
|
self.queried = True
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
|
|
||||||
def remove(self, irc, msg, args):
|
def remove(self, irc, msg, args):
|
||||||
@ -260,12 +276,18 @@ class WordStats(callbacks.Privmsg):
|
|||||||
if count:
|
if count:
|
||||||
s = '%s has said %r %s.' % \
|
s = '%s has said %r %s.' % \
|
||||||
(user, word, utils.nItems('time', count))
|
(user, word, utils.nItems('time', count))
|
||||||
|
self.queried = True
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
else:
|
else:
|
||||||
irc.error('%s has never said %r.' % (user, word))
|
irc.error('%s has never said %r.' % (user, word))
|
||||||
elif arg1 in WordDict.fromkeys(self.db.getWords(channel)):
|
elif arg1 in WordDict.fromkeys(self.db.getWords(channel)):
|
||||||
word = arg1
|
word = arg1
|
||||||
total = self.db.getTotalWordCount(channel, word)
|
total = self.db.getTotalWordCount(channel, word)
|
||||||
|
if total == 0:
|
||||||
|
irc.reply('I\'m keeping stats on %s, but I haven\'t seen it '
|
||||||
|
'in this channel.' % word)
|
||||||
|
self.queried = True
|
||||||
|
return
|
||||||
n = self.registryValue('rankingDisplay', channel)
|
n = self.registryValue('rankingDisplay', channel)
|
||||||
try:
|
try:
|
||||||
id = ircdb.users.getUserId(msg.prefix)
|
id = ircdb.users.getUserId(msg.prefix)
|
||||||
@ -296,6 +318,7 @@ class WordStats(callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
s = ''
|
s = ''
|
||||||
ret = '%s %s.%s' % (ret, utils.commaAndify(L), s)
|
ret = '%s %s.%s' % (ret, utils.commaAndify(L), s)
|
||||||
|
self.queried = True
|
||||||
irc.reply(ret)
|
irc.reply(ret)
|
||||||
else:
|
else:
|
||||||
user = arg1
|
user = arg1
|
||||||
|
@ -33,14 +33,8 @@ from testsupport import *
|
|||||||
|
|
||||||
import ircdb
|
import ircdb
|
||||||
|
|
||||||
try:
|
|
||||||
import sqlite
|
|
||||||
except ImportError:
|
|
||||||
sqlite = None
|
|
||||||
|
|
||||||
if sqlite is not None:
|
|
||||||
class WordStatsTestCase(ChannelPluginTestCase):
|
class WordStatsTestCase(ChannelPluginTestCase):
|
||||||
plugins = ('WordStats', 'User')
|
plugins = ('WordStats', 'User', 'Utilities')
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
ChannelPluginTestCase.setUp(self)
|
ChannelPluginTestCase.setUp(self)
|
||||||
self.prefix = 'foo!bar@baz'
|
self.prefix = 'foo!bar@baz'
|
||||||
@ -181,5 +175,20 @@ if sqlite is not None:
|
|||||||
finally:
|
finally:
|
||||||
conf.supybot.plugins.WordStats.rankingDisplay.setValue(orig)
|
conf.supybot.plugins.WordStats.rankingDisplay.setValue(orig)
|
||||||
|
|
||||||
|
def testWordStatsIgnoreQueries(self):
|
||||||
|
try:
|
||||||
|
original = conf.supybot.plugins.WordStats.ignoreQueries()
|
||||||
|
conf.supybot.plugins.WordStats.ignoreQueries.setValue(True)
|
||||||
|
self.assertNotError('add lol')
|
||||||
|
self.assertNotRegexp('wordstats lol', 'foo')
|
||||||
|
self.assertNotRegexp('wordstats lol', 'foo')
|
||||||
|
self.assertNotRegexp('wordstats lol', 'foo')
|
||||||
|
self.assertNotError('echo lol')
|
||||||
|
self.assertRegexp('wordstats lol', 'foo: 1')
|
||||||
|
self.assertRegexp('wordstats lol', 'foo: 1')
|
||||||
|
self.assertRegexp('wordstats lol', 'foo: 1')
|
||||||
|
finally:
|
||||||
|
conf.supybot.plugins.WordStats.ignoreQueries.setValue(original)
|
||||||
|
|
||||||
# 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