From 4f065d368bae43249134c00617c0e25d27718e7f Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 30 Jun 2024 17:55:41 -0400 Subject: [PATCH] FIX: Fixed some typos as well as fixed up the update module --- config.py | 2 +- main.py | 17 ++++++++++------- modules/admin/update.py | 36 +++++++++++------------------------- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/config.py b/config.py index 69506ed..b9b9afb 100644 --- a/config.py +++ b/config.py @@ -23,6 +23,6 @@ config = { 'twitch': {'enabled': True}, 'update': {'enabled': True}, 'data_privacy': {'enabled': True}, - 'term_privacy': {'enabled': True} + 'terms_privacy': {'enabled': True} } } diff --git a/main.py b/main.py index 70bbc1a..54b7cf4 100644 --- a/main.py +++ b/main.py @@ -60,16 +60,19 @@ class Selena(discord.Client): twitch.setup(self.tree) if config['modules']['update']['enabled']: - from modules.admin.update import setup as update_setup - update_setup(self.tree) + from modules.admin.update import Update + update = Update(self) + update.setup(self.tree) if config['modules']['data_privacy']['enabled']: - from modules.admin.data_privacy import setup as data_privacy_setup - data_privacy_setup(self.tree) + from modules.admin.data_privacy import DataPrivacy + data_privacy = DataPrivacy(self) + data_privacy.setup(self.tree) - if config['modules']['term_privacy']['enabled']: - from modules.admin.term_privacy import setup as term_privacy_setup - term_privacy_setup(self.tree) + if config['modules']['terms_privacy']['enabled']: + from modules.admin.terms_privacy import TermsPrivacy + terms_privacy = TermsPrivacy(self) + terms_privacy.setup(self.tree) bot = Selena() diff --git a/modules/admin/update.py b/modules/admin/update.py index 278eafd..65b281b 100644 --- a/modules/admin/update.py +++ b/modules/admin/update.py @@ -1,8 +1,8 @@ import discord from discord import app_commands import os -import logging import subprocess +import logging import sys @@ -16,34 +16,20 @@ class Update: self.logger.addHandler(handler) async def update_bot(self, interaction: discord.Interaction): + await interaction.response.defer(ephemeral=True) + await interaction.followup.send(embed=discord.Embed(description="Updating Selena...", color=discord.Color.green())) + self.logger.info('Starting update process...') try: - await interaction.response.send_message(embed=discord.Embed(description="Updating Selena...", color=discord.Color.green())) - except discord.errors.InteractionResponded: - await interaction.followup.send(embed=discord.Embed(description="Updating Selena...", color=discord.Color.green())) - - # Fetch updates from the specified branch - branch = 'main' # change this to your branch if necessary - result = subprocess.run(['git', 'pull', 'origin', branch], capture_output=True, text=True) - - if result.returncode == 0: - self.logger.info("Successfully pulled updates from the repository") - self.logger.info(result.stdout) - try: - await interaction.followup.send(embed=discord.Embed(description="Successfully updated Selena. Restarting...", color=discord.Color.green())) - except discord.errors.InteractionResponded: - await interaction.followup.send(embed=discord.Embed(description="Successfully updated Selena. Restarting...", color=discord.Color.green())) - - # Restart the bot (this is just a placeholder, modify according to your setup) + subprocess.run(["git", "pull"], check=True) + self.logger.info('Successfully pulled updates from git.') + await interaction.followup.send(embed=discord.Embed(description="Update complete. Restarting...", color=discord.Color.green())) os.execv(sys.executable, ['python'] + sys.argv) - else: - self.logger.error(f"Failed to pull updates: {result.stderr}") - try: - await interaction.followup.send(embed=discord.Embed(description="Failed to update Selena. Check logs for details.", color=discord.Color.red())) - except discord.errors.InteractionResponded: - await interaction.followup.send(embed=discord.Embed(description="Failed to update Selena. Check logs for details.", color=discord.Color.red())) + except subprocess.CalledProcessError as e: + self.logger.error(f'Error during update: {e}') + await interaction.followup.send(embed=discord.Embed(description=f"Update failed: {e}", color=discord.Color.red())) def setup(self, tree: app_commands.CommandTree): - @tree.command(name="update", description="Update the bot to the latest version") + @tree.command(name="update", description="Update the bot from the repository") async def update_command(interaction: discord.Interaction): await self.update_bot(interaction)