mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-02 17:29:22 +01:00
Fixed several bugz0rs.
This commit is contained in:
parent
e989cd4bc1
commit
bb74f518a1
@ -65,34 +65,36 @@ class HeraldDB(object):
|
|||||||
self.open()
|
self.open()
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
fd = file(os.path.join(conf.dataDir, 'Herald.db'))
|
filename = os.path.join(conf.dataDir, 'Herald.db')
|
||||||
for line in fd:
|
if os.path.exists(filename):
|
||||||
line = line.rstrip()
|
fd = file(filename)
|
||||||
try:
|
for line in fd:
|
||||||
(idChannel, msg) = line.split(':', 1)
|
line = line.rstrip()
|
||||||
(id, channel) = idChannel.split(',', 1)
|
try:
|
||||||
id = int(id)
|
(idChannel, msg) = line.split(':', 1)
|
||||||
except ValueError:
|
(id, channel) = idChannel.split(',', 1)
|
||||||
log.warning('Invalid line in HeraldDB: %r', line)
|
id = int(id)
|
||||||
continue
|
except ValueError:
|
||||||
self.heralds[id] = msg
|
log.warning('Invalid line in HeraldDB: %r', line)
|
||||||
fd.close()
|
continue
|
||||||
|
self.heralds[(id, channel)] = msg
|
||||||
|
fd.close()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
fd = file(os.path.join(conf.dataDir, 'Herald.db'), 'w')
|
fd = file(os.path.join(conf.dataDir, 'Herald.db'), 'w')
|
||||||
L = self.heralds.items()
|
L = self.heralds.items()
|
||||||
L.sort()
|
L.sort()
|
||||||
for (id, msg) in L:
|
for ((id, channel), msg) in L:
|
||||||
fd.write('%s:%s%s' % (id, msg, os.linesep))
|
fd.write('%s,%s:%s%s' % (id, channel, msg, os.linesep))
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
def getHerald(id, channel):
|
def getHerald(self, id, channel):
|
||||||
return self.heralds[(id, channel)]
|
return self.heralds[(id, channel)]
|
||||||
|
|
||||||
def setHerald(id, channel, msg):
|
def setHerald(self, id, channel, msg):
|
||||||
self.heralds[(id, channel)] = msg
|
self.heralds[(id, channel)] = msg
|
||||||
|
|
||||||
def delHerald(id, channel):
|
def delHerald(self, id, channel):
|
||||||
del self.heralds[(id, channel)]
|
del self.heralds[(id, channel)]
|
||||||
|
|
||||||
|
|
||||||
@ -109,14 +111,16 @@ class Herald(callbacks.Privmsg, configurable.Mixin):
|
|||||||
bot will not herald the person when he or she rejoins."""),]
|
bot will not herald the person when he or she rejoins."""),]
|
||||||
)
|
)
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
callbacks.Privmsg.__init__(self)
|
||||||
|
configurable.Mixin.__init__(self)
|
||||||
self.db = HeraldDB()
|
self.db = HeraldDB()
|
||||||
self.lastParts = {}
|
self.lastParts = {}
|
||||||
self.lastHerald = {}
|
self.lastHerald = {}
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
self.db.close()
|
self.db.close()
|
||||||
callbacks.Privmsg.die()
|
callbacks.Privmsg.die(self)
|
||||||
configurable.Mixin.die()
|
configurable.Mixin.die(self)
|
||||||
|
|
||||||
def doJoin(self, irc, msg):
|
def doJoin(self, irc, msg):
|
||||||
channel = msg.args[0]
|
channel = msg.args[0]
|
||||||
@ -128,7 +132,7 @@ class Herald(callbacks.Privmsg, configurable.Mixin):
|
|||||||
return
|
return
|
||||||
now = time.time()
|
now = time.time()
|
||||||
throttle = self.configurables.get('throttle-time', channel)
|
throttle = self.configurables.get('throttle-time', channel)
|
||||||
if now - self.lastHeralds[(id, channel)] > throttle:
|
if now - self.lastHerald.get((id, channel), 0) > throttle:
|
||||||
if (id, channel) in self.lastParts:
|
if (id, channel) in self.lastParts:
|
||||||
i = self.configurables.get('throttle-after-part', channel)
|
i = self.configurables.get('throttle-after-part', channel)
|
||||||
if now - self.lastParts[(id, channel)] < i:
|
if now - self.lastParts[(id, channel)] < i:
|
||||||
@ -147,6 +151,7 @@ class Herald(callbacks.Privmsg, configurable.Mixin):
|
|||||||
id = ircdb.users.getUserId(hostmask)
|
id = ircdb.users.getUserId(hostmask)
|
||||||
else:
|
else:
|
||||||
raise KeyError
|
raise KeyError
|
||||||
|
return id
|
||||||
|
|
||||||
def add(self, irc, msg, args):
|
def add(self, irc, msg, args):
|
||||||
"""[<channel>] <user|nick|hostmask> <msg>
|
"""[<channel>] <user|nick|hostmask> <msg>
|
||||||
|
Loading…
Reference in New Issue
Block a user