diff --git a/.gitignore b/.gitignore index a6a62e9..ce4e516 100755 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ __pycache__/ # Ctags file tags +frank.yaml diff --git a/frank.yaml b/frank.yaml deleted file mode 100644 index 1933cea..0000000 --- a/frank.yaml +++ /dev/null @@ -1,2 +0,0 @@ -test: - channel_id: 740301700606197918 diff --git a/frank/frank.py b/frank/frank.py index 7f1eb1d..18a56b6 100644 --- a/frank/frank.py +++ b/frank/frank.py @@ -14,18 +14,18 @@ class Frank(discord.Client): try: with open(config_file, "r") as f: - self._settings = yaml.load(f, Loader=yaml.FullLoader) + self._config = yaml.load(f, Loader=yaml.FullLoader) except FileNotFoundError: - self._settings = None + self._config = None async def on_ready(self): print("Connected") # Startup all modules for module in self._modules: - if self._settings and module.NAME in self._settings: - loaded = module(self, settings=self._settings[module.NAME]) + if self._config and module.NAME in self._config: + loaded = module(self, config=self._config[module.NAME]) else: loaded = module(self) diff --git a/frank/module.py b/frank/module.py index 903ddfd..702b34d 100644 --- a/frank/module.py +++ b/frank/module.py @@ -5,9 +5,9 @@ class Module: PREFIX = None NAME = None - def __init__(self, client: "Frank", settings: Dict = None): + def __init__(self, client: "Frank", config: Dict = None): self._client = client - self._settings = settings + self._config = config async def start(self): pass diff --git a/frank/modules/__init__.py b/frank/modules/__init__.py index bbb2ff3..c79d5e8 100644 --- a/frank/modules/__init__.py +++ b/frank/modules/__init__.py @@ -1 +1,2 @@ from .testmod import TestMod +from .mcstat import McStat diff --git a/frank/modules/mcstat.py b/frank/modules/mcstat.py new file mode 100644 index 0000000..84285c8 --- /dev/null +++ b/frank/modules/mcstat.py @@ -0,0 +1,34 @@ +from .. import Module +from mcstatus import MinecraftServer + + +class McStat(Module): + PREFIX = "mc" + NAME = "mcstat" + + async def command(self, cmd): + if cmd[0] == "online": + address = self._config["domain"] + port = self._config.get("port") + + if port: + address += ":" + str(port) + + server = MinecraftServer.lookup(address) + status = server.status() + + if status.players.sample is not None: + players = [player.name for player in status.players.sample] + + else: + players = None + + channel = self._client.get_channel(self._config["channel_id"]) + + if players: + await channel.send(f'Currently online: {",".join(players)}') + + else: + await channel.send("No one is here bro") + + diff --git a/frank/modules/testmod.py b/frank/modules/testmod.py index 31c0592..6a6d876 100644 --- a/frank/modules/testmod.py +++ b/frank/modules/testmod.py @@ -3,10 +3,11 @@ from .. import Module class TestMod(Module): + PREFIX = "test" NAME = "test" async def command(self, cmd: List[str]): if cmd[0] == "test": - channel = self._client.get_channel(self._settings["channel_id"]) + channel = self._client.get_channel(self._config["channel_id"]) await channel.send("psycho frank is in the house") diff --git a/main.py b/main.py index 9ec509e..2f2dad6 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,10 @@ import os from dotenv import load_dotenv -from frank.modules import TestMod +from frank.modules import TestMod, McStat from frank import Frank if __name__ == "__main__": load_dotenv() - client = Frank([TestMod]) + client = Frank([TestMod, McStat]) client.run(os.getenv('DISCORD_TOKEN')) diff --git a/requirements.txt b/requirements.txt index c0eea01..5afd50a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ pylint jedi python-dotenv pyyaml +mcstatus