From af3ec01734a339b08dfc38ea96dbc0f4c677a775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9munaire?= Date: Sun, 2 Sep 2012 18:40:44 +0200 Subject: [PATCH] ID are keept when an event is not finished --- bot.py | 21 +++++++++++++-------- modules/events/__init__.py | 6 ++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/bot.py b/bot.py index e201f0a..0bdc98d 100644 --- a/bot.py +++ b/bot.py @@ -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() diff --git a/modules/events/__init__.py b/modules/events/__init__.py index a1174a0..70b1b67 100644 --- a/modules/events/__init__.py +++ b/modules/events/__init__.py @@ -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: