events: fix event removal

This commit is contained in:
nemunaire 2017-09-27 00:13:26 +02:00
parent 5646850df1
commit b15d18b3a5
3 changed files with 6 additions and 6 deletions

View File

@ -296,7 +296,7 @@ class Bot(threading.Thread):
# Register the event in the source module # Register the event in the source module
if module_src is not None: if module_src is not None:
module_src.__nemubot_context__.events.append(evt.id) module_src.__nemubot_context__.events.append((evt, evt.id))
evt.module_src = module_src evt.module_src = module_src
logger.info("New event registered in %d position: %s", i, t) logger.info("New event registered in %d position: %s", i, t)
@ -326,10 +326,10 @@ class Bot(threading.Thread):
id = evt id = evt
if len(self.events) > 0 and id == self.events[0].id: if len(self.events) > 0 and id == self.events[0].id:
if module_src is not None:
module_src.__nemubot_context__.events.remove((self.events[0], id))
self.events.remove(self.events[0]) self.events.remove(self.events[0])
self._update_event_timer() self._update_event_timer()
if module_src is not None:
module_src.__nemubot_context__.events.remove(id)
return True return True
for evt in self.events: for evt in self.events:
@ -337,7 +337,7 @@ class Bot(threading.Thread):
self.events.remove(evt) self.events.remove(evt)
if module_src is not None: if module_src is not None:
module_src.__nemubot_context__.events.remove(evt.id) module_src.__nemubot_context__.events.remove((evt, evt.id))
return True return True
return False return False

View File

@ -94,7 +94,7 @@ class EventConsumer:
# Or remove reference of this event # Or remove reference of this event
elif (hasattr(self.evt, "module_src") and elif (hasattr(self.evt, "module_src") and
self.evt.module_src is not None): self.evt.module_src is not None):
self.evt.module_src.__nemubot_context__.events.remove(self.evt.id) self.evt.module_src.__nemubot_context__.events.remove((self.evt, self.evt.id))

View File

@ -85,7 +85,7 @@ class _ModuleContext:
self.del_hook(h, *s) self.del_hook(h, *s)
# Remove registered events # Remove registered events
for evt, eid, module_src in self.events: for evt, eid in self.events:
self.del_event(evt) self.del_event(evt)
self.save() self.save()