mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +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
dfeb50de2d
commit
a6d92a70e8
@ -51,5 +51,9 @@ conf.registerGlobalValue(Later, 'private',
|
|||||||
conf.registerGlobalValue(Later, 'tellOnJoin',
|
conf.registerGlobalValue(Later, 'tellOnJoin',
|
||||||
registry.Boolean(True, _("""Determines whether users will be notified upon
|
registry.Boolean(True, _("""Determines whether users will be notified upon
|
||||||
joining any channel the bot is in, or only upon sending a message.""")))
|
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:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
import csv
|
import csv
|
||||||
import time
|
import time
|
||||||
|
import datetime
|
||||||
|
|
||||||
import supybot.log as log
|
import supybot.log as log
|
||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
@ -120,6 +121,31 @@ class Later(callbacks.Plugin):
|
|||||||
return nick[:-1]
|
return nick[:-1]
|
||||||
return nick
|
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.
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def tell(self, irc, msg, args, nick, text):
|
def tell(self, irc, msg, args, nick, text):
|
||||||
"""<nick> <text>
|
"""<nick> <text>
|
||||||
@ -128,6 +154,7 @@ class Later(callbacks.Plugin):
|
|||||||
contain wildcard characters, and the first matching nick will be
|
contain wildcard characters, and the first matching nick will be
|
||||||
given the note.
|
given the note.
|
||||||
"""
|
"""
|
||||||
|
self._deleteExpired()
|
||||||
if ircutils.strEqual(nick, irc.nick):
|
if ircutils.strEqual(nick, irc.nick):
|
||||||
irc.error(_('I can\'t send notes to myself.'))
|
irc.error(_('I can\'t send notes to myself.'))
|
||||||
return
|
return
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
###
|
###
|
||||||
|
|
||||||
from supybot.test import *
|
from supybot.test import *
|
||||||
|
import time
|
||||||
|
|
||||||
class LaterTestCase(PluginTestCase):
|
class LaterTestCase(PluginTestCase):
|
||||||
plugins = ('Later',)
|
plugins = ('Later',)
|
||||||
@ -52,5 +53,14 @@ class LaterTestCase(PluginTestCase):
|
|||||||
self.assertRegexp('later notes', 'foo\.')
|
self.assertRegexp('later notes', 'foo\.')
|
||||||
conf.supybot.protocols.irc.strictRfc.setValue(origconf)
|
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:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user