mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
[scripts] add a script for inspecting Discord snowflakes
This commit is contained in:
parent
c53525dc09
commit
b30830ed85
1 changed files with 36 additions and 0 deletions
36
scripts/discord-snowflake
Executable file
36
scripts/discord-snowflake
Executable file
|
@ -0,0 +1,36 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# https://discord.com/developers/docs/reference#snowflakes
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import colorama
|
||||||
|
import time
|
||||||
|
|
||||||
|
DISCORD_EPOCH = 1420070400000 # milliseconds
|
||||||
|
|
||||||
|
user_snowflake = int(sys.argv[1])
|
||||||
|
|
||||||
|
|
||||||
|
def print_field(name, value):
|
||||||
|
print(
|
||||||
|
"{}{}:{} {}".format(
|
||||||
|
colorama.Style.BRIGHT, name.rjust(21), colorama.Style.RESET_ALL, value
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
creation_time = (user_snowflake >> 22) + DISCORD_EPOCH
|
||||||
|
internal_worker_id = (user_snowflake >> 17) & 0x1F
|
||||||
|
internal_process_id = (user_snowflake >> 12) & 0x1F
|
||||||
|
increment = user_snowflake & 0xFFF
|
||||||
|
|
||||||
|
print_field(
|
||||||
|
"Created at",
|
||||||
|
"{}.{}".format(
|
||||||
|
time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(creation_time // 1000)),
|
||||||
|
creation_time % 1000,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
print_field("Internal worker ID", internal_worker_id)
|
||||||
|
print_field("Internal process ID", internal_process_id)
|
||||||
|
print_field("Increment", increment)
|
Loading…
Reference in a new issue