FIX: Fixed some typos as well as fixed up the update module

This commit is contained in:
Dan 2024-06-30 17:55:41 -04:00
parent 8e125c9758
commit 4f065d368b
3 changed files with 22 additions and 33 deletions

View File

@ -23,6 +23,6 @@ config = {
'twitch': {'enabled': True},
'update': {'enabled': True},
'data_privacy': {'enabled': True},
'term_privacy': {'enabled': True}
'terms_privacy': {'enabled': True}
}
}

17
main.py
View File

@ -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()

View File

@ -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):
try:
await interaction.response.send_message(embed=discord.Embed(description="Updating Selena...", color=discord.Color.green()))
except discord.errors.InteractionResponded:
await interaction.response.defer(ephemeral=True)
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)
self.logger.info('Starting update process...')
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)