|
| 1 | +from discord import Interaction, Message, NotFound |
| 2 | +from discord.app_commands import command |
| 3 | +from discord.app_commands.commands import describe |
| 4 | +from discord.ext.commands.bot import Bot |
| 5 | +from discord.ext.commands.cog import Cog, GroupCog |
| 6 | + |
| 7 | +from data.admin.config_auto import Config |
| 8 | +from ui.modals.edit_post import EditPostModal |
| 9 | +from utils.decorators import is_staff |
| 10 | + |
| 11 | + |
| 12 | +class EditPost(Cog): |
| 13 | + def __init__(self, bot: Bot): |
| 14 | + self.bot = bot |
| 15 | + self.config = Config(self.bot.pool) |
| 16 | + |
| 17 | + @is_staff() |
| 18 | + @command( |
| 19 | + name="post-edit", |
| 20 | + description="A command to allow staff to edit an existing post created by the PPH bot", |
| 21 | + ) |
| 22 | + @describe(message_id="The ID post/message to edit") |
| 23 | + async def edit_post(self, interaction: Interaction, message_id: str): |
| 24 | + |
| 25 | + if not interaction.channel_id: |
| 26 | + return |
| 27 | + |
| 28 | + try: |
| 29 | + message = await interaction.channel.fetch_message(int(message_id)) |
| 30 | + except (ValueError, NotFound): |
| 31 | + await interaction.response.send_message( |
| 32 | + "Message not found in this channel.", ephemeral=True |
| 33 | + ) |
| 34 | + return |
| 35 | + |
| 36 | + if self.bot.user is not None and message.author.id != self.bot.user.id: |
| 37 | + await interaction.response.send_message( |
| 38 | + "Cannot edit message that isn't from PPH bot!", ephemeral=True |
| 39 | + ) |
| 40 | + return |
| 41 | + |
| 42 | + post_id = message.id |
| 43 | + content = message.content |
| 44 | + edit_post_modal = EditPostModal( |
| 45 | + channel_id=interaction.channel_id, |
| 46 | + post_id=post_id, |
| 47 | + original_content=content, |
| 48 | + bot=self.bot, |
| 49 | + ) |
| 50 | + |
| 51 | + await interaction.response.send_modal(edit_post_modal) |
| 52 | + |
| 53 | + |
| 54 | +async def setup(bot: Bot): |
| 55 | + await bot.add_cog(EditPost(bot)) |
0 commit comments