You've already forked JapariArchive
Fixed commands.py not having database access
This commit is contained in:
21
commands.py
21
commands.py
@@ -23,7 +23,6 @@ from nextcord import application_command
|
||||
class Commands(commands.Cog):
|
||||
def __init__(self, botData : RuntimeBotData):
|
||||
self.botData = botData
|
||||
self.db = botData.db
|
||||
self._last_member = None
|
||||
|
||||
@application_command.slash_command()
|
||||
@@ -149,8 +148,8 @@ class Commands(commands.Cog):
|
||||
@application_command.slash_command()
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def query(self, interaction: nextcord.Interaction, query: str):
|
||||
self.db.cursor.execute(query)
|
||||
self.db.conn.commit()
|
||||
self.botData.db.cursor.execute(query)
|
||||
self.botData.db.conn.commit()
|
||||
await interaction.response.send_message("ok")
|
||||
|
||||
@application_command.slash_command()
|
||||
@@ -171,11 +170,11 @@ class Commands(commands.Cog):
|
||||
if result.status_code != 200:
|
||||
raise Exception("Failed to get user 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.download_mode == download_mode:
|
||||
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:
|
||||
await interaction.followup.send("Added " + handle + " to download list (with full check)")
|
||||
elif download_mode == DownloadMode.NO_DOWNLOAD:
|
||||
@@ -198,7 +197,7 @@ class Commands(commands.Cog):
|
||||
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 '
|
||||
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:
|
||||
await interaction.response.send_message("post not found in database", ephemeral=True)
|
||||
return
|
||||
@@ -208,7 +207,7 @@ class Commands(commands.Cog):
|
||||
return
|
||||
|
||||
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)
|
||||
|
||||
@application_command.message_command(guild_ids=[1043267878851457096])
|
||||
@@ -218,7 +217,7 @@ class Commands(commands.Cog):
|
||||
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 '
|
||||
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:
|
||||
await interaction.response.send_message("post not found in database", ephemeral=True)
|
||||
return
|
||||
@@ -228,7 +227,7 @@ class Commands(commands.Cog):
|
||||
return
|
||||
|
||||
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)
|
||||
|
||||
@application_command.message_command(guild_ids=[1043267878851457096])
|
||||
@@ -238,13 +237,13 @@ class Commands(commands.Cog):
|
||||
return
|
||||
|
||||
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:
|
||||
await interaction.response.send_message("post not found in database", ephemeral=True)
|
||||
return
|
||||
|
||||
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)
|
||||
|
||||
def setup(bot: commands.Bot, botData: RuntimeBotData):
|
||||
|
||||
Reference in New Issue
Block a user