FEAT: Added an update module to allow Selena to be deployed
This commit is contained in:
parent
c0dd278cd4
commit
d92810b84c
32
config.py
32
config.py
@ -14,26 +14,14 @@ config = {
|
||||
'OAUTH_URL': os.getenv('OAUTH_URL'),
|
||||
'OAUTH_CLIENT_ID': os.getenv('OAUTH_CLIENT_ID'),
|
||||
'modules': {
|
||||
'currency': {
|
||||
'enabled': True
|
||||
},
|
||||
'xp': {
|
||||
'enabled': True
|
||||
},
|
||||
'birthday': {
|
||||
'enabled': True
|
||||
},
|
||||
'destiny2': {
|
||||
'enabled': False
|
||||
},
|
||||
'music': {
|
||||
'enabled': True
|
||||
},
|
||||
'youtube': {
|
||||
'enabled': True
|
||||
},
|
||||
'twitch': {
|
||||
'enabled': True
|
||||
}
|
||||
}
|
||||
'currency': {'enabled': True},
|
||||
'xp': {'enabled': True},
|
||||
'birthday': {'enabled': True},
|
||||
'destiny2': {'enabled': False},
|
||||
'music': {'enabled': True},
|
||||
'youtube': {'enabled': True},
|
||||
'twitch': {'enabled': True},
|
||||
'update': {'enabled': True}
|
||||
},
|
||||
'UPDATE_BRANCH': 'dev-rework'
|
||||
}
|
||||
|
7
main.py
7
main.py
@ -1,3 +1,4 @@
|
||||
# main.py
|
||||
import discord
|
||||
from config import config
|
||||
import logging
|
||||
@ -15,7 +16,6 @@ class Selena(discord.Client):
|
||||
def __init__(self):
|
||||
super().__init__(intents=intents)
|
||||
self.tree = discord.app_commands.CommandTree(self)
|
||||
self.twitch = None
|
||||
self.load_modules()
|
||||
|
||||
async def setup_hook(self):
|
||||
@ -59,6 +59,11 @@ class Selena(discord.Client):
|
||||
twitch = Twitch(self)
|
||||
twitch.setup(self.tree)
|
||||
|
||||
if config['modules']['update']['enabled']:
|
||||
from modules.admin.update import setup as update_setup
|
||||
branch_name = config.get('UPDATE_BRANCH', 'dev-rework')
|
||||
update_setup(self, branch=branch_name)
|
||||
|
||||
|
||||
bot = Selena()
|
||||
|
||||
|
47
modules/admin/update.py
Normal file
47
modules/admin/update.py
Normal file
@ -0,0 +1,47 @@
|
||||
# modules/admin/update.py
|
||||
import discord
|
||||
from discord import app_commands
|
||||
import os
|
||||
import subprocess
|
||||
import logging
|
||||
|
||||
|
||||
class Update:
|
||||
def __init__(self, bot, branch='dev-rework'):
|
||||
self.bot = bot
|
||||
self.branch = branch
|
||||
self.logger = logging.getLogger('Update')
|
||||
self.logger.setLevel(logging.DEBUG)
|
||||
handler = logging.FileHandler(filename='log/selena.log', encoding='utf-8', mode='w')
|
||||
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s:%(message)s'))
|
||||
self.logger.addHandler(handler)
|
||||
|
||||
async def update_bot(self, interaction: discord.Interaction):
|
||||
await interaction.response.send_message(embed=discord.Embed(description="Updating Selena...", color=discord.Color.green()))
|
||||
|
||||
self.logger.info(f"Pulling latest code from Git repository on branch {self.branch}...")
|
||||
subprocess.run(["git", "fetch"], check=True)
|
||||
subprocess.run(["git", "checkout", self.branch], check=True)
|
||||
subprocess.run(["git", "pull", "origin", self.branch], check=True)
|
||||
|
||||
self.logger.info("Installing dependencies...")
|
||||
subprocess.run(["pip", "install", "-r", "requirements.txt"], check=True)
|
||||
|
||||
await interaction.followup.send(embed=discord.Embed(description="Update completed. Restarting Selena...", color=discord.Color.green()))
|
||||
self.logger.info("Update completed. Restarting Selena...")
|
||||
|
||||
os._exit(0)
|
||||
|
||||
def setup(self, tree: app_commands.CommandTree):
|
||||
@tree.command(name="update", description="Update Selena to the latest version")
|
||||
async def update_command(interaction: discord.Interaction):
|
||||
await interaction.response.defer() # Defer the interaction response
|
||||
await self.update_bot(interaction)
|
||||
|
||||
if not tree.get_command("update"):
|
||||
tree.add_command(update_command)
|
||||
|
||||
|
||||
def setup(bot, branch='dev-rework'):
|
||||
updater = Update(bot, branch=branch)
|
||||
updater.setup(bot.tree)
|
64
requirements.txt
Normal file
64
requirements.txt
Normal file
@ -0,0 +1,64 @@
|
||||
aiohttp==3.9.5
|
||||
aiosignal==1.3.1
|
||||
async-timeout==4.0.3
|
||||
attrs==23.2.0
|
||||
autoflake==2.3.1
|
||||
black==24.4.2
|
||||
Brotli==1.1.0
|
||||
cachetools==5.3.3
|
||||
certifi==2024.6.2
|
||||
cffi==1.16.0
|
||||
charset-normalizer==3.3.2
|
||||
click==8.1.7
|
||||
colorama==0.4.6
|
||||
com2ann==0.3.0
|
||||
discord.py==2.3.2
|
||||
ffmpeg-python==0.2.0
|
||||
frozenlist==1.4.1
|
||||
future==1.0.0
|
||||
google-api-core==2.19.0
|
||||
google-api-python-client==2.134.0
|
||||
google-auth==2.30.0
|
||||
google-auth-httplib2==0.2.0
|
||||
googleapis-common-protos==1.63.1
|
||||
httplib2==0.22.0
|
||||
idna==3.7
|
||||
iso8601==2.1.0
|
||||
libcst==1.4.0
|
||||
multidict==6.0.5
|
||||
mutagen==1.47.0
|
||||
mypy-extensions==1.0.0
|
||||
packaging==24.1
|
||||
pathspec==0.12.1
|
||||
platformdirs==4.2.2
|
||||
PlexAPI==4.15.13
|
||||
proto-plus==1.24.0
|
||||
protobuf==4.25.3
|
||||
pyasn1==0.6.0
|
||||
pyasn1_modules==0.4.0
|
||||
pycparser==2.22
|
||||
pycryptodomex==3.20.0
|
||||
pyflakes==3.2.0
|
||||
PyNaCl==1.5.0
|
||||
pyparsing==3.1.2
|
||||
python-dateutil==2.9.0.post0
|
||||
python-dotenv==1.0.1
|
||||
pyupgrade==3.16.0
|
||||
PyYAML==6.0.1
|
||||
redis==5.0.6
|
||||
requests==2.32.3
|
||||
rsa==4.9
|
||||
ruff==0.4.10
|
||||
shed==2024.3.1
|
||||
six==1.16.0
|
||||
spotipy==2.24.0
|
||||
tokenize-rt==5.2.0
|
||||
tomli==2.0.1
|
||||
twitchAPI==4.2.0
|
||||
twitchio==2.9.1
|
||||
typing_extensions==4.12.2
|
||||
uritemplate==4.1.1
|
||||
urllib3==2.2.2
|
||||
websockets==12.0
|
||||
yarl==1.9.4
|
||||
yt-dlp==2024.5.27
|
Loading…
x
Reference in New Issue
Block a user