Fix database creation

This commit is contained in:
Parker M. 2025-01-21 21:06:33 -06:00
parent b0ea7ab935
commit 13ee068358
Signed by: parker
GPG Key ID: 505ED36FC12B5D5E
3 changed files with 15 additions and 11 deletions

View File

@ -1,5 +1,5 @@
import discord
from discord.ext import commands
from discord.ext import commands, tasks
import os
from utils.database import Base, engine
@ -14,6 +14,7 @@ class MyBot(commands.Bot):
)
async def setup_hook(self):
delete_accounts_task.start()
for ext in os.listdir("./code/cogs"):
if ext.endswith(".py"):
await self.load_extension(f"cogs.{ext[:-3]}")
@ -28,7 +29,14 @@ async def on_ready():
config.LOG.info(f"{bot.user} has connected to Discord.")
if __name__ == "__main__":
@tasks.loop(minutes=1)
async def delete_accounts_task():
from utils.jellyfin_delete import delete_accounts
Base.metadata.create_all(bind=engine)
delete_accounts()
if __name__ == "__main__":
config.load_config()
bot.run(config.BOT_TOKEN)

View File

@ -1,10 +1,9 @@
import discord
from discord import app_commands
from discord.ext import commands, tasks
from discord.ext import commands
from utils.database import Session
from utils.jellyfin_create import create_jellyfin_account
from utils.jellyfin_delete import delete_accounts
from utils.models import JellyfinAccounts
from utils.config import (
JELLYFIN_PUBLIC_URL,
@ -17,9 +16,6 @@ class NewAccount(commands.Cog):
def __init__(self, bot):
self.bot = bot
def cog_load(self):
self.delete_accounts_loop.start()
@app_commands.command()
@app_commands.check(lambda inter: JELLYFIN_ENABLED)
async def newaccount(self, interaction: discord.Interaction) -> None:
@ -91,10 +87,6 @@ class NewAccount(commands.Cog):
embed=embed, ephemeral=True
)
@tasks.loop(minutes=1)
async def delete_accounts_loop(self):
delete_accounts()
async def setup(bot):
await bot.add_cog(NewAccount(bot))

View File

@ -1,6 +1,10 @@
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
import os
if not os.path.exists("data"):
os.makedirs("data")
database_url = "sqlite:///data/cordarr.db"