Start working on update_messages function.
This commit is contained in:
@@ -10,6 +10,7 @@ from config import DakinyConfig
|
|||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git"
|
REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git"
|
||||||
REPO_DIR = "./dakiny-messages"
|
REPO_DIR = "./dakiny-messages"
|
||||||
|
MESSAGES_DIR = f"{REPO_DIR}/messages"
|
||||||
|
|
||||||
|
|
||||||
class ClanMessages(commands.Cog, name="Clan 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.
|
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"])
|
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)
|
||||||
@@ -34,13 +36,25 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
|
|||||||
return {"message": "webhook get"}
|
return {"message": "webhook get"}
|
||||||
|
|
||||||
async def update_messages(self):
|
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
|
# 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
|
# 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.
|
# 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):
|
def repo_setup(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user