only trigger updating clan messages in updated directories.

Update clan info message if the template was updated.
This commit is contained in:
2024-05-16 21:37:10 -04:00
parent 3761d3bb77
commit 04c44bc470
2 changed files with 29 additions and 5 deletions
+26 -3
View File
@@ -10,8 +10,9 @@ from fastapi import FastAPI
from git import Repo from git import Repo
from nextcord.ext import commands from nextcord.ext import commands
from classes.gitea_webhook import GiteaWebhook
from config import DakinyConfig from config import DakinyConfig
from utils import REPO_DIR, update_clan_messages from utils import REPO_DIR, edit_clan_council_info, update_clan_messages
app = FastAPI() app = FastAPI()
REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git" REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git"
@@ -38,16 +39,38 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
server = uvicorn.Server(config) server = uvicorn.Server(config)
await server.serve() await server.serve()
async def update_messages(self): async def update_messages(self, hook_info: GiteaWebhook):
""" """
Pulls from git and then calls method to update all the discord messages as described by the Pulls from git and then calls method to update all the discord messages as described by the
files in the git repo. files in the git repo.
""" """
# Get all modified/added files
modified_files: list[str] = [
file
for list in [commit.modified + commit.added for commit in hook_info.commits]
for file in list
]
template_updates = {
file.split("/")[1] for file in modified_files if "message_templates" in file
}
channel_updates = {
file.split("/")[1]
for file in modified_files
if file.split("/")[1] not in template_updates
}
self.origin.pull() self.origin.pull()
guild: nextcord.Guild = self.bot.get_guild(self.config.params.guild_id) guild: nextcord.Guild = self.bot.get_guild(self.config.params.guild_id)
await update_clan_messages(guild) await update_clan_messages(guild, channel_updates)
# if the council members template has changed, update the message
if "council_members.txt" in template_updates:
await edit_clan_council_info(
self.bot.get_guild(self.config.params.guild_id), self.config
)
return {"message": "Successfully updated all discord messages."} return {"message": "Successfully updated all discord messages."}
+3 -2
View File
@@ -4,6 +4,7 @@ File contains util functions.
import os import os
from datetime import datetime from datetime import datetime
from typing import Iterable
import nextcord import nextcord
from sqlalchemy import select, true, update from sqlalchemy import select, true, update
@@ -395,7 +396,7 @@ def record_event_host(config: DakinyConfig, user: int):
session.commit() session.commit()
async def update_clan_messages(guild: nextcord.Guild): async def update_clan_messages(guild: nextcord.Guild, channel_updates: Iterable[str]):
""" """
Updates all clan messages to contents in MESSAGES_DIR. Updates all clan messages to contents in MESSAGES_DIR.
Does not to any git work. Is expected to be called after git is pulled. Does not to any git work. Is expected to be called after git is pulled.
@@ -411,7 +412,7 @@ async def update_clan_messages(guild: nextcord.Guild):
dirs = [ dirs = [
dir_name dir_name
for dir_name in os.listdir(MESSAGES_DIR) for dir_name in channel_updates
if os.path.isdir(f"{MESSAGES_DIR}/{dir_name}") if os.path.isdir(f"{MESSAGES_DIR}/{dir_name}")
] ]