aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-05-31 23:15:12 -0400
committerRapptz <[email protected]>2021-05-31 23:15:12 -0400
commit78275023ccdbb460d0cd207834882ff29ae4e10c (patch)
tree945cd5b397306b8e2a021d3858096364af0df6d7
parentEnsure views added to Client.add_view are persistent views (diff)
downloaddiscord.py-78275023ccdbb460d0cd207834882ff29ae4e10c.tar.xz
discord.py-78275023ccdbb460d0cd207834882ff29ae4e10c.zip
Add Client.persistent_views to get all persistent views
-rw-r--r--discord/client.py7
-rw-r--r--discord/state.py4
-rw-r--r--discord/ui/view.py11
3 files changed, 20 insertions, 2 deletions
diff --git a/discord/client.py b/discord/client.py
index cc793c0b..27ec55c1 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -29,7 +29,7 @@ import logging
import signal
import sys
import traceback
-from typing import Any, Generator, List, Optional, TYPE_CHECKING, TypeVar, Union
+from typing import Any, Generator, List, Optional, Sequence, TYPE_CHECKING, TypeVar, Union
import aiohttp
@@ -1463,3 +1463,8 @@ class Client:
raise ValueError('View is not persistent. Items need to have a custom_id set and View must have no timeout')
self._connection.store_view(view, message_id)
+
+ @property
+ def persistent_views(self) -> Sequence[View]:
+ """Sequence[:class:`View`]: A sequence of persistent views added to the client."""
+ return self._connection.persistent_views
diff --git a/discord/state.py b/discord/state.py
index 80272cd6..71892fd8 100644
--- a/discord/state.py
+++ b/discord/state.py
@@ -288,6 +288,10 @@ class ConnectionState:
return self._view_store.remove_message_tracking(message_id)
@property
+ def persistent_views(self):
+ return self._view_store.persistent_views
+
+ @property
def guilds(self):
return list(self._guilds.values())
diff --git a/discord/ui/view.py b/discord/ui/view.py
index b6ddf4e6..f6dac241 100644
--- a/discord/ui/view.py
+++ b/discord/ui/view.py
@@ -23,7 +23,7 @@ DEALINGS IN THE SOFTWARE.
"""
from __future__ import annotations
-from typing import Any, Callable, ClassVar, Dict, Iterator, List, Optional, TYPE_CHECKING, Tuple
+from typing import Any, Callable, ClassVar, Dict, Iterator, List, Optional, Sequence, TYPE_CHECKING, Tuple
from functools import partial
from itertools import groupby
@@ -370,6 +370,15 @@ class ViewStore:
self._synced_message_views: Dict[int, View] = {}
self._state: ConnectionState = state
+ @property
+ def persistent_views(self) -> Sequence[View]:
+ views = {
+ view.id: view
+ for (_, (view, _, _)) in self._views.items()
+ if view.is_persistent()
+ }
+ return list(views.values())
+
def __verify_integrity(self):
to_remove: List[Tuple[int, str]] = []
now = time.monotonic()