dotfiles/scripts/discord-snowflake

36 lines
845 B
Text
Raw Normal View History

#!/usr/bin/env python3
# https://discord.com/developers/docs/reference#snowflakes
import sys
import colorama
import time
2021-04-26 07:20:57 +00:00
DISCORD_EPOCH = 1420070400000 # milliseconds
user_snowflake = int(sys.argv[1])
def print_field(name, value):
2021-04-26 07:20:57 +00:00
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(
2021-04-26 07:20:57 +00:00
"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)