Skip to content

Commit

Permalink
Don't store finished views/modals
Browse files Browse the repository at this point in the history
  • Loading branch information
z03h committed Feb 14, 2023
1 parent caf0fbd commit e6ef431
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion discord/abc.py
Expand Up @@ -1552,7 +1552,7 @@ async def send(
data = await state.http.send_message(channel.id, params=params)

ret = state.create_message(channel=channel, data=data)
if view:
if view and not view.is_finished():
state.store_view(view, ret.id)

if delete_after is not None:
Expand Down
2 changes: 1 addition & 1 deletion discord/channel.py
Expand Up @@ -2653,7 +2653,7 @@ async def create_thread(
data = await state.http.start_thread_in_forum(self.id, params=params, reason=reason)
thread = Thread(guild=self.guild, state=self._state, data=data)
message = Message(state=self._state, channel=thread, data=data['message'])
if view:
if view and not view.is_finished():
self._state.store_view(view, message.id)

return ThreadWithMessage(thread=thread, message=message)
Expand Down
5 changes: 4 additions & 1 deletion discord/client.py
Expand Up @@ -2694,7 +2694,7 @@ def add_view(self, view: View, *, message_id: Optional[int] = None) -> None:
TypeError
A view was not passed.
ValueError
The view is not persistent. A persistent view has no timeout
The view is not persistent or is already finished. A persistent view has no timeout
and all their components have an explicitly provided custom_id.
"""

Expand All @@ -2704,6 +2704,9 @@ def add_view(self, view: View, *, message_id: Optional[int] = None) -> None:
if not view.is_persistent():
raise ValueError('View is not persistent. Items need to have a custom_id set and View must have no timeout')

if view.is_finished():
raise ValueError('View is already finished.')

self._connection.store_view(view, message_id)

@property
Expand Down
6 changes: 3 additions & 3 deletions discord/interactions.py
Expand Up @@ -784,7 +784,7 @@ async def send_message(
params=params,
)

if view is not MISSING:
if view is not MISSING and not view.is_finished():
if ephemeral and view.timeout is None:
view.timeout = 15 * 60.0

Expand Down Expand Up @@ -954,8 +954,8 @@ async def send_modal(self, modal: Modal, /) -> None:
proxy_auth=http.proxy_auth,
params=params,
)

self._parent._state.store_view(modal)
if not modal.is_finished():
self._parent._state.store_view(modal)
self._response_type = InteractionResponseType.modal

async def autocomplete(self, choices: Sequence[Choice[ChoiceT]]) -> None:
Expand Down

0 comments on commit e6ef431

Please sign in to comment.