Fix module reload

This commit is contained in:
Némunaire 2012-06-29 23:53:47 +02:00
parent fdd794ff1b
commit d234d83df8
2 changed files with 20 additions and 3 deletions

View File

@ -110,6 +110,9 @@ def parseanswer(msg):
msg.send_snd ("Compteurs connus : %s." % ", ".join(DATAS.index.keys())) msg.send_snd ("Compteurs connus : %s." % ", ".join(DATAS.index.keys()))
elif msg.cmd[0] in DATAS.index: elif msg.cmd[0] in DATAS.index:
if DATAS.index[msg.cmd[0]].name == "strend": if DATAS.index[msg.cmd[0]].name == "strend":
if DATAS.index[msg.cmd[0]].hasAttribute("end"):
msg.send_chn ("%s commencé il y a %s et se terminera dans %s." % (msg.cmd[0], msg.just_countdown(datetime.now() - DATAS.index[msg.cmd[0]].getDate("start")), msg.just_countdown(DATAS.index[msg.cmd[0]].getDate("end") - datetime.now())))
else:
msg.send_chn ("%s commencé il y a %s." % (msg.cmd[0], msg.just_countdown(datetime.now () - DATAS.index[msg.cmd[0]].getDate("start")))) msg.send_chn ("%s commencé il y a %s." % (msg.cmd[0], msg.just_countdown(datetime.now () - DATAS.index[msg.cmd[0]].getDate("start"))))
else: else:
msg.send_chn (msg.countdown_format (DATAS.index[msg.cmd[0]].getDate("start"), DATAS.index[msg.cmd[0]]["msg_before"], DATAS.index[msg.cmd[0]]["msg_after"])) msg.send_chn (msg.countdown_format (DATAS.index[msg.cmd[0]].getDate("start"), DATAS.index[msg.cmd[0]]["msg_before"], DATAS.index[msg.cmd[0]]["msg_after"]))

View File

@ -115,7 +115,15 @@ def mod_has_access(mod, config, msg):
def load_module_from_name(name, servers, config=None): def load_module_from_name(name, servers, config=None):
try: try:
#Import the module code #Import the module code
loaded = False
for md in MODS:
if md.name == name:
mod = imp.reload(md)
loaded = True
break
if not loaded:
mod = __import__(name) mod = __import__(name)
imp.reload(mod)
try: try:
if mod.nemubotversion < 3.0: if mod.nemubotversion < 3.0:
print (" Module `%s' is not compatible with this version." % name) print (" Module `%s' is not compatible with this version." % name)
@ -166,6 +174,12 @@ def load_module_from_name(name, servers, config=None):
except AttributeError: except AttributeError:
print (" Module `%s' successfully added." % name) print (" Module `%s' successfully added." % name)
#TODO: don't append already running modules #TODO: don't append already running modules
exitsts = False
for md in MODS:
if md.name == name:
exitsts = True
break
if not exitsts:
MODS.append(mod) MODS.append(mod)
except AttributeError: except AttributeError:
print (" Module `%s' is not a nemubot module." % name) print (" Module `%s' is not a nemubot module." % name)