minya_hotomoe/module_interface.py

40 lines
925 B
Python
Raw Normal View History

2023-09-08 02:49:37 +02:00
from mipa.ext.commands.bot import Bot
2023-10-03 04:01:27 +02:00
2023-09-08 02:49:37 +02:00
class ModuleInterface:
def __init__(self):
self.name = None
self.regex_pattern = None
self.funcs = {}
self.manager: (ModuleManager | None) = None
2023-10-03 04:01:27 +02:00
2023-09-08 02:49:37 +02:00
def set_manager(self, manager):
self.manager = manager
2023-10-03 04:01:27 +02:00
# self.module_ready()
2023-09-08 02:49:37 +02:00
def get_execute_pattern(self, regex_pattern):
return self.__regex_pattern
2023-10-03 04:01:27 +02:00
2023-09-08 02:49:37 +02:00
def module_ready(self):
pass
async def execute_module(self, ctx):
pass
def get_func(self, name):
return self.funcs[name]
class ModuleManager:
2023-10-03 04:01:27 +02:00
def __init__(self, main_bot=None):
2023-09-08 02:49:37 +02:00
self.modules = {}
2023-10-03 04:01:27 +02:00
self.bot: (Bot | None) = main_bot
2023-09-08 02:49:37 +02:00
def require(self, name):
return self.modules[name]
def register_module(self, module):
if module.name not in self.modules:
self.modules[module.name] = module
module.set_manager(self)