-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement soundmojis #1281
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add :attr:`PartialSoundboardSound.mention`, :attr:`SoundboardSound.mention`, :attr:`GuildSoundboardSound.mention`, :attr:`Message.soundboard_sounds` and :attr:`ForwardedMessage.soundboard_sounds`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 @@ | |
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 @@ | |
"components", | ||
"guild", | ||
"poll", | ||
"soundboard_sounds", | ||
"_edited_timestamp", | ||
"_role_subscription_data", | ||
) | ||
|
@@ -1200,6 +1206,11 @@ | |
except AttributeError: | ||
self.guild = state._get_guild(utils._get_as_snowflake(data, "guild_id")) | ||
|
||
self.soundboard_sounds: List[GuildSoundboardSound] = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should also handle this for message updates. |
||
GuildSoundboardSound(data=d, state=state, guild_id=self.guild.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this won't necessarily be the same guild (or even from any guild at all), soundmojis can be from other guilds or default sounds. Example message data snippets: guild sound "soundboard_sounds": [
{
"name": "test",
"sound_id": "123123",
"volume": 0.699999988079071,
"emoji_id": "456456",
"emoji_name": null,
"guild_id": "789789",
"available": true
}
], default sound "soundboard_sounds": [
{
"name": "airhorn",
"sound_id": "2",
"volume": 1.0,
"emoji_id": null,
"emoji_name": "🔊",
"available": true
}
], |
||
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 @@ | |
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 @@ | |
"stickers", | ||
"components", | ||
"guild_id", | ||
"soundboard_sounds", | ||
) | ||
|
||
def __init__( | ||
|
@@ -2956,6 +2972,11 @@ | |
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__}>" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,14 @@ def created_at(self) -> Optional[datetime.datetime]: | |
return None | ||
return snowflake_time(self.id) | ||
|
||
@property | ||
def mention(self) -> str: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
""":class:`str`: Returns a string that allows you to mention the given soundboard sound. | ||
|
||
.. versionadded:: 2.11 | ||
""" | ||
return f"<sound:0:{self.id}>" | ||
|
||
@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"<sound:{self.guild_id}:{self.id}>" | ||
|
||
async def edit( | ||
self, | ||
*, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.