from __future__ import annotations import nextcord from nextcord.ui import View from Database.x_classes import ActionTaken from Discord import discordHelper from typing import TYPE_CHECKING if TYPE_CHECKING: from runtimeBotData import RuntimeBotData class XView(View): def __init__(self, botData : RuntimeBotData): self.botData = botData super().__init__(timeout=None, prevent_update=False) @nextcord.ui.button(label="KF Art", custom_id="button-keep", style=nextcord.ButtonStyle.gray) async def button_keep(self, button, interaction : nextcord.Interaction): if not discordHelper.check_permission(interaction): await interaction.response.send_message("No permission", ephemeral=True) return self_message = interaction.message main_post, x_post_id = await discordHelper.get_main_post_and_data(interaction.guild, self_message.embeds[0].author.url, self.botData) self.botData.db.x_update_post(x_post_id, main_post.id, 0, ActionTaken.Accepted) await discordHelper.edit_existing_embed_color(main_post, nextcord.Colour.green()) await self_message.edit(view=None) @nextcord.ui.button(label="Non-KF Art", custom_id="button-hide", style=nextcord.ButtonStyle.gray) async def button_hide(self, button, interaction : nextcord.Interaction): if not discordHelper.check_permission(interaction): await interaction.response.send_message("No permission", ephemeral=True) return self_message = interaction.message main_post, x_post_id = await discordHelper.get_main_post_and_data(interaction.guild, self_message.embeds[0].author.url, self.botData) self.botData.db.x_update_post(x_post_id, main_post.id, 0, ActionTaken.Hidden) await discordHelper.edit_existing_embed_color(main_post, nextcord.Colour.yellow()) await self_message.delete() @nextcord.ui.button(label="Delete", custom_id="button-delete", style=nextcord.ButtonStyle.gray) async def button_delete(self, button, interaction : nextcord.Interaction): if not discordHelper.check_permission(interaction): await interaction.response.send_message("No permission", ephemeral=True) return try: self_message = interaction.message main_post, x_post_id = await discordHelper.get_main_post_and_data(interaction.guild, self_message.embeds[0].author.url, self.botData) print("Deleting", x_post_id, main_post.jump_url) await main_post.delete() await self_message.delete() self.botData.db.x_update_post(x_post_id, 0, 0, ActionTaken.Rejected) except Exception as e: await interaction.response.send_message("Error occured " + str(e), ephemeral=False) class YView(View): def __init__(self, botData : RuntimeBotData): self.botData = botData super().__init__(timeout=None, prevent_update=False) @nextcord.ui.button(label="KF Art", custom_id="y-button-keep", style=nextcord.ButtonStyle.gray) async def button_keep(self, button, interaction : nextcord.Interaction): if not discordHelper.check_permission(interaction): await interaction.response.send_message("No permission", ephemeral=True) return self_message = interaction.message main_post, x_post_id = await discordHelper.get_main_post_and_data(interaction.guild, self_message.content.split(" ")[1], self.botData) self.botData.db.x_update_post(x_post_id, main_post.id, 0, ActionTaken.Accepted) await discordHelper.edit_existing_embed_color(main_post, nextcord.Colour.green()) await self_message.edit(view=None) @nextcord.ui.button(label="Non-KF Art", custom_id="y-button-hide", style=nextcord.ButtonStyle.gray) async def button_hide(self, button, interaction : nextcord.Interaction): if not discordHelper.check_permission(interaction): await interaction.response.send_message("No permission", ephemeral=True) return self_message = interaction.message main_post, x_post_id = await discordHelper.get_main_post_and_data(interaction.guild, self_message.content.split(" ")[1], self.botData) self.botData.db.x_update_post(x_post_id, main_post.id, 0, ActionTaken.Hidden) await discordHelper.edit_existing_embed_color(main_post, nextcord.Colour.yellow()) await self_message.delete() @nextcord.ui.button(label="Delete", custom_id="y-button-delete", style=nextcord.ButtonStyle.gray) async def button_delete(self, button, interaction : nextcord.Interaction): if not discordHelper.check_permission(interaction): await interaction.response.send_message("No permission", ephemeral=True) return try: self_message = interaction.message main_post, x_post_id = await discordHelper.get_main_post_and_data(interaction.guild, self_message.content.split(" ")[1], self.botData) print("Deleting", x_post_id, main_post.jump_url) await main_post.delete() await self_message.delete() self.botData.db.x_update_post(x_post_id, 0, 0, ActionTaken.Rejected) except Exception as e: await interaction.response.send_message("Error occured " + str(e), ephemeral=False)