From 008f79adeea828c086e7abefb35baeaa0d315cb0 Mon Sep 17 00:00:00 2001 From: dolfies Date: Mon, 11 Apr 2022 12:17:27 -0400 Subject: [PATCH] Rebase to latest upstream --- .github/workflows/lint.yml | 2 +- discord/state.py | 3 ++- discord/threads.py | 2 +- discord/webhook/async_.py | 19 ++++++++++++++----- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3c75626a6..0f17fb701 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -37,7 +37,7 @@ jobs: - name: Install pyright run: | - npm install -g pyright + npm install -g pyright@1.1.235 - name: Run pyright run: | diff --git a/discord/state.py b/discord/state.py index 322204ba8..8e0e593d0 100644 --- a/discord/state.py +++ b/discord/state.py @@ -1980,7 +1980,8 @@ class ConnectionState: _log.debug('WEBHOOKS_UPDATE referencing an unknown guild ID: %s. Discarding', data['guild_id']) return - channel = guild.get_channel(int(data['channel_id'])) + channel_id = utils._get_as_snowflake(data, 'channel_id') + channel = guild.get_channel(channel_id) # type: ignore # None is okay here if channel is not None: self.dispatch('webhooks_update', channel) else: diff --git a/discord/threads.py b/discord/threads.py index ba1c1151c..ca8a220c0 100644 --- a/discord/threads.py +++ b/discord/threads.py @@ -543,7 +543,7 @@ class Thread(Messageable, Hashable): Specifies the slowmode rate limit for user in this thread, in seconds. A value of ``0`` disables slowmode. The maximum value possible is ``21600``. reason: Optional[:class:`str`] - The reason for editing the thread. Shows up on the audit log. + The reason for editing this thread. Shows up on the audit log. Raises ------- diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index 53d25981c..e9c033461 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -46,7 +46,7 @@ from ..asset import Asset from ..partial_emoji import PartialEmoji from ..http import Route, handle_message_parameters, HTTPClient from ..mixins import Hashable -from ..channel import PartialMessageable +from ..channel import TextChannel, PartialMessageable from ..file import File __all__ = ( @@ -69,7 +69,7 @@ if TYPE_CHECKING: from ..http import Response from ..guild import Guild from ..emoji import Emoji - from ..channel import TextChannel + from ..channel import TextChannel, VoiceChannel from ..abc import Snowflake import datetime from ..types.webhook import ( @@ -744,8 +744,8 @@ class BaseWebhook(Hashable): return self._state and self._state._get_guild(self.guild_id) @property - def channel(self) -> Optional[TextChannel]: - """Optional[:class:`TextChannel`]: The text channel this webhook belongs to. + def channel(self) -> Optional[Union[VoiceChannel, TextChannel]]: + """Optional[Union[:class:`VoiceChannel`, :class:`TextChannel`]]: The channel this webhook belongs to. If this is a partial webhook, then this will always return ``None``. """ @@ -1156,7 +1156,16 @@ class Webhook(BaseWebhook): def _create_message(self, data, *, thread: Snowflake): state = _WebhookState(self, parent=self._state, thread=thread) # state may be artificial (unlikely at this point...) - channel = self.channel or PartialMessageable(state=self._state, id=int(data['channel_id'])) # type: ignore + if thread is MISSING: + channel = self.channel or PartialMessageable(state=self._state, id=int(data['channel_id'])) # type: ignore + else: + channel = self.channel + if isinstance(channel, TextChannel): + channel = channel.get_thread(thread.id) + + if channel is None: + channel = PartialMessageable(state=self._state, id=int(data['channel_id'])) # type: ignore + # state is artificial return WebhookMessage(data=data, state=state, channel=channel) # type: ignore