From 091b54f65267707c21bb78bbd0e173affe699aa6 Mon Sep 17 00:00:00 2001 From: Snipy7374 <100313469+Snipy7374@users.noreply.github.com> Date: Thu, 30 Jan 2025 00:21:14 +0100 Subject: [PATCH] feat: implement soundmojis --- changelog/1280.feature.rst | 1 + disnake/message.py | 23 ++++++++++++++++++++++- disnake/soundboard.py | 18 ++++++++++++++++++ disnake/types/message.py | 3 +++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 changelog/1280.feature.rst diff --git a/changelog/1280.feature.rst b/changelog/1280.feature.rst new file mode 100644 index 0000000000..133c35a31e --- /dev/null +++ b/changelog/1280.feature.rst @@ -0,0 +1 @@ +Add :attr:`PartialSoundboardSound.mention`, :attr:`SoundboardSound.mention`, :attr:`GuildSoundboardSound.mention`, :attr:`Message.soundboard_sounds` and :attr:`ForwardedMessage.soundboard_sounds`. diff --git a/disnake/message.py b/disnake/message.py index 9dcbdfe16b..3911f464fb 100644 --- a/disnake/message.py +++ b/disnake/message.py @@ -38,7 +38,7 @@ from .errors import HTTPException from .file import File from .flags import AttachmentFlags, MessageFlags -from .guild import Guild +from .guild import Guild, GuildSoundboardSound from .member import Member from .mixins import Hashable from .partial_emoji import PartialEmoji @@ -1097,6 +1097,11 @@ class Message(Hashable): The poll contained in this message. .. versionadded:: 2.10 + + soundboard_sounds: List[:class:`GuildSoundboardSound`] + A list of soundboard sounds in the message. + + .. versionadded:: 2.11 """ __slots__ = ( @@ -1135,6 +1140,7 @@ class Message(Hashable): "components", "guild", "poll", + "soundboard_sounds", "_edited_timestamp", "_role_subscription_data", ) @@ -1200,6 +1206,11 @@ def __init__( except AttributeError: self.guild = state._get_guild(utils._get_as_snowflake(data, "guild_id")) + self.soundboard_sounds: List[GuildSoundboardSound] = [ + GuildSoundboardSound(data=d, state=state, guild_id=self.guild.id) + for d in data.get("soundboard_sounds", []) + ] + self._interaction: Optional[InteractionReference] = ( InteractionReference(state=state, guild=self.guild, data=interaction) if (interaction := data.get("interaction")) @@ -2885,6 +2896,10 @@ class ForwardedMessage: A list of components in the message. guild_id: Optional[:class:`int`] The guild ID where the message was forwarded from, if applicable. + soundboard_sounds: List[:class:`GuildSoundboardSound`] + A list of soundboard sounds in the message. + + .. versionadded:: 2.11 """ __slots__ = ( @@ -2902,6 +2917,7 @@ class ForwardedMessage: "stickers", "components", "guild_id", + "soundboard_sounds", ) def __init__( @@ -2956,6 +2972,11 @@ def __init__( if role is not None: self.role_mentions.append(role) + self.soundboard_sounds: List[GuildSoundboardSound] = [ + GuildSoundboardSound(data=d, state=state, guild_id=guild_id or 0) + for d in data.get("soundboard_sounds", []) + ] + def __repr__(self) -> str: return f"<{self.__class__.__name__}>" diff --git a/disnake/soundboard.py b/disnake/soundboard.py index 0d1d701dac..4f772a0bd7 100644 --- a/disnake/soundboard.py +++ b/disnake/soundboard.py @@ -86,6 +86,14 @@ def created_at(self) -> Optional[datetime.datetime]: return None return snowflake_time(self.id) + @property + def mention(self) -> str: + """:class:`str`: Returns a string that allows you to mention the given soundboard sound. + + .. versionadded:: 2.11 + """ + return f"" + @property def url(self) -> str: """:class:`str`: The url for the sound file.""" @@ -230,6 +238,16 @@ def guild(self) -> Guild: # this will most likely never return None return self._state._get_guild(self.guild_id) # type: ignore + @property + def mention(self) -> str: + """:class:`str`: Returns a string that allows you to mention the given soundboard sound. + + .. versionadded:: 2.11 + """ + if self.is_default(): + return super().mention + return f"" + async def edit( self, *, diff --git a/disnake/types/message.py b/disnake/types/message.py index c3f8e4d1e9..f8ac801001 100644 --- a/disnake/types/message.py +++ b/disnake/types/message.py @@ -14,6 +14,7 @@ from .member import Member, UserWithMember from .poll import Poll from .snowflake import Snowflake, SnowflakeList +from .soundboard import GuildSoundboardSound from .sticker import StickerItem from .threads import Thread from .user import User @@ -90,6 +91,7 @@ class ForwardedMessage(TypedDict): mention_roles: NotRequired[SnowflakeList] sticker_items: NotRequired[List[StickerItem]] components: NotRequired[List[Component]] + soundboard_sounds: NotRequired[List[GuildSoundboardSound]] class MessageSnapshot(TypedDict): @@ -149,6 +151,7 @@ class Message(TypedDict): # specific to MESSAGE_CREATE/MESSAGE_UPDATE events guild_id: NotRequired[Snowflake] member: NotRequired[Member] + soundboard_sounds: NotRequired[List[GuildSoundboardSound]] AllowedMentionType = Literal["roles", "users", "everyone"]