Browse Source

Fix WebhookState not handling reaction emoji

Fix #7842
pull/7791/head
Rapptz 3 years ago
parent
commit
b561024163
  1. 15
      discord/webhook/async_.py

15
discord/webhook/async_.py

@ -43,6 +43,7 @@ from ..enums import try_enum, WebhookType
from ..user import BaseUser, User from ..user import BaseUser, User
from ..flags import MessageFlags from ..flags import MessageFlags
from ..asset import Asset from ..asset import Asset
from ..partial_emoji import PartialEmoji
from ..http import Route, handle_message_parameters, MultipartParameters, HTTPClient from ..http import Route, handle_message_parameters, MultipartParameters, HTTPClient
from ..mixins import Hashable from ..mixins import Hashable
from ..channel import PartialMessageable from ..channel import PartialMessageable
@ -67,6 +68,7 @@ if TYPE_CHECKING:
from ..state import ConnectionState from ..state import ConnectionState
from ..http import Response from ..http import Response
from ..guild import Guild from ..guild import Guild
from ..emoji import Emoji
from ..channel import TextChannel from ..channel import TextChannel
from ..abc import Snowflake from ..abc import Snowflake
from ..ui.view import View from ..ui.view import View
@ -85,6 +87,7 @@ if TYPE_CHECKING:
from ..types.channel import ( from ..types.channel import (
PartialChannel as PartialChannelPayload, PartialChannel as PartialChannelPayload,
) )
from ..types.emoji import PartialEmoji as PartialEmojiPayload
BE = TypeVar('BE', bound=BaseException) BE = TypeVar('BE', bound=BaseException)
_State = Union[ConnectionState, '_WebhookState'] _State = Union[ConnectionState, '_WebhookState']
@ -648,6 +651,18 @@ class _WebhookState:
# state parameter is artificial # state parameter is artificial
return BaseUser(state=self, data=data) # type: ignore return BaseUser(state=self, data=data) # type: ignore
def get_reaction_emoji(self, data: PartialEmojiPayload) -> Union[PartialEmoji, Emoji, str]:
if self._parent is not None:
return self._parent.get_reaction_emoji(data)
emoji_id = utils._get_as_snowflake(data, 'id')
if not emoji_id:
# the name key will be a str
return data['name'] # type: ignore
return PartialEmoji(animated=data.get('animated', False), id=emoji_id, name=data['name']) # type: ignore
@property @property
def http(self) -> Union[HTTPClient, _FriendlyHttpAttributeErrorHelper]: def http(self) -> Union[HTTPClient, _FriendlyHttpAttributeErrorHelper]:
if self._parent is not None: if self._parent is not None:

Loading…
Cancel
Save