From f51f66697ffe5a3ffe981135628b81ef3a095694 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Tue, 14 May 2024 17:54:58 -0400 Subject: [PATCH] Start working on update_messages function. --- cogs/clan_messages/__init__.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/cogs/clan_messages/__init__.py b/cogs/clan_messages/__init__.py index a9c2712..7f27c14 100644 --- a/cogs/clan_messages/__init__.py +++ b/cogs/clan_messages/__init__.py @@ -10,6 +10,7 @@ from config import DakinyConfig app = FastAPI() REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git" REPO_DIR = "./dakiny-messages" +MESSAGES_DIR = f"{REPO_DIR}/messages" class ClanMessages(commands.Cog, name="Clan Messages"): @@ -23,6 +24,7 @@ class ClanMessages(commands.Cog, name="Clan Messages"): """ Triggers when the bot is in ready state. Adds the webhook listener to FastAPI and serves. """ + await self.update_messages() app.add_api_route("/message/", self.hello, methods=["POST"]) config = uvicorn.Config(app=app, port=5000, log_level="info") server = uvicorn.Server(config) @@ -34,13 +36,25 @@ class ClanMessages(commands.Cog, name="Clan Messages"): return {"message": "webhook get"} async def update_messages(self): - # TODO everything + """ + _summary_ + """ + + self.origin.pull() - # git pull - # if no change, return # for ever directory, sort the files by number then post # posting involves checking if there is a message for that particular file then editing it or creating a # new one. the message could be deleted, which would cause a new message to be sent and database updated. + dirs = [ + f"{MESSAGES_DIR}/{dir_name}" + for dir_name in os.listdir(MESSAGES_DIR) + if os.path.isdir(f"{MESSAGES_DIR}/{dir_name}") + ] + for dir_name in dirs: + sorted_files = sorted( + os.listdir(dir_name), key=lambda filename: int(filename.split(".")[0]) + ) + print(sorted_files) def repo_setup(self): """