Browse Source

Add discord.utils.sleep_until helper function

pull/2519/head
Josh B 5 years ago
committed by Rapptz
parent
commit
40369a493d
  1. 18
      discord/utils.py

18
discord/utils.py

@ -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…
Cancel
Save