From 43667a715abbf9379e26de522e72d2657b321b9e Mon Sep 17 00:00:00 2001 From: "airo.pi_" <47398145+AiroPi@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:23:30 +0100 Subject: [PATCH] feat: pin context message command Allow anyone to pin / unpin messages using Context Message Commands --- config.example.toml | 1 + src/cogs/pin.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/cogs/pin.py 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))