Skip to content

Commit

Permalink
Merge branch 'main' into refactor-emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite authored Jan 13, 2025
2 parents 4f24695 + 28afb0c commit 2837156
Show file tree
Hide file tree
Showing 34 changed files with 605 additions and 420 deletions.
7 changes: 5 additions & 2 deletions apps/website/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ async function fetchLatestVersion(packageName: string): Promise<string> {
}

try {
const { rows } = await sql`select version from documentation where name = ${packageName} order by version desc`;
const { rows } = await sql<{ version: string }>`with ordered_versions as (
select version from documentation where name = ${packageName} and version != 'main' order by string_to_array(version, '.')::int[] desc
)
select version from ordered_versions limit 1`;

return rows.map((row) => row.version).at(1) ?? 'main';
return rows[0]?.version ?? 'main';
} catch {
return '';
}
Expand Down
16 changes: 0 additions & 16 deletions apps/website/src/util/fetchLatestVersion.ts

This file was deleted.

11 changes: 10 additions & 1 deletion apps/website/src/util/fetchVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ export async function fetchVersions(packageName: string) {
try {
const { rows } = await sql<{
version: string;
}>`select version from documentation where name = ${packageName} order by version desc`;
}>`select version from documentation where name = ${packageName} order by
case
when version = 'main' then 0
else 1
end,
case
when version = 'main' then null
else string_to_array(version, '.')::int[]
end desc;
`;

return rows;
} catch {
Expand Down
1 change: 1 addition & 0 deletions packages/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@vercel/postgres": "^0.9.0",
"meilisearch": "^0.38.0",
"p-limit": "^6.2.0",
"p-queue": "^8.0.1",
"tslib": "^2.8.1",
"undici": "6.21.0"
},
Expand Down
41 changes: 33 additions & 8 deletions packages/actions/src/uploadSplitDocumentation/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { readFile } from 'node:fs/promises';
import { basename, dirname, relative, sep } from 'node:path';
import { cwd } from 'node:process';
import { getInput } from '@actions/core';
import { setTimeout as sleep } from 'node:timers/promises';
import { setFailed, getInput } from '@actions/core';
import { create } from '@actions/glob';
import { put } from '@vercel/blob';
import pLimit from 'p-limit';
import PQueue from 'p-queue';

const pkg = getInput('package') || '*';
const version = getInput('version') || 'main';

const limit = pLimit(10);
const queue = new PQueue({ concurrency: 10, interval: 60_000, intervalCap: 1_000 });
const promises = [];
const failedUploads: string[] = [];

