Add gitpython requirement. Clone the repo.

This commit is contained in:
2024-05-14 16:34:31 -04:00
parent 4ae31159dc
commit 9d78070c45
3 changed files with 25 additions and 3 deletions
+3 -2
View File
@@ -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
database
dakiny-messages/
+20
View File
@@ -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.
+2 -1
View File
@@ -4,4 +4,5 @@ pytz==2022.7.1
hydra-core==1.3.2
sqlalchemy<2.0
pandas==1.5.2
fastapi==0.111.0
fastapi==0.111.0
GitPython==3.1.43