Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Makiyu-py committed Oct 27, 2021
1 parent 6e2cb76 commit 60dcc53
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 12 deletions.
55 changes: 49 additions & 6 deletions discord/webhook/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,21 @@ def get_webhook_message(
message_id: int,
*,
session: aiohttp.ClientSession,
thread_id: Optional[int] = None,
) -> Response[MessagePayload]:
params = {}

if thread_id:
params['thread_id'] = thread_id

route = Route(
'GET',
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
webhook_id=webhook_id,
webhook_token=token,
message_id=message_id,
)
return self.request(route, session)
return self.request(route, session, params=params)

def edit_webhook_message(
self,
Expand All @@ -291,18 +297,24 @@ def edit_webhook_message(
message_id: int,
*,
session: aiohttp.ClientSession,
thread_id: Optional[int] = None,
payload: Optional[Dict[str, Any]] = None,
multipart: Optional[List[Dict[str, Any]]] = None,
files: Optional[List[File]] = None,
) -> Response[Message]:
params = {}

if thread_id:
params['thread_id'] = thread_id

route = Route(
'PATCH',
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
webhook_id=webhook_id,
webhook_token=token,
message_id=message_id,
)
return self.request(route, session, payload=payload, multipart=multipart, files=files)
return self.request(route, session, params=params, payload=payload, multipart=multipart, files=files)

def delete_webhook_message(
self,
Expand All @@ -311,15 +323,21 @@ def delete_webhook_message(
message_id: int,
*,
session: aiohttp.ClientSession,
thread_id: Optional[int] = None,
) -> Response[None]:
params = {}

if thread_id:
params['thread_id'] = thread_id

route = Route(
'DELETE',
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
webhook_id=webhook_id,
webhook_token=token,
message_id=message_id,
)
return self.request(route, session)
return self.request(route, session, params=params)

def fetch_webhook(
self,
Expand Down Expand Up @@ -1429,7 +1447,12 @@ async def send(

return msg

async def fetch_message(self, id: int, /) -> WebhookMessage:
async def fetch_message(
self,
id: int,
*,
thread_id: Optional[int] = None
) -> WebhookMessage:
"""|coro|
Retrieves a single :class:`~discord.WebhookMessage` owned by this webhook.
Expand All @@ -1440,6 +1463,8 @@ async def fetch_message(self, id: int, /) -> WebhookMessage:
------------
id: :class:`int`
The message ID to look for.
thread_id: Optional[:class:`int`]
The ID of the thread where the message is.
Raises
--------
Expand Down Expand Up @@ -1467,6 +1492,7 @@ async def fetch_message(self, id: int, /) -> WebhookMessage:
self.token,
id,
session=self.session,
thread_id=thread_id,
)
return self._create_message(data)

Expand All @@ -1481,6 +1507,7 @@ async def edit_message(
files: List[File] = MISSING,
view: Optional[View] = MISSING,
allowed_mentions: Optional[AllowedMentions] = None,
thread: Optional[Snowflake] = MISSING
) -> WebhookMessage:
"""|coro|
Expand Down Expand Up @@ -1522,7 +1549,9 @@ async def edit_message(
the view is removed. The webhook must have state attached, similar to
:meth:`send`.
.. versionadded:: 2.0
.. versionadded:: 2.
thread: Optional[:class:`~discord.abc.Snowflake`]
The thread where the message is.
Raises
-------
Expand Down Expand Up @@ -1564,12 +1593,18 @@ async def edit_message(
allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions,
)

thread_id: Optional[int] = None
if thread_id is not MISSING:
thread_id = thread.id

adapter = async_context.get()
data = await adapter.edit_webhook_message(
self.id,
self.token,
message_id,
session=self.session,
thread_id=thread_id,
payload=params.payload,
multipart=params.multipart,
files=params.files,
Expand All @@ -1580,7 +1615,12 @@ async def edit_message(
self._state.store_view(view, message_id)
return message

async def delete_message(self, message_id: int, /) -> None:
async def delete_message(
self,
message_id: int,
*,
thread_id: Optional[int] = None
) -> None:
"""|coro|
Deletes a message owned by this webhook.
Expand All @@ -1594,6 +1634,8 @@ async def delete_message(self, message_id: int, /) -> None:
------------
message_id: :class:`int`
The message ID to delete.
thread_id: Optional[:class:`int`]
The ID of the thread where the message is.
Raises
-------
Expand All @@ -1611,4 +1653,5 @@ async def delete_message(self, message_id: int, /) -> None:
self.token,
message_id,
session=self.session,
thread_id=thread_id,
)
55 changes: 49 additions & 6 deletions discord/webhook/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,21 @@ def get_webhook_message(
message_id: int,
*,
session: Session,
thread_id: Optional[int] = None,
):
params = {}

if thread_id:
params['thread_id'] = thread_id

route = Route(
'GET',
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
webhook_id=webhook_id,
webhook_token=token,
message_id=message_id,
)
return self.request(route, session)
return self.request(route, session, params=params)

def edit_webhook_message(
self,
Expand All @@ -298,18 +304,24 @@ def edit_webhook_message(
message_id: int,
*,
session: Session,
thread_id: Optional[int] = None,
payload: Optional[Dict[str, Any]] = None,
multipart: Optional[List[Dict[str, Any]]] = None,
files: Optional[List[File]] = None,
):
params = {}

if thread_id:
params['thread_id'] = thread_id

route = Route(
'PATCH',
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
webhook_id=webhook_id,
webhook_token=token,
message_id=message_id,
)
return self.request(route, session, payload=payload, multipart=multipart, files=files)
return self.request(route, session, params=params, payload=payload, multipart=multipart, files=files)

def delete_webhook_message(
self,
Expand All @@ -318,15 +330,21 @@ def delete_webhook_message(
message_id: int,
*,
session: Session,
thread_id: Optional[int] = None,
):
params = {}

if thread_id:
params['thread_id'] = thread_id

route = Route(
'DELETE',
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
webhook_id=webhook_id,
webhook_token=token,
message_id=message_id,
)
return self.request(route, session)
return self.request(route, session, params=params)

def fetch_webhook(
self,
Expand Down Expand Up @@ -920,7 +938,12 @@ def send(
if wait:
return self._create_message(data)

def fetch_message(self, id: int, /) -> SyncWebhookMessage:
def fetch_message(
self,
id: int,
*,
thread_id: Optional[int] = None
) -> SyncWebhookMessage:
"""Retrieves a single :class:`~discord.SyncWebhookMessage` owned by this webhook.
.. versionadded:: 2.0
Expand All @@ -929,6 +952,8 @@ def fetch_message(self, id: int, /) -> SyncWebhookMessage:
------------
id: :class:`int`
The message ID to look for.
thread_id: Optional[:class:`int`]
The ID of the thread where the message is.
Raises
--------
Expand Down Expand Up @@ -956,6 +981,7 @@ def fetch_message(self, id: int, /) -> SyncWebhookMessage:
self.token,
id,
session=self.session,
thread_id=thread_id,
)
return self._create_message(data)

Expand All @@ -969,6 +995,7 @@ def edit_message(
file: File = MISSING,
files: List[File] = MISSING,
allowed_mentions: Optional[AllowedMentions] = None,
thread: Optional[Snowflake] = MISSING,
) -> SyncWebhookMessage:
"""Edits a message owned by this webhook.
Expand Down Expand Up @@ -996,6 +1023,8 @@ def edit_message(
allowed_mentions: :class:`AllowedMentions`
Controls the mentions being processed in this message.
See :meth:`.abc.Messageable.send` for more information.
thread: Optional[:class:`~discord.abc.Snowflake`]
The thread where the message is.
Raises
-------
Expand Down Expand Up @@ -1025,19 +1054,30 @@ def edit_message(
previous_allowed_mentions=previous_mentions,
)
adapter: WebhookAdapter = _get_webhook_adapter()

thread_id: Optional[int] = None
if thread is not MISSING:
thread_id = thread.id

data = adapter.edit_webhook_message(
self.id,
self.token,
message_id,
session=self.session,
thread_id=thread_id,
payload=params.payload,
multipart=params.multipart,
files=params.files,
)
return self._create_message(data)

def delete_message(self, message_id: int, /) -> None:
"""Deletes a message owned by this webhook.
def delete_message(
self,
message_id: int,
*,
thread_id: Optional[int] = None
) -> None:
"""Deletes a message owned by this webhook.
This is a lower level interface to :meth:`WebhookMessage.delete` in case
you only have an ID.
Expand All @@ -1048,6 +1088,8 @@ def delete_message(self, message_id: int, /) -> None:
------------
message_id: :class:`int`
The message ID to delete.
thread_id: Optional[:class:`int`]
The ID of the thread where the message is.
Raises
-------
Expand All @@ -1065,4 +1107,5 @@ def delete_message(self, message_id: int, /) -> None:
self.token,
message_id,
session=self.session,
thread_id=thread_id,
)

0 comments on commit 60dcc53

Please sign in to comment.