[scripts] add a script for inspecting Discord snowflakes

This commit is contained in:
Dmytro Meleshko 2020-12-07 01:14:02 +02:00
parent c53525dc09
commit b30830ed85

36
scripts/discord-snowflake Executable file
View 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)