ID are keept when an event is not finished

This commit is contained in:
Némunaire 2012-09-02 18:40:44 +02:00
parent 642c5ef502
commit af3ec01734
2 changed files with 17 additions and 10 deletions

21
bot.py
View File

@ -59,14 +59,17 @@ class Bot:
self.msg_thrd_size = -1
def add_event(self, evt):
def add_event(self, evt, eid=None):
"""Register an event and return its identifiant for futur update"""
# Find an ID
now = datetime.now()
evt.id = "%d%c%d%d%c%d%d%c%d" % (now.year, ID_letters[now.microsecond % 52],
now.month, now.day, ID_letters[now.microsecond % 42],
now.hour, now.minute, ID_letters[now.microsecond % 32],
now.second)
if eid is None:
# Find an ID
now = datetime.now()
evt.id = "%d%c%d%d%c%d%d%c%d" % (now.year, ID_letters[now.microsecond % 52],
now.month, now.day, ID_letters[now.microsecond % 42],
now.hour, now.minute, ID_letters[now.microsecond % 32],
now.second)
else:
evt.id = eid
# Add the event in place
t = evt.current
@ -78,6 +81,8 @@ class Bot:
self.events.insert(i + 1, evt)
if i == -1:
self.update_timer()
if len(self.events) <= 0 or self.events[i+1] != evt:
return None
return evt.id
@ -119,7 +124,7 @@ class Bot:
evt = self.events.pop(0)
evt.launch_check()
if evt.next is not None:
self.add_event(evt)
self.add_event(evt, evt.id)
self.update_timer()

View File

@ -33,10 +33,12 @@ def load(context):
if DATAS.index[evt].hasAttribute("end"):
event = ModuleEvent(call=fini, call_data=dict(strend=DATAS.index[evt]))
event.end = DATAS.index[evt].getDate("end")
DATAS.index[evt]["id"] = context.add_event(event)
idt = context.add_event(event)
if idt is not None:
DATAS.index[evt]["id"] = idt
def fini(strend):
def fini(d, strend):
for server in CONTEXT.servers.keys():
if not strend.hasAttribute("server") or server == strend["server"]:
if strend["channel"] == CONTEXT.servers[server].nick: