Skip to content

Commit

Permalink
fix(snowflake): snowflakes length (#9144)
Browse files Browse the repository at this point in the history
* fix(snowflake): fix snowflakes length

* fix(snowflake): fix length
  • Loading branch information
DraftProducts authored Mar 12, 2023
1 parent 4458a13 commit 955e8fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/discord.js/src/managers/ThreadManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class ThreadManager extends CachedManager {
let id;
const query = makeURLSearchParams({ limit });
if (typeof before !== 'undefined') {
if (before instanceof ThreadChannel || /^\d{16,19}$/.test(String(before))) {
if (before instanceof ThreadChannel || /^\d{17,19}$/.test(String(before))) {
id = this.resolveId(before);
timestamp = this.resolve(before)?.archivedAt?.toISOString();
const toUse = type === 'private' && !fetchAll ? id : timestamp;
Expand Down
6 changes: 3 additions & 3 deletions packages/rest/src/lib/RequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,14 @@ export class RequestManager extends EventEmitter {
* @internal
*/
private static generateRouteData(endpoint: RouteLike, method: RequestMethod): RouteData {
const majorIdMatch = /^\/(?:channels|guilds|webhooks)\/(\d{16,19})/.exec(endpoint);
const majorIdMatch = /^\/(?:channels|guilds|webhooks)\/(\d{17,19})/.exec(endpoint);

// Get the major id for this route - global otherwise
const majorId = majorIdMatch?.[1] ?? 'global';

const baseRoute = endpoint
// Strip out all ids
.replaceAll(/\d{16,19}/g, ':id')
.replaceAll(/\d{17,19}/g, ':id')
// Strip out reaction as they fall under the same bucket
.replace(/\/reactions\/(.*)/, '/reactions/:reaction');

Expand All @@ -515,7 +515,7 @@ export class RequestManager extends EventEmitter {
// Hard-Code Old Message Deletion Exception (2 week+ old messages are a different bucket)
// https://github.com/discord/discord-api-docs/issues/1295
if (method === RequestMethod.Delete && baseRoute === '/channels/:id/messages/:id') {
const id = /\d{16,19}$/.exec(endpoint)![0]!;
const id = /\d{17,19}$/.exec(endpoint)![0]!;
const timestamp = DiscordSnowflake.timestampFrom(id);
if (Date.now() - timestamp > 1_000 * 60 * 60 * 24 * 14) {
exceptions += '/Delete Old Message';
Expand Down

2 comments on commit 955e8fe

@vercel
Copy link

@vercel vercel bot commented on 955e8fe Mar 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 955e8fe Mar 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.