add names to plugins and state tracking

This commit is contained in:
randomuser 2021-08-03 10:49:57 -05:00
parent b42222d400
commit d4d6ab9a8e
1 changed files with 5 additions and 3 deletions

8
main.py Normal file → Executable file
View File

@ -56,7 +56,7 @@ class Server(BaseServer):
mod = mod_include(name) mod = mod_include(name)
for i in EVENTS: for i in EVENTS:
if hasattr(mod, i): if hasattr(mod, i):
self.handlers[i].append(getattr(mod, i)) self.handlers[i].append([name, getattr(mod, i)])
self.states[name] = None self.states[name] = None
def event_get(self, line: Line): def event_get(self, line: Line):
@ -74,7 +74,9 @@ class Server(BaseServer):
if event == None: return False if event == None: return False
try: try:
for i in self.handlers[event]: for i in self.handlers[event]:
i(line, self) ret = i[1](line, self)
if not ret == None:
self.states[i[0]] = ret
except IndexError: return False except IndexError: return False
return True return True
@ -95,5 +97,5 @@ async def main():
if __name__ == "__main__": if __name__ == "__main__":
os.chdir("mods") os.chdir("mods")
sys.path.append(os.getcwd()) sys.path = [os.getcwd()] + sys.path
asyncio.run(main()) asyncio.run(main())