diff --git a/.gitignore b/.gitignore index 2b4fd5b..351e035 100644 --- a/.gitignore +++ b/.gitignore @@ -130,7 +130,7 @@ dmypy.json # logging nextcord.log -# data file for bot +# bot files highscores_data.json highscores_config.json deleted_backups/ @@ -139,4 +139,5 @@ TODO.txt sql_tester.py conf outputs -database \ No newline at end of file +database +dakiny-messages/ \ No newline at end of file diff --git a/cogs/clan_messages/__init__.py b/cogs/clan_messages/__init__.py index 9d479a9..1e85952 100644 --- a/cogs/clan_messages/__init__.py +++ b/cogs/clan_messages/__init__.py @@ -1,16 +1,25 @@ +import os + import uvicorn from fastapi import FastAPI +from git import Repo from nextcord.ext import commands app = FastAPI() +REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git" +REPO_DIR = "./dakiny-messages" class ClanMessages(commands.Cog, name="Clan Messages"): def __init__(self, bot: commands.Bot): self.bot = bot + self.clone_repo() @commands.Cog.listener() async def on_ready(self): + """ + Triggers when the bot is in ready state. Adds the webhook listener to FastAPI and serves. + """ app.add_api_route("/message/", self.hello, methods=["POST"]) config = uvicorn.Config(app=app, port=5000, log_level="info") server = uvicorn.Server(config) @@ -18,6 +27,7 @@ class ClanMessages(commands.Cog, name="Clan Messages"): async def hello(self): print("we did a webhook") + await self.update_messages() return {"message": "webhook get"} async def update_messages(self): @@ -30,6 +40,16 @@ class ClanMessages(commands.Cog, name="Clan Messages"): # new one. the message could be deleted, which would cause a new message to be sent and database updated. pass + def clone_repo(self): + """ + Checks if the repo exists and creates repo object, clones if it does not. + """ + # check if repo has been cloned. open repo object + if os.path.isdir(REPO_DIR): + self.repo = Repo(REPO_DIR) + else: + self.repo = Repo.clone_from(REPO_URL, REPO_DIR) + # This function will be called when this extension is loaded. # It is necessary to add these functions to the bot. diff --git a/requirements.txt b/requirements.txt index 205c64d..c397c41 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ pytz==2022.7.1 hydra-core==1.3.2 sqlalchemy<2.0 pandas==1.5.2 -fastapi==0.111.0 \ No newline at end of file +fastapi==0.111.0 +GitPython==3.1.43 \ No newline at end of file