utility: add snowflake

This commit is contained in:
Cynthia Foxwell 2021-06-10 21:54:17 -06:00
parent 13480c45e3
commit ece00a9be4

View file

@ -209,3 +209,30 @@ lookupinvite.callback = async function (msg, line) {
}
};
hf.registerCommand(lookupinvite);
const snowflake = new Command("snowflake");
snowflake.category = CATEGORY;
snowflake.helpText = "Converts a snowflake ID into readable time.";
snowflake.usage = "<--twitter> [snowflake]";
snowflake.callback = function (msg, line) {
let twitter = false;
if (line.startsWith("--twitter")) {
twitter = true;
line.replace("--twitter ", "");
}
const num = parseInt(line);
if (!isNaN(num)) {
let binary = num.toString(2);
binary = "0".repeat(64 - binary.length) + binary;
const timestamp =
parseInt(binary.substr(0, 42), 2) +
(twitter ? 1288834974657 : 1420070400000);
return `The timestamp for \`${line}\` is ${
new Date(timestamp).toUTCString
}`;
} else {
return "Argument provided is not a number.";
}
};
hf.registerCommand(snowflake);