Added error reporting functionality, fixed bugs in the various game's code and tidied up a bit

This commit is contained in:
ION606
2022-07-19 15:41:49 +03:00
parent 4e1214a312
commit 0b13f6db29
13 changed files with 259 additions and 79 deletions
+24 -20
View File
@@ -12,27 +12,31 @@ function convertSnowflakeToDate(snowflake, epoch = DISCORD_EPOCH) {
// Validates a snowflake ID string and returns a JS Date object if valid
function validateSnowflake(snowflake, epoch) {
if (!Number.isInteger(+snowflake)) {
throw new Error(
"That doesn't look like a snowflake. Snowflakes contain only numbers."
)
try {
if (!Number.isInteger(+snowflake)) {
throw new Error(
"That doesn't look like a snowflake. Snowflakes contain only numbers."
)
}
if (snowflake < 4194304) {
throw new Error(
"That doesn't look like a snowflake. Snowflakes are much larger numbers."
)
}
const timestamp = convertSnowflakeToDate(snowflake, epoch)
if (Number.isNaN(timestamp.getTime())) {
throw new Error(
"That doesn't look like a snowflake. Snowflakes have fewer digits."
)
}
return timestamp
} catch(err) {
console.log(err);
}
if (snowflake < 4194304) {
throw new Error(
"That doesn't look like a snowflake. Snowflakes are much larger numbers."
)
}
const timestamp = convertSnowflakeToDate(snowflake, epoch)
if (Number.isNaN(timestamp.getTime())) {
throw new Error(
"That doesn't look like a snowflake. Snowflakes have fewer digits."
)
}
return timestamp
}
module.exports = { convertSnowflakeToDate, validateSnowflake }