mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-02 17:29:22 +01:00
Add Later note expiration period, 30 days by default.
This should prevent the accumulation of old unclaimed notes in the database, which is possible due to notes left to misspelled nicks, to temporary nicks used by regulars, or to one-time visitor nicks.
This commit is contained in:
parent
e4c51ef517
commit
9c12f80285
@ -48,5 +48,9 @@ conf.registerGlobalValue(Later, 'private',
|
||||
conf.registerGlobalValue(Later, 'tellOnJoin',
|
||||
registry.Boolean(True, """Determines whether users will be notified upon
|
||||
joining any channel the bot is in, or only upon sending a message."""))
|
||||
|
||||
conf.registerGlobalValue(Later, 'messageExpiry',
|
||||
registry.NonNegativeInteger(30, """Determines the maximum number of
|
||||
days that a message will remain queued for a user. After this time elapses,
|
||||
the message will be deleted. If this value is 0, there is no maximum."""))
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
import csv
|
||||
import time
|
||||
import datetime
|
||||
|
||||
import supybot.log as log
|
||||
import supybot.conf as conf
|
||||
@ -118,6 +119,31 @@ class Later(callbacks.Plugin):
|
||||
return nick[:-1]
|
||||
return nick
|
||||
|
||||
def _deleteExpired(self):
|
||||
expiry = self.registryValue('messageExpiry')
|
||||
curtime = time.time()
|
||||
nickremovals=[]
|
||||
for (nick, notes) in self._notes.iteritems():
|
||||
removals = []
|
||||
for (notetime, whence, text) in notes:
|
||||
td = datetime.timedelta(seconds=(curtime - notetime))
|
||||
if td.days > expiry:
|
||||
removals.append((notetime, whence, text))
|
||||
for note in removals:
|
||||
notes.remove(note)
|
||||
if len(notes) == 0:
|
||||
nickremovals.append(nick)
|
||||
for nick in nickremovals:
|
||||
del self._notes[nick]
|
||||
self._flushNotes()
|
||||
|
||||
## Note: we call _deleteExpired from 'tell'. This means that it's possible
|
||||
## for expired notes to remain in the database for longer than the maximum,
|
||||
## if no tell's are called.
|
||||
## However, the whole point of this is to avoid crud accumulation in the
|
||||
## database, so it's fine that we only delete expired notes when we try
|
||||
## adding new ones.
|
||||
|
||||
def tell(self, irc, msg, args, nick, text):
|
||||
"""<nick> <text>
|
||||
|
||||
@ -125,6 +151,7 @@ class Later(callbacks.Plugin):
|
||||
contain wildcard characters, and the first matching nick will be
|
||||
given the note.
|
||||
"""
|
||||
self._deleteExpired()
|
||||
if ircutils.strEqual(nick, irc.nick):
|
||||
irc.error('I can\'t send notes to myself.')
|
||||
return
|
||||
|
@ -28,6 +28,7 @@
|
||||
###
|
||||
|
||||
from supybot.test import *
|
||||
import time
|
||||
|
||||
class LaterTestCase(PluginTestCase):
|
||||
plugins = ('Later',)
|
||||
@ -52,5 +53,14 @@ class LaterTestCase(PluginTestCase):
|
||||
self.assertRegexp('later notes', 'foo\.')
|
||||
conf.supybot.protocols.irc.strictRfc.setValue(origconf)
|
||||
|
||||
def testNoteExpiry(self):
|
||||
cb = self.irc.getCallback('Later')
|
||||
# add a note 40 days in the past
|
||||
cb._addNote('foo', 'test', 'some stuff', at=(time.time() - 3456000))
|
||||
self.assertRegexp('later notes', 'foo')
|
||||
self.assertNotError('later tell moo stuff')
|
||||
self.assertNotRegexp('later notes', 'foo')
|
||||
self.assertRegexp('later notes', 'moo')
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user