Add gitpython requirement. Clone the repo.
This commit is contained in:
+3
-2
@@ -130,7 +130,7 @@ dmypy.json
|
|||||||
# logging
|
# logging
|
||||||
nextcord.log
|
nextcord.log
|
||||||
|
|
||||||
# data file for bot
|
# bot files
|
||||||
highscores_data.json
|
highscores_data.json
|
||||||
highscores_config.json
|
highscores_config.json
|
||||||
deleted_backups/
|
deleted_backups/
|
||||||
@@ -139,4 +139,5 @@ TODO.txt
|
|||||||
sql_tester.py
|
sql_tester.py
|
||||||
conf
|
conf
|
||||||
outputs
|
outputs
|
||||||
database
|
database
|
||||||
|
dakiny-messages/
|
||||||
@@ -1,16 +1,25 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from git import Repo
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git"
|
||||||
|
REPO_DIR = "./dakiny-messages"
|
||||||
|
|
||||||
|
|
||||||
class ClanMessages(commands.Cog, name="Clan Messages"):
|
class ClanMessages(commands.Cog, name="Clan Messages"):
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
self.clone_repo()
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_ready(self):
|
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"])
|
app.add_api_route("/message/", self.hello, methods=["POST"])
|
||||||
config = uvicorn.Config(app=app, port=5000, log_level="info")
|
config = uvicorn.Config(app=app, port=5000, log_level="info")
|
||||||
server = uvicorn.Server(config)
|
server = uvicorn.Server(config)
|
||||||
@@ -18,6 +27,7 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
|
|||||||
|
|
||||||
async def hello(self):
|
async def hello(self):
|
||||||
print("we did a webhook")
|
print("we did a webhook")
|
||||||
|
await self.update_messages()
|
||||||
return {"message": "webhook get"}
|
return {"message": "webhook get"}
|
||||||
|
|
||||||
async def update_messages(self):
|
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.
|
# new one. the message could be deleted, which would cause a new message to be sent and database updated.
|
||||||
pass
|
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.
|
# This function will be called when this extension is loaded.
|
||||||
# It is necessary to add these functions to the bot.
|
# It is necessary to add these functions to the bot.
|
||||||
|
|||||||
+2
-1
@@ -4,4 +4,5 @@ pytz==2022.7.1
|
|||||||
hydra-core==1.3.2
|
hydra-core==1.3.2
|
||||||
sqlalchemy<2.0
|
sqlalchemy<2.0
|
||||||
pandas==1.5.2
|
pandas==1.5.2
|
||||||
fastapi==0.111.0
|
fastapi==0.111.0
|
||||||
|
GitPython==3.1.43
|
||||||
Reference in New Issue
Block a user