Skip to content
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 voice_channel_effect event #993

Merged
merged 27 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2820ed9
feat: implement `voice_channel_effect` event
shiftinv Mar 30, 2023
e37a22e
feat: add cached fields to raw event
shiftinv Mar 30, 2023
c63a166
docs: add/update documentation
shiftinv Mar 30, 2023
23dfb20
docs: add changelog entry
shiftinv Mar 30, 2023
5d6ff11
chore(types): use `total=False` for effect typeddict
shiftinv Mar 30, 2023
c8bdfd7
chore: run autotyping
shiftinv Mar 30, 2023
4cce725
chore: add another todo
shiftinv Mar 30, 2023
b46070a
refactor: move `VoiceChannelEffect` to `disnake.channel`
shiftinv Apr 1, 2023
ce08c34
feat: add repr
shiftinv Apr 1, 2023
1b6ba55
Merge remote-tracking branch 'upstream/master' into feature/voice-cha…
shiftinv Apr 9, 2023
4e8a8e3
Merge remote-tracking branch 'upstream/master' into feature/voice-cha…
shiftinv May 2, 2023
0264c76
Merge remote-tracking branch 'upstream/master' into feature/voice-cha…
shiftinv Jul 1, 2023
378de67
chore(docs): update versionadded
shiftinv Jul 1, 2023
b6e3608
feat: add soundboard effect fields
shiftinv Jul 1, 2023
1ee704a
chore: remove obsolete todos
shiftinv Jul 1, 2023
4202e58
docs: link new events on page
shiftinv Jul 2, 2023
b27a6de
revert: remove soundboard fields, moved to other PR
shiftinv Jul 3, 2023
ee4f70c
Merge remote-tracking branch 'upstream/master' into feature/voice-cha…
shiftinv Jun 4, 2024
f09a4fb
Merge remote-tracking branch 'upstream/master' into feature/voice-cha…
shiftinv Aug 9, 2024
1a0f017
Merge remote-tracking branch 'upstream/master' into feature/voice-cha…
shiftinv Aug 16, 2024
1d1291e
lint: make pylance happy
shiftinv Aug 16, 2024
5848c61
refactor: rename to `cached_member`
shiftinv Aug 16, 2024
b394539
refactor: create `VoiceChannelEffect` outside of raw model
shiftinv Aug 19, 2024
75a4c8f
refactor: move emoji conversion into `VoiceChannelEffect`, use emoji …
shiftinv Aug 19, 2024
beeb8f0
Merge remote-tracking branch 'upstream/master' into feature/voice-cha…
shiftinv Nov 13, 2024
2a7ced2
docs: add link to raw event
shiftinv Nov 13, 2024
022dc36
docs: effects will always happen in `VoiceChannel`s
shiftinv Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: move VoiceChannelEffect to disnake.channel
  • Loading branch information
shiftinv committed Apr 1, 2023
commit b46070a6475466bc70455aa5d46923821f84cdb1
41 changes: 41 additions & 0 deletions disnake/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
ThreadLayout,
ThreadSortOrder,
VideoQualityMode,
VoiceChannelEffectAnimationType,
try_enum,
try_enum_to_int,
)
Expand All @@ -50,6 +51,7 @@
from .utils import MISSING

__all__ = (
"VoiceChannelEffect",
"TextChannel",
"VoiceChannel",
"StageChannel",
Expand Down Expand Up @@ -87,13 +89,52 @@
)
from .types.snowflake import SnowflakeList
from .types.threads import ThreadArchiveDurationLiteral
from .types.voice import VoiceChannelEffect as VoiceChannelEffectPayload
from .ui.action_row import Components, MessageUIComponent
from .ui.view import View
from .user import BaseUser, ClientUser, User
from .voice_region import VoiceRegion
from .webhook import Webhook


class VoiceChannelEffect:
"""An effect sent by a member in a voice channel.

Different sets of attributes will be present, depending on the type of effect.

.. versionadded:: 2.9

Attributes
----------
emoji: Optional[:class:`PartialEmoji`]
The emoji, if this is an emoji reaction effect.
animation_type: Optional[:class:`VoiceChannelEffectAnimationType`]
The animation type, if this is an emoji reaction effect.
animation_id: Optional[:class:`int`]
The animation ID, if this is an emoji reaction effect.
"""

__slots__ = (
"emoji",
"animation_type",
"animation_id",
)

def __init__(self, data: VoiceChannelEffectPayload, emoji: Optional[PartialEmoji]) -> None:
# TODO: store raw payload as well?

self.emoji: Optional[PartialEmoji] = emoji
self.animation_type = (
try_enum(VoiceChannelEffectAnimationType, value)
if (value := data.get("animation_type")) is not None
else None
)
try:
self.animation_id: Optional[int] = int(data["animation_id"])
except KeyError:
self.animation_id: Optional[int] = None


async def _single_delete_strategy(messages: Iterable[Message]) -> None:
for m in messages:
await m.delete()
Expand Down
43 changes: 2 additions & 41 deletions disnake/raw_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import datetime
from typing import TYPE_CHECKING, List, Literal, Optional, Set, Union, cast

from .enums import ChannelType, VoiceChannelEffectAnimationType, try_enum
from .channel import VoiceChannelEffect
from .enums import ChannelType, try_enum
from .utils import get_slots

if TYPE_CHECKING:
Expand All @@ -28,7 +29,6 @@
TypingStartEvent,
VoiceChannelEffectSendEvent,
)
from .types.voice import VoiceChannelEffect as VoiceChannelEffectPayload
from .user import User


Expand All @@ -45,7 +45,6 @@
"RawThreadMemberRemoveEvent",
"RawTypingEvent",
"RawGuildMemberRemoveEvent",
"VoiceChannelEffect",
"RawVoiceChannelEffectEvent",
)

Expand Down Expand Up @@ -428,44 +427,6 @@ def __init__(self, user: Union[User, Member], guild_id: int) -> None:
self.guild_id: int = guild_id


class VoiceChannelEffect(_RawReprMixin):
"""An effect sent by a member in a voice channel.

Different sets of attributes will be present, depending on the type of effect.

.. versionadded:: 2.9

Attributes
----------
emoji: Optional[:class:`PartialEmoji`]
The emoji, if this is an emoji reaction effect.
animation_type: Optional[:class:`VoiceChannelEffectAnimationType`]
The animation type, if this is an emoji reaction effect.
animation_id: Optional[:class:`int`]
The animation ID, if this is an emoji reaction effect.
"""

__slots__ = (
"emoji",
"animation_type",
"animation_id",
)

def __init__(self, data: VoiceChannelEffectPayload, emoji: Optional[PartialEmoji]) -> None:
# TODO: store raw payload as well?

self.emoji: Optional[PartialEmoji] = emoji
self.animation_type = (
try_enum(VoiceChannelEffectAnimationType, value)
if (value := data.get("animation_type")) is not None
else None
)
try:
self.animation_id: Optional[int] = int(data["animation_id"])
except KeyError:
self.animation_id: Optional[int] = None


class RawVoiceChannelEffectEvent(_RawReprMixin):
"""Represents the event payload for an :func:`on_raw_voice_channel_effect` event.

Expand Down