Fix events (the first event was always skiped)
This commit is contained in:
parent
d394ff5784
commit
387ecc7d5c
54
bot.py
54
bot.py
@ -61,24 +61,33 @@ class Bot:
|
||||
|
||||
def add_event(self, evt):
|
||||
"""Register an event and return its identifiant for futur update"""
|
||||
# Find ID
|
||||
# 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)
|
||||
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)
|
||||
|
||||
# Add the event in place
|
||||
t = evt.current
|
||||
i = 0
|
||||
i = -1
|
||||
for i in range(0, len(self.events)):
|
||||
if self.events[i].current > t:
|
||||
i -= 1
|
||||
break
|
||||
self.events.insert(i, evt)
|
||||
if i == 0:
|
||||
self.events.insert(i + 1, evt)
|
||||
if i == -1:
|
||||
self.update_timer()
|
||||
|
||||
return evt.id
|
||||
|
||||
def del_event(self, id):
|
||||
"""Find and remove an event from list"""
|
||||
if len(self.events) > 0 and id == self.events[0].id:
|
||||
self.events.remove(self.events[0])
|
||||
self.update_timer()
|
||||
return True
|
||||
|
||||
for evt in self.events:
|
||||
if evt.id == id:
|
||||
self.events.remove(evt)
|
||||
@ -157,7 +166,7 @@ class Bot:
|
||||
if name in self.modules:
|
||||
self.modules[name].save()
|
||||
if hasattr(self.modules[name], "unload"):
|
||||
self.modules[name].unload()
|
||||
self.modules[name].unload(self)
|
||||
# Remove registered hooks
|
||||
for (s, h) in self.modules[name].REGISTERED_HOOKS:
|
||||
self.hooks.del_hook(s, h)
|
||||
@ -384,8 +393,14 @@ def hotswap(bak):
|
||||
def reload():
|
||||
import imp
|
||||
|
||||
import prompt.builtins
|
||||
imp.reload(prompt.builtins)
|
||||
import channel
|
||||
imp.reload(channel)
|
||||
|
||||
import consumer
|
||||
imp.reload(consumer)
|
||||
|
||||
import DCC
|
||||
imp.reload(DCC)
|
||||
|
||||
import event
|
||||
imp.reload(event)
|
||||
@ -393,22 +408,19 @@ def reload():
|
||||
import hooks
|
||||
imp.reload(hooks)
|
||||
|
||||
import xmlparser
|
||||
imp.reload(xmlparser)
|
||||
import xmlparser.node
|
||||
imp.reload(xmlparser.node)
|
||||
|
||||
import importer
|
||||
imp.reload(importer)
|
||||
|
||||
import message
|
||||
imp.reload(message)
|
||||
|
||||
import prompt.builtins
|
||||
imp.reload(prompt.builtins)
|
||||
|
||||
import server
|
||||
imp.reload(server)
|
||||
|
||||
import channel
|
||||
imp.reload(channel)
|
||||
|
||||
import DCC
|
||||
imp.reload(DCC)
|
||||
|
||||
import message
|
||||
imp.reload(message)
|
||||
import xmlparser
|
||||
imp.reload(xmlparser)
|
||||
import xmlparser.node
|
||||
imp.reload(xmlparser.node)
|
||||
|
14
event.py
14
event.py
@ -37,6 +37,8 @@ class ModuleEvent:
|
||||
self.cmp_data = self.func(**self.func_data)
|
||||
else:
|
||||
self.cmp_data = self.func(self.func_data)
|
||||
else:
|
||||
self.cmp_data = None
|
||||
|
||||
self.offset = timedelta(seconds=offset) # Time to wait before the first check
|
||||
self.intervalle = timedelta(seconds=intervalle)
|
||||
@ -92,7 +94,10 @@ class ModuleEvent:
|
||||
#print ("do test with", d, self.cmp_data)
|
||||
|
||||
if self.check is None:
|
||||
if self.cmp_data is None:
|
||||
r = True
|
||||
else:
|
||||
r = d != self.cmp_data
|
||||
elif self.cmp_data is None:
|
||||
r = self.check(d)
|
||||
elif isinstance(self.cmp_data, dict):
|
||||
@ -103,8 +108,11 @@ class ModuleEvent:
|
||||
if r:
|
||||
self.times -= 1
|
||||
if self.call_data is None:
|
||||
if d is None:
|
||||
self.call()
|
||||
elif isinstance(self.call_data, dict):
|
||||
self.call(**self.call_data)
|
||||
else:
|
||||
self.call(self.call_data)
|
||||
self.call(d)
|
||||
elif isinstance(self.call_data, dict):
|
||||
self.call(d, **self.call_data)
|
||||
else:
|
||||
self.call(d, self.call_data)
|
||||
|
@ -147,7 +147,7 @@ class ModuleLoader(SourceLoader):
|
||||
module.name = fullname
|
||||
module.print = lambda msg: print("[%s] %s"%(module.name, msg))
|
||||
module.print_debug = lambda msg: mod_print_dbg(module, msg)
|
||||
module.send_response = lambda srv, res: mod_send_response(context, srv, res)
|
||||
module.send_response = lambda srv, res: mod_send_response(self.context, srv, res)
|
||||
|
||||
if not hasattr(module, "NODATA"):
|
||||
module.DATAS = xmlparser.parse_file(self.context.datas_path
|
||||
@ -236,7 +236,7 @@ def mod_print_dbg(mod, msg):
|
||||
|
||||
def mod_save(mod, datas_path):
|
||||
mod.DATAS.save(datas_path + "/" + mod.name + ".xml")
|
||||
mod.print ("Saving!")
|
||||
mod.print_debug("Saving!")
|
||||
|
||||
def mod_has_access(mod, config, msg):
|
||||
if config is not None and config.hasNode("channel"):
|
||||
@ -249,4 +249,4 @@ def mod_has_access(mod, config, msg):
|
||||
return True
|
||||
|
||||
def mod_send_response(context, server, res):
|
||||
context.servers[server].send_response(res)
|
||||
context.servers[server].send_response(res, None)
|
||||
|
Loading…
x
Reference in New Issue
Block a user