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

16
discord/message.py

@ -952,7 +952,7 @@ class PartialMessage(Hashable):
if view is not MISSING: if view is not MISSING:
self._state.prevent_view_updates_for(self.id) self._state.prevent_view_updates_for(self.id)
params = handle_message_parameters( with handle_message_parameters(
content=content, content=content,
embed=embed, embed=embed,
embeds=embeds, embeds=embeds,
@ -960,9 +960,9 @@ class PartialMessage(Hashable):
view=view, view=view,
allowed_mentions=allowed_mentions, allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_allowed_mentions, previous_allowed_mentions=previous_allowed_mentions,
) ) as params:
data = await self._state.http.edit_message(self.channel.id, self.id, params=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) message = Message(state=self._state, channel=self.channel, data=data)
if view and not view.is_finished(): if view and not view.is_finished():
interaction: Optional[MessageInteraction] = getattr(self, 'interaction', None) interaction: Optional[MessageInteraction] = getattr(self, 'interaction', None)
@ -2141,7 +2141,7 @@ class Message(PartialMessage, Hashable):
if view is not MISSING: if view is not MISSING:
self._state.prevent_view_updates_for(self.id) self._state.prevent_view_updates_for(self.id)
params = handle_message_parameters( with handle_message_parameters(
content=content, content=content,
flags=flags, flags=flags,
embed=embed, embed=embed,
@ -2150,9 +2150,9 @@ class Message(PartialMessage, Hashable):
view=view, view=view,
allowed_mentions=allowed_mentions, allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_allowed_mentions, previous_allowed_mentions=previous_allowed_mentions,
) ) as params:
data = await self._state.http.edit_message(self.channel.id, self.id, params=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) message = Message(state=self._state, channel=self.channel, data=data)
if view and not view.is_finished(): if view and not view.is_finished():
self._state.store_view(view, self.id) 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: if thread_name is not MISSING and thread is not MISSING:
raise TypeError('Cannot mix thread_name and thread keyword arguments.') raise TypeError('Cannot mix thread_name and thread keyword arguments.')
params = handle_message_parameters( with handle_message_parameters(
content=content, content=content,
username=username, username=username,
avatar_url=avatar_url, avatar_url=avatar_url,
@ -1725,24 +1725,24 @@ class Webhook(BaseWebhook):
thread_name=thread_name, thread_name=thread_name,
allowed_mentions=allowed_mentions, allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions, previous_allowed_mentions=previous_mentions,
) ) as params:
adapter = async_context.get() adapter = async_context.get()
thread_id: Optional[int] = None thread_id: Optional[int] = None
if thread is not MISSING: if thread is not MISSING:
thread_id = thread.id thread_id = thread.id
data = await adapter.execute_webhook( data = await adapter.execute_webhook(
self.id, self.id,
self.token, self.token,
session=self.session, session=self.session,
proxy=self.proxy, proxy=self.proxy,
proxy_auth=self.proxy_auth, proxy_auth=self.proxy_auth,
payload=params.payload, payload=params.payload,
multipart=params.multipart, multipart=params.multipart,
files=params.files, files=params.files,
thread_id=thread_id, thread_id=thread_id,
wait=wait, wait=wait,
) )
msg = None msg = None
if wait: if wait:
@ -1891,7 +1891,7 @@ class Webhook(BaseWebhook):
self._state.prevent_view_updates_for(message_id) self._state.prevent_view_updates_for(message_id)
previous_mentions: Optional[AllowedMentions] = getattr(self._state, 'allowed_mentions', None) previous_mentions: Optional[AllowedMentions] = getattr(self._state, 'allowed_mentions', None)
params = handle_message_parameters( with handle_message_parameters(
content=content, content=content,
attachments=attachments, attachments=attachments,
embed=embed, embed=embed,
@ -1899,25 +1899,24 @@ class Webhook(BaseWebhook):
view=view, view=view,
allowed_mentions=allowed_mentions, allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_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 adapter = async_context.get()
if thread is not MISSING: data = await adapter.edit_webhook_message(
thread_id = thread.id self.id,
self.token,
adapter = async_context.get() message_id,
data = await adapter.edit_webhook_message( session=self.session,
self.id, proxy=self.proxy,
self.token, proxy_auth=self.proxy_auth,
message_id, payload=params.payload,
session=self.session, multipart=params.multipart,
proxy=self.proxy, files=params.files,
proxy_auth=self.proxy_auth, thread_id=thread_id,
payload=params.payload, )
multipart=params.multipart,
files=params.files,
thread_id=thread_id,
)
message = self._create_message(data, thread=thread) message = self._create_message(data, thread=thread)
if view and not view.is_finished(): 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: if thread_name is not MISSING and thread is not MISSING:
raise TypeError('Cannot mix thread_name and thread keyword arguments.') raise TypeError('Cannot mix thread_name and thread keyword arguments.')
params = handle_message_parameters( with handle_message_parameters(
content=content, content=content,
username=username, username=username,
avatar_url=avatar_url, avatar_url=avatar_url,
@ -1018,22 +1018,23 @@ class SyncWebhook(BaseWebhook):
allowed_mentions=allowed_mentions, allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions, previous_allowed_mentions=previous_mentions,
flags=flags, flags=flags,
) ) as params:
adapter: WebhookAdapter = _get_webhook_adapter() adapter: WebhookAdapter = _get_webhook_adapter()
thread_id: Optional[int] = None thread_id: Optional[int] = None
if thread is not MISSING: if thread is not MISSING:
thread_id = thread.id 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: if wait:
return self._create_message(data, thread=thread) 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') raise ValueError('This webhook does not have a token associated with it')
previous_mentions: Optional[AllowedMentions] = getattr(self._state, 'allowed_mentions', None) previous_mentions: Optional[AllowedMentions] = getattr(self._state, 'allowed_mentions', None)
params = handle_message_parameters( with handle_message_parameters(
content=content, content=content,
attachments=attachments, attachments=attachments,
embed=embed, embed=embed,
embeds=embeds, embeds=embeds,
allowed_mentions=allowed_mentions, allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions, previous_allowed_mentions=previous_mentions,
) ) as params:
thread_id: Optional[int] = None
thread_id: Optional[int] = None if thread is not MISSING:
if thread is not MISSING: thread_id = thread.id
thread_id = thread.id
adapter: WebhookAdapter = _get_webhook_adapter()
adapter: WebhookAdapter = _get_webhook_adapter() data = adapter.edit_webhook_message(
data = adapter.edit_webhook_message( self.id,
self.id, self.token,
self.token, message_id,
message_id, session=self.session,
session=self.session, payload=params.payload,
payload=params.payload, multipart=params.multipart,
multipart=params.multipart, files=params.files,
files=params.files, thread_id=thread_id,
thread_id=thread_id, )
) return self._create_message(data, thread=thread)
return self._create_message(data, thread=thread)
def delete_message(self, message_id: int, /, *, thread: Snowflake = MISSING) -> None: def delete_message(self, message_id: int, /, *, thread: Snowflake = MISSING) -> None:
"""Deletes a message owned by this webhook. """Deletes a message owned by this webhook.

Loading…
Cancel
Save