39 lines
941 B
Python
39 lines
941 B
Python
|
from mipa.ext.commands.bot import Bot
|
||
|
|
||
|
class ModuleInterface:
|
||
|
def __init__(self):
|
||
|
self.name = None
|
||
|
self.regex_pattern = None
|
||
|
self.funcs = {}
|
||
|
self.manager: (ModuleManager | None) = None
|
||
|
|
||
|
def set_manager(self, manager):
|
||
|
self.manager = manager
|
||
|
self.module_ready()
|
||
|
|
||
|
def get_execute_pattern(self, regex_pattern):
|
||
|
return self.__regex_pattern
|
||
|
|
||
|
def module_ready(self):
|
||
|
pass
|
||
|
|
||
|
async def execute_module(self, ctx):
|
||
|
pass
|
||
|
|
||
|
def get_func(self, name):
|
||
|
return self.funcs[name]
|
||
|
|
||
|
|
||
|
class ModuleManager:
|
||
|
def __init__(self, main_bot = None):
|
||
|
self.modules = {}
|
||
|
self.bot: (Bot | None) = main_bot
|
||
|
|
||
|
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)
|