mirror of
https://github.com/ION606/selmerBot.git
synced 2026-05-15 05:36:54 +00:00
Added error reporting functionality, fixed bugs in the various game's code and tidied up a bit
This commit is contained in:
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user