diff --git a/frank/frank.py b/frank/frank.py index 18a56b6..a46a861 100644 --- a/frank/frank.py +++ b/frank/frank.py @@ -7,7 +7,8 @@ import yaml class Frank(discord.Client): PREFIX = "fr" - def __init__(self, modules: List["Module"], config_file: str = "frank.yaml"): + def __init__(self, modules: List["Module"], + config_file: str = "frank.yaml"): super().__init__() self._modules = modules self._loaded_modules = [] @@ -38,10 +39,10 @@ class Frank(discord.Client): async def on_message(self, message: str): cmd = shlex.split(message.content.strip()) - if cmd[0] == "fr": - matched_mods = (mod for mod in self._loaded_modules if mod.PREFIX == cmd[1]) + if cmd[0] == self.PREFIX: + matched_mods = (mod for mod in self._loaded_modules if + mod.match(cmd[1])) module = next(matched_mods, None) if module: await module.command(cmd[2:]) - diff --git a/frank/module.py b/frank/module.py index 702b34d..44a2ae4 100644 --- a/frank/module.py +++ b/frank/module.py @@ -2,8 +2,8 @@ from typing import List, Dict class Module: - PREFIX = None - NAME = None + PREFIX = [] + NAME = "" def __init__(self, client: "Frank", config: Dict = None): self._client = client @@ -14,3 +14,19 @@ class Module: async def command(self, cmd: List[str]): pass + + @classmethod + def match(cls, s: str) -> bool: + """ + Checks wether the given string is a prefix in the module. + """ + + if cls.PREFIX: + if isinstance(cls.PREFIX, list): + return s in cls.PREFIX + + else: + return s == cls.PREFIX + + else: + return False diff --git a/frank/modules/mcstat.py b/frank/modules/mcstat.py index 84285c8..37aae9d 100644 --- a/frank/modules/mcstat.py +++ b/frank/modules/mcstat.py @@ -30,5 +30,3 @@ class McStat(Module): else: await channel.send("No one is here bro") - - diff --git a/frank/modules/testmod.py b/frank/modules/testmod.py index 6a6d876..e87d3bf 100644 --- a/frank/modules/testmod.py +++ b/frank/modules/testmod.py @@ -3,7 +3,6 @@ from .. import Module class TestMod(Module): - PREFIX = "test" NAME = "test"