Add listener for on_ready event for easier background tasks.
This commit is contained in:
parent
a1693a8c9d
commit
4fa5b50d2b
@ -125,6 +125,7 @@ class Client:
|
|||||||
|
|
||||||
self._closed = asyncio.Event(loop=self.loop)
|
self._closed = asyncio.Event(loop=self.loop)
|
||||||
self._is_logged_in = asyncio.Event(loop=self.loop)
|
self._is_logged_in = asyncio.Event(loop=self.loop)
|
||||||
|
self._is_ready = asyncio.Event(loop=self.loop)
|
||||||
|
|
||||||
# These two events correspond to the two events necessary
|
# These two events correspond to the two events necessary
|
||||||
# for a connection to be made
|
# for a connection to be made
|
||||||
@ -201,6 +202,9 @@ class Client:
|
|||||||
for idx in reversed(removed):
|
for idx in reversed(removed):
|
||||||
del self._listeners[idx]
|
del self._listeners[idx]
|
||||||
|
|
||||||
|
def handle_ready(self):
|
||||||
|
self._is_ready.set()
|
||||||
|
|
||||||
def _resolve_mentions(self, content, mentions):
|
def _resolve_mentions(self, content, mentions):
|
||||||
if isinstance(mentions, list):
|
if isinstance(mentions, list):
|
||||||
return [user.id for user in mentions]
|
return [user.id for user in mentions]
|
||||||
@ -471,6 +475,28 @@ class Client:
|
|||||||
for member in server.members:
|
for member in server.members:
|
||||||
yield member
|
yield member
|
||||||
|
|
||||||
|
# listeners/waiters
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def wait_for_ready(self):
|
||||||
|
"""|coro|
|
||||||
|
|
||||||
|
This coroutine waits until the client is all ready. This could be considered
|
||||||
|
another way of asking for :func:`discord.on_ready` except meant for your own
|
||||||
|
background tasks.
|
||||||
|
"""
|
||||||
|
yield from self._is_ready.wait()
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def wait_for_login(self):
|
||||||
|
"""|coro|
|
||||||
|
|
||||||
|
This coroutine waits until the client is logged on successfully. This
|
||||||
|
is different from waiting until the client's state is all ready. For
|
||||||
|
that check :func:`discord.on_ready` and :meth:`wait_for_ready`.
|
||||||
|
"""
|
||||||
|
yield from self._is_logged_in.wait()
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def wait_for_message(self, timeout=None, *, author=None, channel=None, content=None, check=None):
|
def wait_for_message(self, timeout=None, *, author=None, channel=None, content=None, check=None):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
@ -706,6 +732,7 @@ class Client:
|
|||||||
|
|
||||||
self.keep_alive.cancel()
|
self.keep_alive.cancel()
|
||||||
self._closed.set()
|
self._closed.set()
|
||||||
|
self._is_ready.clear()
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def start(self, email, password):
|
def start(self, email, password):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user