Browse Source

Fix webhooks and interactions not closing files after a request

pull/9206/head
Rapptz 2 years ago
parent
commit
7e95f98521
  1. 28
      discord/interactions.py
  2. 16
      discord/message.py
  3. 73
      discord/webhook/async_.py
  4. 70
      discord/webhook/sync.py

28
discord/interactions.py

@ -450,7 +450,7 @@ class Interaction(Generic[ClientT]):
"""
previous_mentions: Optional[AllowedMentions] = self._state.allowed_mentions
params = handle_message_parameters(
with handle_message_parameters(
content=content,
attachments=attachments,
embed=embed,
@ -458,19 +458,19 @@ class Interaction(Generic[ClientT]):
view=view,
allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions,
)
adapter = async_context.get()
http = self._state.http
data = await adapter.edit_original_interaction_response(
self.application_id,
self.token,
session=self._session,
proxy=http.proxy,
proxy_auth=http.proxy_auth,
payload=params.payload,
multipart=params.multipart,
files=params.files,
)
) as params:
adapter = async_context.get()
http = self._state.http
data = await adapter.edit_original_interaction_response(
self.application_id,
self.token,
session=self._session,
proxy=http.proxy,
proxy_auth=http.proxy_auth,
payload=params.payload,
multipart=params.multipart,
files=params.files,
)
# The message channel types should always match
state = _InteractionMessageState(self, self._state)

16
discord/message.py

@ -952,7 +952,7 @@ class PartialMessage(Hashable):
if view is not MISSING:
self._state.prevent_view_updates_for(self.id)
params = handle_message_parameters(
with handle_message_parameters(
content=content,
embed=embed,
embeds=embeds,
@ -960,9 +960,9 @@ class PartialMessage(Hashable):
view=view,
allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_allowed_mentions,
)
data = await self._state.http.edit_message(self.channel.id, self.id, params=params)
message = Message(state=self._state, channel=self.channel, data=data)
) as params:
data = await self._state.http.edit_message(self.channel.id, self.id, params=params)
message = Message(state=self._state, channel=self.channel, data=data)
if view and not view.is_finished():
interaction: Optional[MessageInteraction] = getattr(self, 'interaction', None)
@ -2141,7 +2141,7 @@ class Message(PartialMessage, Hashable):
if view is not MISSING:
self._state.prevent_view_updates_for(self.id)
params = handle_message_parameters(
with handle_message_parameters(
content=content,
flags=flags,
embed=embed,
@ -2150,9 +2150,9 @@ class Message(PartialMessage, Hashable):
view=view,
allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_allowed_mentions,
)
data = await self._state.http.edit_message(self.channel.id, self.id, params=params)
message = Message(state=self._state, channel=self.channel, data=data)
) as params:
data = await self._state.http.edit_message(self.channel.id, self.id, params=params)
message = Message(state=self._state, channel=self.channel, data=data)
if view and not view.is_finished():
self._state.store_view(view, self.id)

73
discord/webhook/async_.py

@ -1711,7 +1711,7 @@ class Webhook(BaseWebhook):
if thread_name is not MISSING and thread is not MISSING:
raise TypeError('Cannot mix thread_name and thread keyword arguments.')
params = handle_message_parameters(
with handle_message_parameters(
content=content,
username=username,
avatar_url=avatar_url,
@ -1725,24 +1725,24 @@ class Webhook(BaseWebhook):
thread_name=thread_name,
allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions,
)
adapter = async_context.get()
thread_id: Optional[int] = None
if thread is not MISSING:
thread_id = thread.id
) as params:
adapter = async_context.get()
thread_id: Optional[int] = None
if thread is not MISSING:
thread_id = thread.id
data = await adapter.execute_webhook(
self.id,
self.token,
session=self.session,
proxy=self.proxy,
proxy_auth=self.proxy_auth,
payload=params.payload,
multipart=params.multipart,
files=params.files,
thread_id=thread_id,
wait=wait,
)
data = await adapter.execute_webhook(
self.id,
self.token,
session=self.session,
proxy=self.proxy,
proxy_auth=self.proxy_auth,
payload=params.payload,
multipart=params.multipart,
files=params.files,
thread_id=thread_id,
wait=wait,
)
msg = None
if wait:
@ -1891,7 +1891,7 @@ class Webhook(BaseWebhook):
self._state.prevent_view_updates_for(message_id)
previous_mentions: Optional[AllowedMentions] = getattr(self._state, 'allowed_mentions', None)
params = handle_message_parameters(
with handle_message_parameters(
content=content,
attachments=attachments,
embed=embed,
@ -1899,25 +1899,24 @@ class Webhook(BaseWebhook):
view=view,
allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions,
)
) as params:
thread_id: Optional[int] = None
if thread is not MISSING:
thread_id = thread.id
thread_id: Optional[int] = None
if thread 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,
proxy=self.proxy,
proxy_auth=self.proxy_auth,
payload=params.payload,
multipart=params.multipart,
files=params.files,
thread_id=thread_id,
)
adapter = async_context.get()
data = await adapter.edit_webhook_message(
self.id,
self.token,
message_id,
session=self.session,
proxy=self.proxy,
proxy_auth=self.proxy_auth,
payload=params.payload,
multipart=params.multipart,
files=params.files,
thread_id=thread_id,
)
message = self._create_message(data, thread=thread)
if view and not view.is_finished():

70
discord/webhook/sync.py

@ -1005,7 +1005,7 @@ class SyncWebhook(BaseWebhook):
if thread_name is not MISSING and thread is not MISSING:
raise TypeError('Cannot mix thread_name and thread keyword arguments.')
params = handle_message_parameters(
with handle_message_parameters(
content=content,
username=username,
avatar_url=avatar_url,
@ -1018,22 +1018,23 @@ class SyncWebhook(BaseWebhook):
allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions,
flags=flags,
)
adapter: WebhookAdapter = _get_webhook_adapter()
thread_id: Optional[int] = None
if thread is not MISSING:
thread_id = thread.id
) as params:
adapter: WebhookAdapter = _get_webhook_adapter()
thread_id: Optional[int] = None
if thread is not MISSING:
thread_id = thread.id
data = adapter.execute_webhook(
self.id,
self.token,
session=self.session,
payload=params.payload,
multipart=params.multipart,
files=params.files,
thread_id=thread_id,
wait=wait,
)
data = adapter.execute_webhook(
self.id,
self.token,
session=self.session,
payload=params.payload,
multipart=params.multipart,
files=params.files,
thread_id=thread_id,
wait=wait,
)
if wait:
return self._create_message(data, thread=thread)
@ -1142,31 +1143,30 @@ class SyncWebhook(BaseWebhook):
raise ValueError('This webhook does not have a token associated with it')
previous_mentions: Optional[AllowedMentions] = getattr(self._state, 'allowed_mentions', None)
params = handle_message_parameters(
with handle_message_parameters(
content=content,
attachments=attachments,
embed=embed,
embeds=embeds,
allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions,
)
thread_id: Optional[int] = None
if thread is not MISSING:
thread_id = thread.id
adapter: WebhookAdapter = _get_webhook_adapter()
data = adapter.edit_webhook_message(
self.id,
self.token,
message_id,
session=self.session,
payload=params.payload,
multipart=params.multipart,
files=params.files,
thread_id=thread_id,
)
return self._create_message(data, thread=thread)
) as params:
thread_id: Optional[int] = None
if thread is not MISSING:
thread_id = thread.id
adapter: WebhookAdapter = _get_webhook_adapter()
data = adapter.edit_webhook_message(
self.id,
self.token,
message_id,
session=self.session,
payload=params.payload,
multipart=params.multipart,
files=params.files,
thread_id=thread_id,
)
return self._create_message(data, thread=thread)
def delete_message(self, message_id: int, /, *, thread: Snowflake = MISSING) -> None:
"""Deletes a message owned by this webhook.

Loading…
Cancel
Save