aboutsummaryrefslogtreecommitdiff
path: root/code/cogs/newaccount.py
diff options
context:
space:
mode:
authorParker <contact@pkrm.dev>2025-01-21 20:38:33 -0600
committerParker <contact@pkrm.dev>2025-01-21 20:38:33 -0600
commitb0ea7ab93564f1b2f004f7ea74783508f12f4ff6 (patch)
tree2bf229bff30649598bd651d15fcf1ec9feaf4b13 /code/cogs/newaccount.py
parent023ee141ebf437919a4c0f43ddee18aaefa4cbbc (diff)
Fixes + Use SQLAlchemy
Diffstat (limited to 'code/cogs/newaccount.py')
-rw-r--r--code/cogs/newaccount.py31
1 files changed, 19 insertions, 12 deletions
diff --git a/code/cogs/newaccount.py b/code/cogs/newaccount.py
index 8e17cda..f3f5ac8 100644
--- a/code/cogs/newaccount.py
+++ b/code/cogs/newaccount.py
@@ -1,9 +1,11 @@
import discord
from discord import app_commands
-from discord.ext import commands
-import sqlite3
+from discord.ext import commands, tasks
+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,
JELLYFIN_ENABLED,
@@ -15,19 +17,20 @@ 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:
"""Create a new temporary Jellyfin account"""
# Make sure the user doesn't already have an account
- db = sqlite3.connect("data/cordarr.db")
- cursor = db.cursor()
- cursor.execute(
- "SELECT * FROM jellyfin_accounts WHERE user_id = ?",
- (interaction.user.id,),
- )
- account = cursor.fetchone()
- db.close()
+ with Session() as session:
+ account = (
+ session.query(JellyfinAccounts)
+ .filter(JellyfinAccounts.user_id == interaction.user.id)
+ .first()
+ )
# Account already allocated
if account:
embed = discord.Embed(
@@ -63,8 +66,8 @@ class NewAccount(commands.Cog):
title="Jellyfin Account Information",
description=(
# fmt: off
- "Here is your temporary account information.\n\n",
- f"**Server URL:** `[{JELLYFIN_PUBLIC_URL}]({JELLYFIN_PUBLIC_URL})`\n"
+ "Here is your temporary account information.\n\n"
+ f"**Server URL:** `{JELLYFIN_PUBLIC_URL}`\n"
f"**Username:** `{response[0]}`\n"
f"**Password:** `{response[1]}`\n\n"
"Your account will be automatically deleted in"
@@ -88,6 +91,10 @@ 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))