diff --git a/config.example.toml b/config.example.toml index 06fc4de..8b7f024 100644 --- a/config.example.toml +++ b/config.example.toml @@ -11,4 +11,5 @@ loaded_extensions = [ "colloscope_helper", "birthday", "admin", + "pin", ] diff --git a/src/cogs/pin.py b/src/cogs/pin.py new file mode 100644 index 0000000..6b23da1 --- /dev/null +++ b/src/cogs/pin.py @@ -0,0 +1,35 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +from discord import Message, app_commands +from discord.ext.commands import Cog # pyright: ignore[reportMissingTypeStubs] + +if TYPE_CHECKING: + from discord import Interaction + + from bot import FISABot + + +class Pin(Cog): + def __init__(self, bot: FISABot) -> None: + self.bot = bot + + self.bot.tree.add_command( + app_commands.ContextMenu( + name="Epingler/Desepingler", + callback=self.pin, + ) + ) + + async def pin(self, interaction: Interaction, message: Message): + if message.pinned: + await message.unpin() + await interaction.response.send_message(f"Message {message.jump_url} désépinglé.", ephemeral=True) + else: + await message.pin() + await interaction.response.send_message(f"Message {message.jump_url} épinglé.", ephemeral=True) + + +async def setup(bot: FISABot) -> None: + await bot.add_cog(Pin(bot))