utility: add snowflake
This commit is contained in:
parent
13480c45e3
commit
ece00a9be4
1 changed files with 27 additions and 0 deletions
|
@ -209,3 +209,30 @@ lookupinvite.callback = async function (msg, line) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
hf.registerCommand(lookupinvite);
|
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);
|
||||||
|
|
Loading…
Reference in a new issue