From b30830ed8525bbb602a09ff1d4d2321531da6fce Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Mon, 7 Dec 2020 01:14:02 +0200 Subject: [PATCH] [scripts] add a script for inspecting Discord snowflakes --- scripts/discord-snowflake | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 scripts/discord-snowflake diff --git a/scripts/discord-snowflake b/scripts/discord-snowflake new file mode 100755 index 0000000..25380b9 --- /dev/null +++ b/scripts/discord-snowflake @@ -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)