From 59c18d385ea34ee4f937820457901916362fece3 Mon Sep 17 00:00:00 2001 From: Essem Date: Mon, 23 Feb 2026 16:40:43 -0600 Subject: [PATCH] fix: Use BigInt for higher precision on snowflake --- commands/general/snowflake.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/commands/general/snowflake.js b/commands/general/snowflake.js index 552c25c1..d7215629 100644 --- a/commands/general/snowflake.js +++ b/commands/general/snowflake.js @@ -1,4 +1,5 @@ import Command from "#cmd-classes/command.js"; +import { safeBigInt } from "#utils/misc.js"; class SnowflakeCommand extends Command { async run() { @@ -6,21 +7,17 @@ class SnowflakeCommand extends Command { if (!this.args[0]) return this.getString("commands.responses.snowflake.noInput"); if (!this.args[0].match(/^?$/) || Number.parseInt(this.args[0]) < 21154535154122752n) return this.getString("commands.responses.snowflake.invalid"); - const id = Math.floor( - (Number( - this.args[0] - .replaceAll("@", "") - .replaceAll("#", "") - .replaceAll("!", "") - .replaceAll("&", "") - .replaceAll("<", "") - .replaceAll(">", ""), - ) / - 4194304 + - 1420070400000) / - 1000, + const baseId = safeBigInt( + this.args[0] + .replaceAll("@", "") + .replaceAll("#", "") + .replaceAll("!", "") + .replaceAll("&", "") + .replaceAll("<", "") + .replaceAll(">", ""), ); - if (Number.isNaN(id)) return this.getString("commands.responses.snowflake.invalid"); + if (baseId === -1) throw this.getString("commands.responses.snowflake.invalid"); + const id = (baseId / 4194304n + 1420070400000n) / 1000n; this.success = true; return ``; } -- 2.51.2