mirror of
https://github.com/discordjs/discord.js.git
synced 2024-07-08 02:01:19 +12:00
Merge branch 'main' into chore/label-enhancements
This commit is contained in:
commit
a055170a57
|
@ -5,7 +5,7 @@
|
|||
"type-enum": [
|
||||
2,
|
||||
"always",
|
||||
["chore", "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test", "types", "typings"]
|
||||
["chore", "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test", "types"]
|
||||
],
|
||||
"scope-case": [0]
|
||||
}
|
||||
|
|
2
.github/COMMIT_CONVENTION.md
vendored
2
.github/COMMIT_CONVENTION.md
vendored
|
@ -7,7 +7,7 @@
|
|||
Messages must be matched by the following regex:
|
||||
|
||||
```js
|
||||
/^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|build|ci|chore|types|wip)(\(.+\))?: .{1,72}/;
|
||||
/^(revert: )?(feat|fix|docs|style|refactor|perf|test|build|ci|chore|types)(\(.+\))?: .{1,72}/;
|
||||
```
|
||||
|
||||
#### Examples
|
||||
|
|
5
.github/workflows/pr-triage.yml
vendored
5
.github/workflows/pr-triage.yml
vendored
|
@ -23,9 +23,10 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Validate pull request title
|
||||
env:
|
||||
TITLE: ${{ github.event.pull_request.title }}
|
||||
run: |
|
||||
TITLE="${{ github.event.pull_request.title }}"
|
||||
REGEX="^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|build|ci|chore|types|wip)(\\(.+\\))?: .{1,72}$"
|
||||
REGEX="^(revert: )?(feat|fix|docs|style|refactor|perf|test|build|ci|chore|types)(\\(.+\\))?: .{1,72}$"
|
||||
|
||||
echo "Title: \"$TITLE\""
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ export async function DocNode({ node, version }: { readonly node?: any; readonly
|
|||
rel="external noreferrer noopener"
|
||||
target="_blank"
|
||||
>
|
||||
{`${node.text}${node.members}`}
|
||||
{`${node.text}${node.members ?? ''}`}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -115,6 +115,7 @@ export class ModelReferenceResolver {
|
|||
if (memberSelector === undefined) {
|
||||
if (foundMembers.length > 1) {
|
||||
const foundClass: ApiItem | undefined = foundMembers.find((member) => member.kind === ApiItemKind.Class);
|
||||
const foundEvent: ApiItem | undefined = foundMembers.find((member) => member.kind === ApiItemKind.Event);
|
||||
if (
|
||||
foundClass &&
|
||||
foundMembers.filter((member) => member.kind === ApiItemKind.Interface).length === foundMembers.length - 1
|
||||
|
@ -124,6 +125,11 @@ export class ModelReferenceResolver {
|
|||
foundMembers.every((member) => member.kind === ApiItemKind.Method && (member as ApiMethod).overloadIndex)
|
||||
) {
|
||||
currentItem = foundMembers.find((member) => (member as ApiMethod).overloadIndex === 1)!;
|
||||
} else if (
|
||||
foundEvent &&
|
||||
foundMembers.filter((member) => member.kind === ApiItemKind.Method).length === foundMembers.length - 1
|
||||
) {
|
||||
currentItem = foundEvent;
|
||||
} else {
|
||||
result.errorMessage = `The member reference ${JSON.stringify(identifier)} was ambiguous`;
|
||||
return result;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { PermissionFlagsBits } from 'discord-api-types/v10';
|
||||
import { ApplicationIntegrationType, InteractionContextType, PermissionFlagsBits } from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { ContextMenuCommandAssertions, ContextMenuCommandBuilder } from '../../src/index.js';
|
||||
|
||||
|
@ -144,5 +144,51 @@ describe('Context Menu Commands', () => {
|
|||
expect(() => getBuilder().setDefaultMemberPermissions(1.1)).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('contexts', () => {
|
||||
test('GIVEN a builder with valid contexts THEN does not throw an error', () => {
|
||||
expect(() =>
|
||||
getBuilder().setContexts([InteractionContextType.Guild, InteractionContextType.BotDM]),
|
||||
).not.toThrowError();
|
||||
|
||||
expect(() =>
|
||||
getBuilder().setContexts(InteractionContextType.Guild, InteractionContextType.BotDM),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a builder with invalid contexts THEN does throw an error', () => {
|
||||
// @ts-expect-error: Invalid contexts
|
||||
expect(() => getBuilder().setContexts(999)).toThrowError();
|
||||
|
||||
// @ts-expect-error: Invalid contexts
|
||||
expect(() => getBuilder().setContexts([999, 998])).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('integration types', () => {
|
||||
test('GIVEN a builder with valid integraton types THEN does not throw an error', () => {
|
||||
expect(() =>
|
||||
getBuilder().setIntegrationTypes([
|
||||
ApplicationIntegrationType.GuildInstall,
|
||||
ApplicationIntegrationType.UserInstall,
|
||||
]),
|
||||
).not.toThrowError();
|
||||
|
||||
expect(() =>
|
||||
getBuilder().setIntegrationTypes(
|
||||
ApplicationIntegrationType.GuildInstall,
|
||||
ApplicationIntegrationType.UserInstall,
|
||||
),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a builder with invalid integration types THEN does throw an error', () => {
|
||||
// @ts-expect-error: Invalid integration types
|
||||
expect(() => getBuilder().setIntegrationTypes(999)).toThrowError();
|
||||
|
||||
// @ts-expect-error: Invalid integration types
|
||||
expect(() => getBuilder().setIntegrationTypes([999, 998])).toThrowError();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
import { ChannelType, PermissionFlagsBits, type APIApplicationCommandOptionChoice } from 'discord-api-types/v10';
|
||||
import {
|
||||
ApplicationIntegrationType,
|
||||
ChannelType,
|
||||
InteractionContextType,
|
||||
PermissionFlagsBits,
|
||||
type APIApplicationCommandOptionChoice,
|
||||
} from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
SlashCommandAssertions,
|
||||
|
@ -532,5 +538,51 @@ describe('Slash Commands', () => {
|
|||
expect(() => getBuilder().addChannelOption(getChannelOption()).setDMPermission(false)).not.toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('contexts', () => {
|
||||
test('GIVEN a builder with valid contexts THEN does not throw an error', () => {
|
||||
expect(() =>
|
||||
getBuilder().setContexts([InteractionContextType.Guild, InteractionContextType.BotDM]),
|
||||
).not.toThrowError();
|
||||
|
||||
expect(() =>
|
||||
getBuilder().setContexts(InteractionContextType.Guild, InteractionContextType.BotDM),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a builder with invalid contexts THEN does throw an error', () => {
|
||||
// @ts-expect-error: Invalid contexts
|
||||
expect(() => getBuilder().setContexts(999)).toThrowError();
|
||||
|
||||
// @ts-expect-error: Invalid contexts
|
||||
expect(() => getBuilder().setContexts([999, 998])).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('integration types', () => {
|
||||
test('GIVEN a builder with valid integraton types THEN does not throw an error', () => {
|
||||
expect(() =>
|
||||
getBuilder().setIntegrationTypes([
|
||||
ApplicationIntegrationType.GuildInstall,
|
||||
ApplicationIntegrationType.UserInstall,
|
||||
]),
|
||||
).not.toThrowError();
|
||||
|
||||
expect(() =>
|
||||
getBuilder().setIntegrationTypes(
|
||||
ApplicationIntegrationType.GuildInstall,
|
||||
ApplicationIntegrationType.UserInstall,
|
||||
),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a builder with invalid integration types THEN does throw an error', () => {
|
||||
// @ts-expect-error: Invalid integration types
|
||||
expect(() => getBuilder().setIntegrationTypes(999)).toThrowError();
|
||||
|
||||
// @ts-expect-error: Invalid integration types
|
||||
expect(() => getBuilder().setIntegrationTypes([999, 998])).toThrowError();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
"@discordjs/formatters": "workspace:^",
|
||||
"@discordjs/util": "workspace:^",
|
||||
"@sapphire/shapeshift": "^3.9.7",
|
||||
"discord-api-types": "0.37.87",
|
||||
"discord-api-types": "0.37.90",
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"ts-mixer": "^6.0.4",
|
||||
"tslib": "^2.6.2"
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import {
|
||||
ComponentType,
|
||||
type APIMessageComponentEmoji,
|
||||
type APIButtonComponent,
|
||||
type APIButtonComponentWithURL,
|
||||
type APIButtonComponentWithCustomId,
|
||||
type APIButtonComponentWithSKUId,
|
||||
type APIButtonComponentWithURL,
|
||||
type APIMessageComponentEmoji,
|
||||
type ButtonStyle,
|
||||
} from 'discord-api-types/v10';
|
||||
import {
|
||||
|
@ -94,7 +95,7 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
|||
* @param emoji - The emoji to use
|
||||
*/
|
||||
public setEmoji(emoji: APIMessageComponentEmoji) {
|
||||
this.data.emoji = emojiValidator.parse(emoji);
|
||||
(this.data as Exclude<APIButtonComponent, APIButtonComponentWithSKUId>).emoji = emojiValidator.parse(emoji);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -114,7 +115,7 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
|||
* @param label - The label to use
|
||||
*/
|
||||
public setLabel(label: string) {
|
||||
this.data.label = buttonLabelValidator.parse(label);
|
||||
(this.data as Exclude<APIButtonComponent, APIButtonComponentWithSKUId>).label = buttonLabelValidator.parse(label);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -124,8 +125,8 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
|||
public toJSON(): APIButtonComponent {
|
||||
validateRequiredButtonParameters(
|
||||
this.data.style,
|
||||
this.data.label,
|
||||
this.data.emoji,
|
||||
(this.data as Exclude<APIButtonComponent, APIButtonComponentWithSKUId>).label,
|
||||
(this.data as Exclude<APIButtonComponent, APIButtonComponentWithSKUId>).emoji,
|
||||
(this.data as APIButtonComponentWithCustomId).custom_id,
|
||||
(this.data as APIButtonComponentWithURL).url,
|
||||
);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { s } from '@sapphire/shapeshift';
|
||||
import { ApplicationCommandType } from 'discord-api-types/v10';
|
||||
import { ApplicationCommandType, ApplicationIntegrationType, InteractionContextType } from 'discord-api-types/v10';
|
||||
import { isValidationEnabled } from '../../util/validation.js';
|
||||
import type { ContextMenuCommandType } from './ContextMenuCommandBuilder.js';
|
||||
|
||||
|
@ -49,3 +49,11 @@ const memberPermissionPredicate = s.union(
|
|||
export function validateDefaultMemberPermissions(permissions: unknown) {
|
||||
return memberPermissionPredicate.parse(permissions);
|
||||
}
|
||||
|
||||
export const contextsPredicate = s.array(
|
||||
s.nativeEnum(InteractionContextType).setValidationEnabled(isValidationEnabled),
|
||||
);
|
||||
|
||||
export const integrationTypesPredicate = s.array(
|
||||
s.nativeEnum(ApplicationIntegrationType).setValidationEnabled(isValidationEnabled),
|
||||
);
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
import type {
|
||||
ApplicationCommandType,
|
||||
ApplicationIntegrationType,
|
||||
InteractionContextType,
|
||||
LocaleString,
|
||||
LocalizationMap,
|
||||
Permissions,
|
||||
RESTPostAPIContextMenuApplicationCommandsJSONBody,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { RestOrArray } from '../../util/normalizeArray.js';
|
||||
import { normalizeArray } from '../../util/normalizeArray.js';
|
||||
import { validateLocale, validateLocalizationMap } from '../slashCommands/Assertions.js';
|
||||
import {
|
||||
validateRequiredParameters,
|
||||
|
@ -13,6 +17,8 @@ import {
|
|||
validateDefaultPermission,
|
||||
validateDefaultMemberPermissions,
|
||||
validateDMPermission,
|
||||
contextsPredicate,
|
||||
integrationTypesPredicate,
|
||||
} from './Assertions.js';
|
||||
|
||||
/**
|
||||
|
@ -39,6 +45,11 @@ export class ContextMenuCommandBuilder {
|
|||
*/
|
||||
public readonly type: ContextMenuCommandType = undefined!;
|
||||
|
||||
/**
|
||||
* The contexts for this command.
|
||||
*/
|
||||
public readonly contexts?: InteractionContextType[];
|
||||
|
||||
/**
|
||||
* Whether this command is enabled by default when the application is added to a guild.
|
||||
*
|
||||
|
@ -59,6 +70,33 @@ export class ContextMenuCommandBuilder {
|
|||
*/
|
||||
public readonly dm_permission: boolean | undefined = undefined;
|
||||
|
||||
/**
|
||||
* The integration types for this command.
|
||||
*/
|
||||
public readonly integration_types?: ApplicationIntegrationType[];
|
||||
|
||||
/**
|
||||
* Sets the contexts of this command.
|
||||
*
|
||||
* @param contexts - The contexts
|
||||
*/
|
||||
public setContexts(...contexts: RestOrArray<InteractionContextType>) {
|
||||
Reflect.set(this, 'contexts', contextsPredicate.parse(normalizeArray(contexts)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets integration types of this command.
|
||||
*
|
||||
* @param integrationTypes - The integration types
|
||||
*/
|
||||
public setIntegrationTypes(...integrationTypes: RestOrArray<ApplicationIntegrationType>) {
|
||||
Reflect.set(this, 'integration_types', integrationTypesPredicate.parse(normalizeArray(integrationTypes)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of this command.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
import { s } from '@sapphire/shapeshift';
|
||||
import { Locale, type APIApplicationCommandOptionChoice, type LocalizationMap } from 'discord-api-types/v10';
|
||||
import {
|
||||
ApplicationIntegrationType,
|
||||
InteractionContextType,
|
||||
Locale,
|
||||
type APIApplicationCommandOptionChoice,
|
||||
type LocalizationMap,
|
||||
} from 'discord-api-types/v10';
|
||||
import { isValidationEnabled } from '../../util/validation.js';
|
||||
import type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder.js';
|
||||
import type { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands.js';
|
||||
|
@ -98,3 +104,11 @@ export function validateDefaultMemberPermissions(permissions: unknown) {
|
|||
export function validateNSFW(value: unknown): asserts value is boolean {
|
||||
booleanPredicate.parse(value);
|
||||
}
|
||||
|
||||
export const contextsPredicate = s.array(
|
||||
s.nativeEnum(InteractionContextType).setValidationEnabled(isValidationEnabled),
|
||||
);
|
||||
|
||||
export const integrationTypesPredicate = s.array(
|
||||
s.nativeEnum(ApplicationIntegrationType).setValidationEnabled(isValidationEnabled),
|
||||
);
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
import type { APIApplicationCommandOption, LocalizationMap, Permissions } from 'discord-api-types/v10';
|
||||
import type {
|
||||
APIApplicationCommandOption,
|
||||
ApplicationIntegrationType,
|
||||
InteractionContextType,
|
||||
LocalizationMap,
|
||||
Permissions,
|
||||
} from 'discord-api-types/v10';
|
||||
import { mix } from 'ts-mixer';
|
||||
import { SharedNameAndDescription } from './mixins/NameAndDescription.js';
|
||||
import { SharedSlashCommand } from './mixins/SharedSlashCommand.js';
|
||||
|
@ -35,6 +41,11 @@ export class SlashCommandBuilder {
|
|||
*/
|
||||
public readonly options: ToAPIApplicationCommandOptions[] = [];
|
||||
|
||||
/**
|
||||
* The contexts for this command.
|
||||
*/
|
||||
public readonly contexts?: InteractionContextType[];
|
||||
|
||||
/**
|
||||
* Whether this command is enabled by default when the application is added to a guild.
|
||||
*
|
||||
|
@ -55,6 +66,11 @@ export class SlashCommandBuilder {
|
|||
*/
|
||||
public readonly dm_permission: boolean | undefined = undefined;
|
||||
|
||||
/**
|
||||
* The integration types for this command.
|
||||
*/
|
||||
public readonly integration_types?: ApplicationIntegrationType[];
|
||||
|
||||
/**
|
||||
* Whether this command is NSFW.
|
||||
*/
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
import type {
|
||||
ApplicationIntegrationType,
|
||||
InteractionContextType,
|
||||
LocalizationMap,
|
||||
Permissions,
|
||||
RESTPostAPIChatInputApplicationCommandsJSONBody,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { RestOrArray } from '../../../util/normalizeArray.js';
|
||||
import { normalizeArray } from '../../../util/normalizeArray.js';
|
||||
import {
|
||||
contextsPredicate,
|
||||
integrationTypesPredicate,
|
||||
validateDMPermission,
|
||||
validateDefaultMemberPermissions,
|
||||
validateDefaultPermission,
|
||||
|
@ -27,6 +33,8 @@ export class SharedSlashCommand {
|
|||
|
||||
public readonly options: ToAPIApplicationCommandOptions[] = [];
|
||||
|
||||
public readonly contexts?: InteractionContextType[];
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link SharedSlashCommand.setDefaultMemberPermissions} or {@link SharedSlashCommand.setDMPermission} instead.
|
||||
*/
|
||||
|
@ -36,8 +44,32 @@ export class SharedSlashCommand {
|
|||
|
||||
public readonly dm_permission: boolean | undefined = undefined;
|
||||
|
||||
public readonly integration_types?: ApplicationIntegrationType[];
|
||||
|
||||
public readonly nsfw: boolean | undefined = undefined;
|
||||
|
||||
/**
|
||||
* Sets the contexts of this command.
|
||||
*
|
||||
* @param contexts - The contexts
|
||||
*/
|
||||
public setContexts(...contexts: RestOrArray<InteractionContextType>) {
|
||||
Reflect.set(this, 'contexts', contextsPredicate.parse(normalizeArray(contexts)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the integration types of this command.
|
||||
*
|
||||
* @param integrationTypes - The integration types
|
||||
*/
|
||||
public setIntegrationTypes(...integrationTypes: RestOrArray<ApplicationIntegrationType>) {
|
||||
Reflect.set(this, 'integration_types', integrationTypesPredicate.parse(normalizeArray(integrationTypes)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the command is enabled by default when the application is added to a guild.
|
||||
*
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
"@discordjs/ws": "workspace:^",
|
||||
"@sapphire/snowflake": "^3.5.3",
|
||||
"@vladfrangu/async_event_emitter": "^2.2.4",
|
||||
"discord-api-types": "0.37.87"
|
||||
"discord-api-types": "0.37.90"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@discordjs/api-extractor": "workspace:^",
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
"@discordjs/util": "workspace:^",
|
||||
"@discordjs/ws": "workspace:^",
|
||||
"@sapphire/snowflake": "3.5.3",
|
||||
"discord-api-types": "0.37.87",
|
||||
"discord-api-types": "0.37.90",
|
||||
"fast-deep-equal": "3.1.3",
|
||||
"lodash.snakecase": "4.1.1",
|
||||
"tslib": "2.6.2",
|
||||
|
|
|
@ -117,14 +117,14 @@ class WebSocketManager extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Emits a debug message.
|
||||
* @param {string} message The debug message
|
||||
* @param {string[]} messages The debug message
|
||||
* @param {?number} [shardId] The id of the shard that emitted this message, if any
|
||||
* @private
|
||||
*/
|
||||
debug(message, shardId) {
|
||||
debug(messages, shardId) {
|
||||
this.client.emit(
|
||||
Events.Debug,
|
||||
`[WS => ${typeof shardId === 'number' ? `Shard ${shardId}` : 'Manager'}] ${message}`,
|
||||
`[WS => ${typeof shardId === 'number' ? `Shard ${shardId}` : 'Manager'}] ${messages.join('\n\t')}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -170,15 +170,8 @@ class WebSocketManager extends EventEmitter {
|
|||
});
|
||||
|
||||
const { total, remaining } = sessionStartLimit;
|
||||
|
||||
this.debug(`Fetched Gateway Information
|
||||
URL: ${gatewayURL}
|
||||
Recommended Shards: ${recommendedShards}`);
|
||||
|
||||
this.debug(`Session Limit Information
|
||||
Total: ${total}
|
||||
Remaining: ${remaining}`);
|
||||
|
||||
this.debug(['Fetched Gateway Information', `URL: ${gatewayURL}`, `Recommended Shards: ${recommendedShards}`]);
|
||||
this.debug(['Session Limit Information', `Total: ${total}`, `Remaining: ${remaining}`]);
|
||||
this.gateway = `${gatewayURL}/`;
|
||||
|
||||
this.client.options.shardCount = await this._ws.getShardCount();
|
||||
|
@ -231,7 +224,7 @@ class WebSocketManager extends EventEmitter {
|
|||
* @private
|
||||
*/
|
||||
attachEvents() {
|
||||
this._ws.on(WSWebSocketShardEvents.Debug, ({ message, shardId }) => this.debug(message, shardId));
|
||||
this._ws.on(WSWebSocketShardEvents.Debug, ({ message, shardId }) => this.debug([message], shardId));
|
||||
this._ws.on(WSWebSocketShardEvents.Dispatch, ({ data, shardId }) => {
|
||||
this.client.emit(Events.Raw, data, shardId);
|
||||
this.emit(data.t, data.d, shardId);
|
||||
|
@ -258,7 +251,7 @@ class WebSocketManager extends EventEmitter {
|
|||
* @param {number} id The shard id that disconnected
|
||||
*/
|
||||
this.client.emit(Events.ShardDisconnect, { code, reason: reasonIsDeprecated, wasClean: true }, shardId);
|
||||
this.debug(`Shard not resumable: ${code} (${GatewayCloseCodes[code] ?? CloseCodes[code]})`, shardId);
|
||||
this.debug([`Shard not resumable: ${code} (${GatewayCloseCodes[code] ?? CloseCodes[code]})`], shardId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -291,7 +284,7 @@ class WebSocketManager extends EventEmitter {
|
|||
});
|
||||
|
||||
this._ws.on(WSWebSocketShardEvents.HeartbeatComplete, ({ heartbeatAt, latency, shardId }) => {
|
||||
this.debug(`Heartbeat acknowledged, latency of ${latency}ms.`, shardId);
|
||||
this.debug([`Heartbeat acknowledged, latency of ${latency}ms.`], shardId);
|
||||
const shard = this.shards.get(shardId);
|
||||
shard.lastPingTimestamp = heartbeatAt;
|
||||
shard.ping = latency;
|
||||
|
@ -324,7 +317,7 @@ class WebSocketManager extends EventEmitter {
|
|||
async destroy() {
|
||||
if (this.destroyed) return;
|
||||
// TODO: Make a util for getting a stack
|
||||
this.debug(Object.assign(new Error(), { name: 'Manager was destroyed:' }).stack);
|
||||
this.debug([Object.assign(new Error(), { name: 'Manager was destroyed:' }).stack]);
|
||||
this.destroyed = true;
|
||||
await this._ws?.destroy({ code: CloseCodes.Normal, reason: 'Manager was destroyed' });
|
||||
}
|
||||
|
|
|
@ -85,11 +85,11 @@ class WebSocketShard extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Emits a debug event.
|
||||
* @param {string} message The debug message
|
||||
* @param {string[]} messages The debug message
|
||||
* @private
|
||||
*/
|
||||
debug(message) {
|
||||
this.manager.debug(message, this.id);
|
||||
debug(messages) {
|
||||
this.manager.debug(messages, this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,10 +110,13 @@ class WebSocketShard extends EventEmitter {
|
|||
wasClean: false,
|
||||
},
|
||||
) {
|
||||
this.debug(`[CLOSE]
|
||||
Event Code: ${event.code}
|
||||
Clean : ${event.wasClean}
|
||||
Reason : ${event.reason ?? 'No reason received'}`);
|
||||
this.debug([
|
||||
'[CLOSE]',
|
||||
`Event Code: ${event.code}`,
|
||||
`Clean : ${event.wasClean}`,
|
||||
`Reason : ${event.reason ?? 'No reason received'}`,
|
||||
]);
|
||||
|
||||
/**
|
||||
* Emitted when a shard's WebSocket closes.
|
||||
* @private
|
||||
|
@ -130,7 +133,7 @@ class WebSocketShard extends EventEmitter {
|
|||
*/
|
||||
onReadyPacket(packet) {
|
||||
if (!packet) {
|
||||
this.debug(`Received broken packet: '${packet}'.`);
|
||||
this.debug([`Received broken packet: '${packet}'.`]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -167,7 +170,7 @@ class WebSocketShard extends EventEmitter {
|
|||
}
|
||||
// Step 1. If we don't have any other guilds pending, we are ready
|
||||
if (!this.expectedGuilds.size) {
|
||||
this.debug('Shard received all its guilds. Marking as fully ready.');
|
||||
this.debug(['Shard received all its guilds. Marking as fully ready.']);
|
||||
this.status = Status.Ready;
|
||||
|
||||
/**
|
||||
|
@ -191,12 +194,12 @@ class WebSocketShard extends EventEmitter {
|
|||
|
||||
this.readyTimeout = setTimeout(
|
||||
() => {
|
||||
this.debug(
|
||||
`Shard ${hasGuildsIntent ? 'did' : 'will'} not receive any more guild packets` +
|
||||
`${hasGuildsIntent ? ` in ${waitGuildTimeout} ms` : ''}.\nUnavailable guild count: ${
|
||||
this.expectedGuilds.size
|
||||
}`,
|
||||
);
|
||||
this.debug([
|
||||
hasGuildsIntent
|
||||
? `Shard did not receive any guild packets in ${waitGuildTimeout} ms.`
|
||||
: 'Shard will not receive anymore guild packets.',
|
||||
`Unavailable guild count: ${this.expectedGuilds.size}`,
|
||||
]);
|
||||
|
||||
this.readyTimeout = null;
|
||||
this.status = Status.Ready;
|
||||
|
|
|
@ -128,8 +128,9 @@ class GuildMemberManager extends CachedManager {
|
|||
resolvedOptions.roles = resolvedRoles;
|
||||
}
|
||||
const data = await this.client.rest.put(Routes.guildMember(this.guild.id, userId), { body: resolvedOptions });
|
||||
// Data is an empty Uint8Array if the member is already part of the guild.
|
||||
return data instanceof Uint8Array
|
||||
|
||||
// Data is an empty array buffer if the member is already part of the guild.
|
||||
return data instanceof ArrayBuffer
|
||||
? options.fetchWhenExisting === false
|
||||
? null
|
||||
: this.fetch(userId)
|
||||
|
|
6
packages/discord.js/typings/index.d.ts
vendored
6
packages/discord.js/typings/index.d.ts
vendored
|
@ -3653,7 +3653,7 @@ export class WebSocketManager extends EventEmitter {
|
|||
public on(event: GatewayDispatchEvents, listener: (data: any, shardId: number) => void): this;
|
||||
public once(event: GatewayDispatchEvents, listener: (data: any, shardId: number) => void): this;
|
||||
|
||||
private debug(message: string, shardId?: number): void;
|
||||
private debug(messages: readonly string[], shardId?: number): void;
|
||||
private connect(): Promise<void>;
|
||||
private broadcast(packet: unknown): void;
|
||||
private destroy(): Promise<void>;
|
||||
|
@ -3684,7 +3684,7 @@ export class WebSocketShard extends EventEmitter {
|
|||
public status: Status;
|
||||
public ping: number;
|
||||
|
||||
private debug(message: string): void;
|
||||
private debug(messages: readonly string[]): void;
|
||||
private onReadyPacket(packet: unknown): void;
|
||||
private gotGuild(guildId: Snowflake): void;
|
||||
private checkReady(): void;
|
||||
|
@ -4069,7 +4069,7 @@ export class ApplicationCommandManager<
|
|||
id: Snowflake,
|
||||
options: FetchApplicationCommandOptions & { guildId: Snowflake },
|
||||
): Promise<ApplicationCommand>;
|
||||
public fetch(options: FetchApplicationCommandOptions): Promise<Collection<string, ApplicationCommandScope>>;
|
||||
public fetch(options: FetchApplicationCommandOptions): Promise<Collection<Snowflake, ApplicationCommandScope>>;
|
||||
public fetch(id: Snowflake, options?: FetchApplicationCommandOptions): Promise<ApplicationCommandScope>;
|
||||
public fetch(
|
||||
id?: Snowflake,
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
"homepage": "https://discord.js.org",
|
||||
"funding": "https://github.com/discordjs/discord.js?sponsor",
|
||||
"dependencies": {
|
||||
"discord-api-types": "0.37.87"
|
||||
"discord-api-types": "0.37.90"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@discordjs/api-extractor": "workspace:^",
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
"@discordjs/rest": "workspace:^",
|
||||
"@discordjs/util": "workspace:^",
|
||||
"@discordjs/ws": "workspace:^",
|
||||
"discord-api-types": "0.37.87"
|
||||
"discord-api-types": "0.37.90"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@discordjs/api-extractor": "workspace:^",
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
"@sapphire/async-queue": "^1.5.2",
|
||||
"@sapphire/snowflake": "^3.5.3",
|
||||
"@vladfrangu/async_event_emitter": "^2.2.4",
|
||||
"discord-api-types": "0.37.87",
|
||||
"discord-api-types": "0.37.90",
|
||||
"magic-bytes.js": "^1.10.0",
|
||||
"tslib": "^2.6.2",
|
||||
"undici": "6.18.2"
|
||||
|
|
|
@ -240,7 +240,12 @@ function itemExcerptText(excerpt: Excerpt, apiPackage: ApiPackage) {
|
|||
// dapi-types doesn't have routes for class members
|
||||
// so we can assume this member is for an enum
|
||||
if (meaning === 'member' && path && 'parent' in path) {
|
||||
href += `/enum/${path.parent}#${path.component}`;
|
||||
// unless it's a variable like FormattingPatterns.Role
|
||||
if (path.parent.toString() === '__type') {
|
||||
href += `#${token.text.split('.')[0]}`;
|
||||
} else {
|
||||
href += `/enum/${path.parent}#${path.component}`;
|
||||
}
|
||||
} else if (meaning === 'type' || meaning === 'var') {
|
||||
href += `#${token.text}`;
|
||||
} else {
|
||||
|
@ -951,11 +956,16 @@ export async function generateSplitDocumentation({
|
|||
|
||||
const members = entry.members
|
||||
.filter((item) => {
|
||||
if (item.kind !== 'Function') {
|
||||
return true;
|
||||
switch (item.kind) {
|
||||
case ApiItemKind.Function:
|
||||
return (item as ApiFunction).overloadIndex === 1;
|
||||
case ApiItemKind.Interface:
|
||||
return !entry.members.some(
|
||||
(innerItem) => innerItem.kind === ApiItemKind.Class && innerItem.displayName === item.displayName,
|
||||
);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
||||
return (item as ApiFunction).overloadIndex === 1;
|
||||
})
|
||||
.map((item) => ({
|
||||
kind: item.kind,
|
||||
|
|
|
@ -41,14 +41,15 @@ export default function generator(plop: PlopTypes.NodePlopAPI): void {
|
|||
{
|
||||
type: 'addMany',
|
||||
destination: `${plop.getDestBasePath()}/../{{name}}`,
|
||||
templateFiles: ['templates/**'],
|
||||
// plop doesn't like our cliff.toml file since it tries to parse it. we add it manually later
|
||||
templateFiles: ['templates/**', '!templates/default/cliff.toml'],
|
||||
globOptions: { dot: true },
|
||||
base: 'templates/default/',
|
||||
stripExtensions: ['hbs'],
|
||||
},
|
||||
{
|
||||
type: 'modify',
|
||||
path: `${plop.getDestBasePath()}/turbo/generators/templates/cliff.toml`,
|
||||
path: `${plop.getDestBasePath()}/turbo/generators/templates/default/cliff.toml`,
|
||||
async transform(content, answers) {
|
||||
const cliffTOML = content.replace('{{name}}', answers.name);
|
||||
await writeFile(`${plop.getDestBasePath()}/../${answers.name}/cliff.toml`, cliffTOML);
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
# Packages node_modules # Log files logs *.log npm-debug.log* # Runtime data pids *.pid *.seed # Env .env # Dist dist
|
||||
dist-docs # Docs docs/**/* !docs/README.md # Miscellaneous .turbo .tmp coverage
|
||||
dist-docs # Docs docs/**/* !docs/README.md # Miscellaneous .turbo .tmp coverage
|
|
@ -64,7 +64,7 @@
|
|||
"funding": "https://github.com/discordjs/discord.js?sponsor",
|
||||
"dependencies": {
|
||||
"@types/ws": "^8.5.10",
|
||||
"discord-api-types": "0.37.87",
|
||||
"discord-api-types": "0.37.90",
|
||||
"prism-media": "^1.3.5",
|
||||
"tslib": "^2.6.2",
|
||||
"ws": "^8.17.0"
|
||||
|
|
|
@ -79,7 +79,7 @@
|
|||
"@sapphire/async-queue": "^1.5.2",
|
||||
"@types/ws": "^8.5.10",
|
||||
"@vladfrangu/async_event_emitter": "^2.2.4",
|
||||
"discord-api-types": "0.37.87",
|
||||
"discord-api-types": "0.37.90",
|
||||
"tslib": "^2.6.2",
|
||||
"ws": "^8.17.0"
|
||||
},
|
||||
|
|
|
@ -915,15 +915,6 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
|
|||
}
|
||||
|
||||
private debug(messages: [string, ...string[]]) {
|
||||
const message = `${messages[0]}${
|
||||
messages.length > 1
|
||||
? `\n${messages
|
||||
.slice(1)
|
||||
.map((message) => ` ${message}`)
|
||||
.join('\n')}`
|
||||
: ''
|
||||
}`;
|
||||
|
||||
this.emit(WebSocketShardEvents.Debug, { message });
|
||||
this.emit(WebSocketShardEvents.Debug, { message: messages.join('\n\t') });
|
||||
}
|
||||
}
|
||||
|
|
2284
pnpm-lock.yaml
generated
2284
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue