chore(bot,utils): Move snowflake utils to @discordeno/utils (#4345)

This commit is contained in:
Fleny
2025-08-14 12:08:19 -07:00
committed by GitHub
parent 247fd4b348
commit 6679f2c0e4
5 changed files with 7 additions and 10 deletions
-1
View File
@@ -12,4 +12,3 @@ export * from './handlers.js'
export * from './helpers.js'
export * from './transformers/index.js'
export * from './transformers.js'
export * from './utils.js'
+1 -1
View File
@@ -79,6 +79,7 @@ import type {
DiscordWelcomeScreen,
RecursivePartial,
} from '@discordeno/types'
import { bigintToSnowflake, snowflakeToBigint } from '@discordeno/utils'
import type { Bot } from './bot.js'
import {
createDesiredPropertiesObject,
@@ -250,7 +251,6 @@ import {
transformMediaGalleryItemToDiscordMediaGalleryItem,
transformUnfurledMediaItemToDiscordUnfurledMediaItem,
} from './transformers/reverse/index.js'
import { bigintToSnowflake, snowflakeToBigint } from './utils.js'
export type Transformers<TProps extends TransformersDesiredProperties, TBehavior extends DesiredPropertiesBehavior> = {
customizers: {
+3 -6
View File
@@ -68,6 +68,7 @@ import {
hasProperty,
logger,
processReactionString,
snowflakeToTimestamp,
urlToBase64,
} from '@discordeno/utils'
import { createInvalidRequestBucket } from './invalidBucket.js'
@@ -558,12 +559,8 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
// The 2 exceptions are for message delete, so we need to check if we are in that route
if (method === 'DELETE' && splittedRoute.length === 5 && splittedRoute[1] === 'channels' && strippedRoute.endsWith('/messages/x')) {
const messageId = BigInt(splittedRoute[4])
// TODO: We should move the utility from @discordeno/bot to @discordeno/utils and use that here
// See https://discord.com/developers/docs/reference#snowflakes-snowflake-id-format-structure-left-to-right
const timestamp = Number(messageId >> 22n) + 1420070400000
const messageId = splittedRoute[4]
const timestamp = snowflakeToTimestamp(messageId)
const now = Date.now()
// https://github.com/discord/discord-api-docs/issues/1092
+1
View File
@@ -11,6 +11,7 @@ export * from './logger.js'
export * from './oauth2.js'
export * from './permissions.js'
export * from './reactions.js'
export * from './snowflakes.js'
export * from './token.js'
export * from './typeguards.js'
export * from './urls.js'
@@ -5,9 +5,9 @@ export function snowflakeToBigint(snowflake: BigString): bigint {
}
export function bigintToSnowflake(snowflake: BigString): string {
return snowflake ? snowflake.toString() : ''
return snowflake.toString()
}
export function snowflakeToTimestamp(snowflake: BigString): number {
return Number(BigInt(snowflake) / 4194304n + 1420070400000n)
return Number(BigInt(snowflake) >> 22n) + 1420070400000
}