mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Converted Seen to use the ChannelUserDB.
This commit is contained in:
parent
097d4e93d6
commit
18fcfd9335
@ -57,49 +57,20 @@ import privmsgs
|
|||||||
import registry
|
import registry
|
||||||
import callbacks
|
import callbacks
|
||||||
|
|
||||||
class SeenDB(object):
|
class SeenDB(plugins.ChannelUserDatabase):
|
||||||
def __init__(self, filename):
|
def serialize(self, v):
|
||||||
self.filename = filename
|
return list(v)
|
||||||
self.channels = ircutils.IrcDict()
|
|
||||||
try:
|
|
||||||
fd = file(filename)
|
|
||||||
except EnvironmentError, e:
|
|
||||||
log.info('Couldn\'t open %s: %s', filename, e)
|
|
||||||
return
|
|
||||||
lineno = 0
|
|
||||||
for line in fd:
|
|
||||||
lineno += 1
|
|
||||||
line = line.rstrip('\r\n')
|
|
||||||
(channel, nickOrId, when, said) = line.split(':', 3)
|
|
||||||
if channel not in self.channels:
|
|
||||||
self.channels[channel] = ircutils.IrcDict()
|
|
||||||
try:
|
|
||||||
self.channels[channel][nickOrId] = (float(when), said)
|
|
||||||
except ValueError: # Invalid float.
|
|
||||||
log.warning('Invalid line #%s in %s: %s',lineno,filename,line)
|
|
||||||
continue
|
|
||||||
fd.close()
|
|
||||||
|
|
||||||
def flush(self):
|
def deserialize(self, L):
|
||||||
fd = file(self.filename, 'w')
|
(seen, saying) = L
|
||||||
for (channel, d) in self.channels.iteritems():
|
return (float(seen), saying)
|
||||||
for (nickOrId, (when, said)) in d.iteritems():
|
|
||||||
fd.write('%s:%s:%s:%s\n' % (channel, nickOrId, when, said))
|
|
||||||
fd.close()
|
|
||||||
|
|
||||||
def close(self):
|
def update(self, channel, nickOrId, saying):
|
||||||
self.flush()
|
seen = time.time()
|
||||||
self.channels.clear()
|
self[channel, nickOrId] = (seen, saying)
|
||||||
|
|
||||||
def update(self, channel, nickOrId, said):
|
|
||||||
if channel not in self.channels:
|
|
||||||
self.channels[channel] = ircutils.IrcDict()
|
|
||||||
when = time.time()
|
|
||||||
self.channels[channel][str(nickOrId)] = (when, said)
|
|
||||||
|
|
||||||
def seen(self, channel, nickOrId):
|
def seen(self, channel, nickOrId):
|
||||||
return self.channels[channel][str(nickOrId)]
|
return self[channel, nickOrId]
|
||||||
|
|
||||||
|
|
||||||
filename = os.path.join(conf.supybot.directories.data(), 'Seen.db')
|
filename = os.path.join(conf.supybot.directories.data(), 'Seen.db')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user