const globber = await create(`packages/${pkg}/docs/${pkg}/split/*.api.json`);
console.log('Glob: ', await globber.glob());
Expand All @@ -20,13 +22,33 @@ for await (const file of globber.globGenerator()) {
try {
promises.push(
// eslint-disable-next-line @typescript-eslint/no-loop-func
limit(async () => {
queue.add(async () => {
console.log(`Uploading ${file} with ${version} from ${pkgName}...`);
const name = basename(file).replace('main.', '');
await put(`rewrite/${pkgName}/${version}.${name}`, data, {
access: 'public',
addRandomSuffix: false,
});
async function upload(retries = 0) {
try {
await put(`rewrite/${pkgName}/${version}.${name}`, data, {
access: 'public',
addRandomSuffix: false,
});
} catch (error) {
if (retries > 3) {
console.error(`Could not upload ${file} after 3 retries`, error);
failedUploads.push(name);
return;
}

if (typeof error === 'object' && error && 'retryAfter' in error && typeof error.retryAfter === 'number') {
await sleep(error.retryAfter * 1_000);
return upload(retries + 1);
} else {
console.error(`Could not upload ${file}`, error);
failedUploads.push(name);
}
}
}

await upload();
}),
);
} catch (error) {
Expand All @@ -36,6 +58,9 @@ for await (const file of globber.globGenerator()) {

try {
await Promise.all(promises);
if (failedUploads.length) {
setFailed(`Failed to upload ${failedUploads.length} files: ${failedUploads.join(', ')}`);
}
} catch (error) {
console.log(error);
}
2 changes: 1 addition & 1 deletion packages/discord.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"funding": "https://github.com/discordjs/discord.js?sponsor",
"dependencies": {
"@discordjs/builders": "^1.9.0",
"@discordjs/collection": "1.5.3",
"@discordjs/collection": "workspace:^",
"@discordjs/formatters": "workspace:^",
"@discordjs/rest": "workspace:^",
"@discordjs/util": "workspace:^",
Expand Down
5 changes: 4 additions & 1 deletion packages/discord.js/src/client/actions/PresenceUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

const Action = require('./Action');
const Events = require('../../util/Events');
const Partials = require('../util/Partials');

class PresenceUpdateAction extends Action {
handle(data) {
let user = this.client.users.cache.get(data.user.id);
if (!user && data.user.username) user = this.client.users._add(data.user);
if (!user && ('username' in data.user || this.client.options.partials.includes(Partials.User))) {
user = this.client.users._add(data.user);
}
if (!user) return;

if (data.user.username) {
Expand Down
2 changes: 0 additions & 2 deletions packages/discord.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ exports.ChannelFlagsBitField = require('./util/ChannelFlagsBitField');
exports.Collection = require('@discordjs/collection').Collection;
exports.Constants = require('./util/Constants');
exports.Colors = require('./util/Colors');
__exportStar(require('./util/DataResolver.js'), exports);
exports.Events = require('./util/Events');
exports.GuildMemberFlagsBitField = require('./util/GuildMemberFlagsBitField').GuildMemberFlagsBitField;
exports.IntentsBitField = require('./util/IntentsBitField');
Expand Down Expand Up @@ -148,7 +147,6 @@ exports.InteractionCallbackResource = require('./structures/InteractionCallbackR
exports.InteractionCallbackResponse = require('./structures/InteractionCallbackResponse');
exports.BaseInteraction = require('./structures/BaseInteraction');
exports.InteractionCollector = require('./structures/InteractionCollector');
exports.InteractionResponse = require('./structures/InteractionResponse');
exports.InteractionWebhook = require('./structures/InteractionWebhook');
exports.Invite = require('./structures/Invite');
exports.InviteGuild = require('./structures/InviteGuild');
Expand Down
20 changes: 0 additions & 20 deletions packages/discord.js/src/structures/ClientApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,6 @@ class ClientApplication extends Application {
this.guildId ??= null;
}

if ('cover_image' in data) {
/**
* The hash of the application's cover image
* @type {?string}
*/
this.cover = data.cover_image;
} else {
this.cover ??= null;
}

if ('rpc_origins' in data) {
/**
* The application's RPC origins, if enabled
* @type {string[]}
*/
this.rpcOrigins = data.rpc_origins;
} else {
this.rpcOrigins ??= [];
}

if ('bot_require_code_grant' in data) {
/**
* If this application's bot requires a code grant when using the OAuth2 flow
Expand Down
10 changes: 0 additions & 10 deletions packages/discord.js/src/structures/IntegrationApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ class IntegrationApplication extends Application {
this.rpcOrigins ??= [];
}

if ('hook' in data) {
/**
* Whether the application can be default hooked by the client
* @type {?boolean}
*/
this.hook = data.hook;
} else {
this.hook ??= null;
}

if ('cover_image' in data) {
/**
* The hash of the application's cover image
Expand Down
36 changes: 3 additions & 33 deletions packages/discord.js/src/structures/InteractionCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const Events = require('../util/Events');
* @property {number} [maxComponents] The maximum number of components to collect
* @property {number} [maxUsers] The maximum number of users to interact
* @property {Message|APIMessage} [message] The message to listen to interactions from
* @property {InteractionResponse} [interactionResponse] The interaction response to listen
* to message component interactions from
*/

/**
Expand All @@ -40,30 +38,20 @@ class InteractionCollector extends Collector {
* The message from which to collect interactions, if provided
* @type {?Snowflake}
*/
this.messageId = options.message?.id ?? options.interactionResponse?.interaction.message?.id ?? null;

/**
* The message interaction id from which to collect interactions, if provided
* @type {?Snowflake}
*/
this.messageInteractionId = options.interactionResponse?.id ?? null;
this.messageId = options.message?.id ?? null;

/**
* The channel from which to collect interactions, if provided
* @type {?Snowflake}
*/
this.channelId =
options.interactionResponse?.interaction.channelId ??
options.message?.channelId ??
options.message?.channel_id ??
this.client.channels.resolveId(options.channel);
options.message?.channelId ?? options.message?.channel_id ?? this.client.channels.resolveId(options.channel);

/**
* The guild from which to collect interactions, if provided
* @type {?Snowflake}
*/
this.guildId =
options.interactionResponse?.interaction.guildId ??
options.message?.guildId ??
options.message?.guild_id ??
this.client.guilds.resolveId(options.channel?.guild) ??
Expand Down Expand Up @@ -99,7 +87,7 @@ class InteractionCollector extends Collector {
if (messages.has(this.messageId)) this.stop('messageDelete');
};

if (this.messageId || this.messageInteractionId) {
if (this.messageId) {
this._handleMessageDeletion = this._handleMessageDeletion.bind(this);
this.client.on(Events.MessageDelete, this._handleMessageDeletion);
this.client.on(Events.MessageBulkDelete, bulkDeleteListener);
Expand Down Expand Up @@ -151,13 +139,6 @@ class InteractionCollector extends Collector {
if (this.interactionType && interaction.type !== this.interactionType) return null;
if (this.componentType && interaction.componentType !== this.componentType) return null;
if (this.messageId && interaction.message?.id !== this.messageId) return null;
if (
this.messageInteractionId &&
interaction.message?.interactionMetadata?.id &&
interaction.message.interactionMetadata.id !== this.messageInteractionId
) {
return null;
}
if (this.channelId && interaction.channelId !== this.channelId) return null;
if (this.guildId && interaction.guildId !== this.guildId) return null;

Expand All @@ -178,13 +159,6 @@ class InteractionCollector extends Collector {
if (this.type && interaction.type !== this.type) return null;
if (this.componentType && interaction.componentType !== this.componentType) return null;
if (this.messageId && interaction.message?.id !== this.messageId) return null;
if (
this.messageInteractionId &&
interaction.message?.interactionMetadata?.id &&
interaction.message.interactionMetadata.id !== this.messageInteractionId
) {
return null;
}
if (this.channelId && interaction.channelId !== this.channelId) return null;
if (this.guildId && interaction.guildId !== this.guildId) return null;

Expand Down Expand Up @@ -223,10 +197,6 @@ class InteractionCollector extends Collector {
if (message.id === this.messageId) {
this.stop('messageDelete');
}

if (message.interactionMetadata?.id === this.messageInteractionId) {
this.stop('messageDelete');
}
}

/**
Expand Down
Loading

0 comments on commit 2837156

Please sign in to comment.