Fixed commands.py not having database access

This commit is contained in:
2026-01-12 23:15:51 +01:00
parent 747d01a652
commit 5662f079eb

View File

@@ -23,7 +23,6 @@ from nextcord import application_command
class Commands(commands.Cog): class Commands(commands.Cog):
def __init__(self, botData : RuntimeBotData): def __init__(self, botData : RuntimeBotData):
self.botData = botData self.botData = botData
self.db = botData.db
self._last_member = None self._last_member = None
@application_command.slash_command() @application_command.slash_command()
@@ -149,8 +148,8 @@ class Commands(commands.Cog):
@application_command.slash_command() @application_command.slash_command()
@commands.has_permissions(administrator=True) @commands.has_permissions(administrator=True)
async def query(self, interaction: nextcord.Interaction, query: str): async def query(self, interaction: nextcord.Interaction, query: str):
self.db.cursor.execute(query) self.botData.db.cursor.execute(query)
self.db.conn.commit() self.botData.db.conn.commit()
await interaction.response.send_message("ok") await interaction.response.send_message("ok")
@application_command.slash_command() @application_command.slash_command()
@@ -171,11 +170,11 @@ class Commands(commands.Cog):
if result.status_code != 200: if result.status_code != 200:
raise Exception("Failed to get user id") raise Exception("Failed to get user id")
id = result.json()["id"] id = result.json()["id"]
existing_account = self.db.x_get_account_by_id(id) existing_account = self.botData.db.x_get_account_by_id(id)
if existing_account != None: if existing_account != None:
if existing_account.download_mode == download_mode: if existing_account.download_mode == download_mode:
raise Exception("Account is already on download list") raise Exception("Account is already on download list")
self.db.x_update_account_properties(id, updates=[(schema_x_accounts.download_mode, download_mode)]) self.botData.db.x_update_account_properties(id, updates=[(schema_x_accounts.download_mode, download_mode)])
if download_mode == DownloadMode.DOWNLOAD_ALL: if download_mode == DownloadMode.DOWNLOAD_ALL:
await interaction.followup.send("Added " + handle + " to download list (with full check)") await interaction.followup.send("Added " + handle + " to download list (with full check)")
elif download_mode == DownloadMode.NO_DOWNLOAD: elif download_mode == DownloadMode.NO_DOWNLOAD:
@@ -198,7 +197,7 @@ class Commands(commands.Cog):
return return
query =f'SELECT {schema_x_posts.id}, {schema_x_posts.account_id}, {schema_x_posts.action_taken} FROM {schema_x_posts.table} WHERE {schema_x_posts.discord_post_id} = %s ' query =f'SELECT {schema_x_posts.id}, {schema_x_posts.account_id}, {schema_x_posts.action_taken} FROM {schema_x_posts.table} WHERE {schema_x_posts.discord_post_id} = %s '
result = self.db.query_get(query, ([message.id]), count = 1) result = self.botData.db.query_get(query, ([message.id]), count = 1)
if result is None: if result is None:
await interaction.response.send_message("post not found in database", ephemeral=True) await interaction.response.send_message("post not found in database", ephemeral=True)
return return
@@ -208,7 +207,7 @@ class Commands(commands.Cog):
return return
await discordHelper.edit_existing_embed_color(message, nextcord.Colour.green()) await discordHelper.edit_existing_embed_color(message, nextcord.Colour.green())
result = self.db.x_update_post(result[schema_x_posts.id], message.id, 0, ActionTaken.Accepted) result = self.botData.db.x_update_post(result[schema_x_posts.id], message.id, 0, ActionTaken.Accepted)
await interaction.response.send_message("post approved", ephemeral=True) await interaction.response.send_message("post approved", ephemeral=True)
@application_command.message_command(guild_ids=[1043267878851457096]) @application_command.message_command(guild_ids=[1043267878851457096])
@@ -218,7 +217,7 @@ class Commands(commands.Cog):
return return
query =f'SELECT {schema_x_posts.id}, {schema_x_posts.account_id}, {schema_x_posts.action_taken} FROM {schema_x_posts.table} WHERE {schema_x_posts.discord_post_id} = %s ' query =f'SELECT {schema_x_posts.id}, {schema_x_posts.account_id}, {schema_x_posts.action_taken} FROM {schema_x_posts.table} WHERE {schema_x_posts.discord_post_id} = %s '
result = self.db.query_get(query, ([message.id]), count = 1) result = self.botData.db.query_get(query, ([message.id]), count = 1)
if result is None: if result is None:
await interaction.response.send_message("post not found in database", ephemeral=True) await interaction.response.send_message("post not found in database", ephemeral=True)
return return
@@ -228,7 +227,7 @@ class Commands(commands.Cog):
return return
await discordHelper.edit_existing_embed_color(message, nextcord.Colour.yellow()) await discordHelper.edit_existing_embed_color(message, nextcord.Colour.yellow())
result = self.db.x_update_post(result[schema_x_posts.id], message.id, 0, ActionTaken.Hidden) result = self.botData.db.x_update_post(result[schema_x_posts.id], message.id, 0, ActionTaken.Hidden)
await interaction.response.send_message("post hidden", ephemeral=True) await interaction.response.send_message("post hidden", ephemeral=True)
@application_command.message_command(guild_ids=[1043267878851457096]) @application_command.message_command(guild_ids=[1043267878851457096])
@@ -238,13 +237,13 @@ class Commands(commands.Cog):
return return
query =f'SELECT {schema_x_posts.id} FROM {schema_x_posts.table} WHERE {schema_x_posts.discord_post_id} = %s' query =f'SELECT {schema_x_posts.id} FROM {schema_x_posts.table} WHERE {schema_x_posts.discord_post_id} = %s'
result = self.db.query_get(query, ([message.id]), count = 1) result = self.botData.db.query_get(query, ([message.id]), count = 1)
if result is None: if result is None:
await interaction.response.send_message("post not found in database", ephemeral=True) await interaction.response.send_message("post not found in database", ephemeral=True)
return return
await message.delete() await message.delete()
result = self.db.x_update_post(result["id"], 0, 0, ActionTaken.Rejected) result = self.botData.db.x_update_post(result["id"], 0, 0, ActionTaken.Rejected)
await interaction.response.send_message("post deleted", ephemeral=True) await interaction.response.send_message("post deleted", ephemeral=True)
def setup(bot: commands.Bot, botData: RuntimeBotData): def setup(bot: commands.Bot, botData: RuntimeBotData):