18 Commits

Author SHA1 Message Date
46d6215646 Update api.rst 2021-10-27 09:58:12 -04:00
c743034e99 should fix it like gnome wants. 2021-10-27 09:17:20 -04:00
da5ee84abe ok 2021-10-27 09:15:38 -04:00
061b2e3d90 ok 2021-10-27 09:15:04 -04:00
0e5cf0f840 okay 2021-10-27 09:13:39 -04:00
7331957ee4 okay one more change 2021-10-27 09:12:26 -04:00
e9850566e8 should fix that a tiny bit. 2021-10-27 09:10:51 -04:00
2bd28a7990 should work with utils. 2021-10-04 22:07:49 -04:00
343d533640 removed quick_snowflake to merge it into what is wanted. 2021-10-04 22:03:55 -04:00
d2837a34f3 Adds the Dt function thing
Again on mobile
2021-10-04 14:04:41 -04:00
6a9083a504 Makes this optional
I am doing this via mobile I will check on my computer later
2021-10-04 13:53:24 -04:00
655692d2cc cool 2021-10-04 09:45:33 -04:00
c360611927 let's see if this generates. 2021-10-04 09:43:20 -04:00
8bb8283ea8 okay 2021-10-03 22:57:10 -04:00
675e3250e2 hmmm 2021-10-03 22:55:43 -04:00
dea01b189b test 2021-10-03 22:49:08 -04:00
5963ec05ca Update utils.py 2021-10-03 22:45:08 -04:00
5133a58d6d updated stuff 2021-10-03 22:00:17 -04:00
2 changed files with 23 additions and 0 deletions

View File

@ -84,6 +84,7 @@ __all__ = (
"escape_mentions",
"as_chunks",
"format_dt",
"generate_snowflake",
)
DISCORD_EPOCH = 1420070400000
@ -1020,3 +1021,23 @@ def format_dt(dt: datetime.datetime, /, style: Optional[TimestampStyle] = None)
if style is None:
return f"<t:{int(dt.timestamp())}>"
return f"<t:{int(dt.timestamp())}:{style}>"
def generate_snowflake(dt: Optional[datetime.datetime] = None) -> int:
"""Returns a numeric snowflake pretending to be created at the given date but more accurate and random than time_snowflake.
If No dt is not passed, it makes one from the current time using utcnow.
Parameters
-----------
dt: :class:`datetime.datetime`
A datetime object to convert to a snowflake.
If naive, the timezone is assumed to be local time.
Returns
--------
:class:`int`
The snowflake representing the time given.
"""
dt = dt or utcnow()
return int(dt.timestamp() * 1000 - DISCORD_EPOCH) << 22 | 0x3fffff

View File

@ -1136,6 +1136,8 @@ Utility Functions
.. autofunction:: discord.utils.as_chunks
.. autofunction:: discord.utils.generate_snowflake
.. _discord-api-enums:
Enumerations