From a3e195925ab628597d02bbc49bffbb76232692d2 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Tue, 14 May 2024 17:14:54 -0400 Subject: [PATCH] Get on the right branch --- cogs/clan_messages/__init__.py | 21 ++++++++++++++++++--- config.py | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cogs/clan_messages/__init__.py b/cogs/clan_messages/__init__.py index 1e85952..a9c2712 100644 --- a/cogs/clan_messages/__init__.py +++ b/cogs/clan_messages/__init__.py @@ -5,6 +5,8 @@ from fastapi import FastAPI from git import Repo from nextcord.ext import commands +from config import DakinyConfig + app = FastAPI() REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git" REPO_DIR = "./dakiny-messages" @@ -13,7 +15,8 @@ REPO_DIR = "./dakiny-messages" class ClanMessages(commands.Cog, name="Clan Messages"): def __init__(self, bot: commands.Bot): self.bot = bot - self.clone_repo() + self.config: DakinyConfig = self.bot.config + self.repo_setup() @commands.Cog.listener() async def on_ready(self): @@ -38,9 +41,8 @@ class ClanMessages(commands.Cog, name="Clan Messages"): # 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 # new one. the message could be deleted, which would cause a new message to be sent and database updated. - pass - def clone_repo(self): + def repo_setup(self): """ Checks if the repo exists and creates repo object, clones if it does not. """ @@ -50,6 +52,19 @@ class ClanMessages(commands.Cog, name="Clan Messages"): else: self.repo = Repo.clone_from(REPO_URL, REPO_DIR) + self.origin = self.repo.remote("origin") + + if self.config.params.git_branch == "test": + self.repo.create_head("test", self.origin.refs.test).set_tracking_branch( + self.origin.refs.test + ).checkout() + else: + self.repo.create_head("main", self.origin.refs.main).set_tracking_branch( + self.origin.refs.main + ).checkout() + + self.origin.pull() + # This function will be called when this extension is loaded. # It is necessary to add these functions to the bot. diff --git a/config.py b/config.py index b779fbc..6510907 100644 --- a/config.py +++ b/config.py @@ -23,6 +23,7 @@ class Params: event_participate_points: int event_post_channel_id: int general_channel_id: int + git_branch: str guild_id: int high_council_role_id: int voting_parent_id: int