add module unloading

This commit is contained in:
randomuser 2021-08-03 11:25:17 -05:00
parent d4d6ab9a8e
commit b23faa1d3f
2 changed files with 13 additions and 0 deletions

View File

@ -59,6 +59,10 @@ class Server(BaseServer):
self.handlers[i].append([name, getattr(mod, i)])
self.states[name] = None
def unload_mod(self, name):
for i in EVENTS:
self.handlers[i] = [j for j in self.handlers[i] if not j[0] == name]
def event_get(self, line: Line):
if line.command.lower() in EVENTS[2:]:
return line.command.lower()

View File

@ -11,3 +11,12 @@ def cmd(line, srv):
else:
utils.message(srv, line.params[0],
"loaded: `" + params[0] + "'")
elif command == "unload":
try:
srv.unload_mod(params[0])
except:
utils.message(srv, line.params[0],
"failed to unload `" + params[0] + "'")
else:
utils.message(srv, line.params[0],
"unloaded: `" + params[0] + "'"