Add discord.utils.sleep_until helper function
This commit is contained in:
parent
d7e925eb89
commit
40369a493d
@ -338,6 +338,24 @@ async def sane_wait_for(futures, *, timeout):
|
||||
|
||||
return done
|
||||
|
||||
async def sleep_until(when):
|
||||
"""Sleep until a specified time.
|
||||
|
||||
If the time supplied is in the past this function will yield instantly.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
when: :class:`datetime.datetime`
|
||||
The timestamp in which to sleep until.
|
||||
|
||||
.. versionadded:: 1.3.0
|
||||
"""
|
||||
if when.tzinfo is None:
|
||||
when = when.replace(tzinfo=datetime.timezone.utc)
|
||||
now = datetime.datetime.now(datetime.timezone.utc)
|
||||
delta = (when - now).total_seconds()
|
||||
await asyncio.sleep(max(delta, 0))
|
||||
|
||||
def valid_icon_size(size):
|
||||
"""Icons must be power of 2 within [16, 4096]."""
|
||||
return not size & (size - 1) and size in range(16, 4097)
|
||||
|
Loading…
x
Reference in New Issue
Block a user