add read-only cached_messages property to Client
For those of us who want access to this sweet trove of zero hop messages
This commit is contained in:
parent
296d4bf580
commit
b1fae0861a
@ -227,6 +227,14 @@ class Client:
|
|||||||
"""List[:class:`.Emoji`]: The emojis that the connected client has."""
|
"""List[:class:`.Emoji`]: The emojis that the connected client has."""
|
||||||
return self._connection.emojis
|
return self._connection.emojis
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cached_messages(self):
|
||||||
|
"""Sequence[:class:`~discord.Message`]: Read-only list of messages the connected client has cached.
|
||||||
|
|
||||||
|
.. versionadded:: 1.1.0
|
||||||
|
"""
|
||||||
|
return utils.SequenceProxy(self._connection._messages)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def private_channels(self):
|
def private_channels(self):
|
||||||
"""List[:class:`abc.PrivateChannel`]: The private channels that the connected client is participating on.
|
"""List[:class:`abc.PrivateChannel`]: The private channels that the connected client is participating on.
|
||||||
|
@ -26,6 +26,7 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
|
|
||||||
import array
|
import array
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import collections.abc
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from bisect import bisect_left
|
from bisect import bisect_left
|
||||||
@ -78,6 +79,32 @@ def cached_slot_property(name):
|
|||||||
return CachedSlotProperty(name, func)
|
return CachedSlotProperty(name, func)
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
class SequenceProxy(collections.abc.Sequence):
|
||||||
|
"""Read-only proxy of a Sequence."""
|
||||||
|
def __init__(self, proxied):
|
||||||
|
self.__proxied = proxied
|
||||||
|
|
||||||
|
def __getitem__(self, idx):
|
||||||
|
return self.__proxied[idx]
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self.__proxied)
|
||||||
|
|
||||||
|
def __contains__(self, item):
|
||||||
|
return item in self.__proxied
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.__proxied)
|
||||||
|
|
||||||
|
def __reversed__(self):
|
||||||
|
return reversed(self.__proxied)
|
||||||
|
|
||||||
|
def index(self, value, *args, **kwargs):
|
||||||
|
return self.__proxied.index(value, *args, **kwargs)
|
||||||
|
|
||||||
|
def count(self, value):
|
||||||
|
return self.__proxied.count(value)
|
||||||
|
|
||||||
def parse_time(timestamp):
|
def parse_time(timestamp):
|
||||||
if timestamp:
|
if timestamp:
|
||||||
return datetime.datetime(*map(int, re.split(r'[^\d]', timestamp.replace('+00:00', ''))))
|
return datetime.datetime(*map(int, re.split(r'[^\d]', timestamp.replace('+00:00', ''))))
|
||||||
|
@ -206,8 +206,6 @@ A list of these changes is enumerated below.
|
|||||||
+---------------------------------------+------------------------------------------------------------------------------+
|
+---------------------------------------+------------------------------------------------------------------------------+
|
||||||
| ``Client.wait_until_login`` | Removed |
|
| ``Client.wait_until_login`` | Removed |
|
||||||
+---------------------------------------+------------------------------------------------------------------------------+
|
+---------------------------------------+------------------------------------------------------------------------------+
|
||||||
| ``Client.messages`` | Removed |
|
|
||||||
+---------------------------------------+------------------------------------------------------------------------------+
|
|
||||||
| ``Client.wait_until_ready`` | No change |
|
| ``Client.wait_until_ready`` | No change |
|
||||||
+---------------------------------------+------------------------------------------------------------------------------+
|
+---------------------------------------+------------------------------------------------------------------------------+
|
||||||
|
|
||||||
@ -330,6 +328,10 @@ They will be enumerated here.
|
|||||||
|
|
||||||
- Use :attr:`Client.emojis` instead.
|
- Use :attr:`Client.emojis` instead.
|
||||||
|
|
||||||
|
` ``Client.messages``
|
||||||
|
|
||||||
|
- Use read-only :attr:`Client.cached_messages` instead.
|
||||||
|
|
||||||
- ``Client.wait_for_message`` and ``Client.wait_for_reaction`` are gone.
|
- ``Client.wait_for_message`` and ``Client.wait_for_reaction`` are gone.
|
||||||
|
|
||||||
- Use :meth:`Client.wait_for` instead.
|
- Use :meth:`Client.wait_for` instead.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user