Skip to content

Commit

Permalink
Merge branch 'main' into types/exection-allow-forum
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Jun 14, 2023
2 parents d774a9a + 2818d7c commit 260179c
Show file tree
Hide file tree
Showing 23 changed files with 205 additions and 74 deletions.
2 changes: 1 addition & 1 deletion apps/website/src/components/ExcerptText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function ExcerptText({ model, excerpt }: ExcerptTextProps) {
<ItemLink
className="text-blurple"
itemURI={resolveItemURI(item)}
key={`${item.displayName}-${item.containerKey}`}
key={`${item.displayName}-${item.containerKey}-${idx}`}
packageName={item.getAssociatedPackage()?.displayName.replace('@discordjs/', '')}
>
{token.text}
Expand Down
18 changes: 8 additions & 10 deletions apps/website/src/components/model/method/Method.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
ApiMethodSignature,
} from '@microsoft/api-extractor-model';
import dynamic from 'next/dynamic';
import { Fragment } from 'react';
import { MethodDocumentation } from './MethodDocumentation';
import { MethodHeader } from './MethodHeader';

Expand All @@ -20,17 +21,14 @@ export function Method({
if (method.getMergedSiblings().length > 1) {
// We have overloads, use the overload switcher, but render
// each overload node on the server.
const overloads = method
.getMergedSiblings()
.map((sibling, idx) => (
<MethodDocumentation key={`${sibling.displayName}-${idx}`} method={sibling as ApiMethod | ApiMethodSignature} />
));
const overloads = method.getMergedSiblings().map((sibling, idx) => (
<Fragment key={`${sibling.displayName}-${idx}`}>
<MethodHeader method={sibling as ApiMethod | ApiMethodSignature} />
<MethodDocumentation method={sibling as ApiMethod | ApiMethodSignature} />
</Fragment>
));

return (
<OverloadSwitcher overloads={overloads}>
<MethodHeader method={method} />
</OverloadSwitcher>
);
return <OverloadSwitcher overloads={overloads} />;
}

// We have just a single method, render it on the server.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

## Installation

**Node.js 18.12.0 or newer is required.**
**Node.js 16.9.0 or newer is required.**

```sh
npm install @discordjs/core
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"vitest": "^0.31.1"
},
"engines": {
"node": ">=18.12.0"
"node": ">=16.9.0"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
import {
GatewayDispatchEvents,
GatewayOpcodes,
type GatewayApplicationCommandPermissionsUpdateDispatchData,
type GatewayAutoModerationActionExecutionDispatchData,
type GatewayAutoModerationRuleCreateDispatchData,
type GatewayAutoModerationRuleDeleteDispatchData,
Expand Down Expand Up @@ -89,6 +90,9 @@ export interface WithIntrinsicProps<T> extends IntrinsicProps {
}

export interface MappedEvents {
[GatewayDispatchEvents.ApplicationCommandPermissionsUpdate]: [
WithIntrinsicProps<GatewayApplicationCommandPermissionsUpdateDispatchData>,
];
[GatewayDispatchEvents.AutoModerationActionExecution]: [
WithIntrinsicProps<GatewayAutoModerationActionExecutionDispatchData>,
];
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
"@discordjs/builders": "workspace:^",
"@discordjs/collection": "workspace:^",
"@discordjs/formatters": "workspace:^",
"@discordjs/rest": "^1.7.1",
"@discordjs/rest": "workspace:^",
"@discordjs/util": "workspace:^",
"@discordjs/ws": "^0.8.3",
"@discordjs/ws": "workspace:^",
"@sapphire/snowflake": "^3.5.1",
"@types/ws": "^8.5.4",
"discord-api-types": "^0.37.42",
Expand Down
8 changes: 4 additions & 4 deletions packages/discord.js/src/managers/ThreadManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ class ThreadManager extends CachedManager {
}, new Collection());

// Discord sends the thread id as id in this object
const threadMembers = rawThreads.members.reduce(
(coll, raw) => coll.set(raw.user_id, threads.get(raw.id).members._add(raw)),
new Collection(),
);
const threadMembers = rawThreads.members.reduce((coll, raw) => {
const thread = threads.get(raw.id);
return thread ? coll.set(raw.user_id, thread.members._add(raw)) : coll;
}, new Collection());

const response = { threads, members: threadMembers };

Expand Down
6 changes: 6 additions & 0 deletions packages/discord.js/src/sharding/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ class Shard extends EventEmitter {
return;
}

// Shard has resumed
if (message._resume) {
this.ready = true;
return;
}

// Shard is requesting a property fetch
if (message._sFetchProp) {
const resp = { _sFetchProp: message._sFetchProp, _sFetchPropShard: message._sFetchPropShard };
Expand Down
6 changes: 6 additions & 0 deletions packages/discord.js/src/sharding/ShardClientUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class ShardClientUtil {
client.on(Events.ShardReconnecting, () => {
process.send({ _reconnecting: true });
});
client.on(Events.ShardResume, () => {
process.send({ _resume: true });
});
break;
case 'worker':
this.parentPort = require('node:worker_threads').parentPort;
Expand All @@ -55,6 +58,9 @@ class ShardClientUtil {
client.on(Events.ShardReconnecting, () => {
this.parentPort.postMessage({ _reconnecting: true });
});
client.on(Events.ShardResume, () => {
this.parentPort.postMessage({ _resume: true });
});
break;
}
}
Expand Down
13 changes: 7 additions & 6 deletions packages/discord.js/src/structures/ModalSubmitInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ class ModalSubmitInteraction extends BaseInteraction {
* @returns {ModalData[]}
*/
static transformComponent(rawComponent) {
return {
value: rawComponent.value,
type: rawComponent.type,
customId: rawComponent.custom_id,
components: rawComponent.components?.map(c => this.transformComponent(c)),
};
return rawComponent.components
? { type: rawComponent.type, components: rawComponent.components.map(c => this.transformComponent(c)) }
: {
value: rawComponent.value,
type: rawComponent.type,
customId: rawComponent.custom_id,
};
}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/discord.js/src/structures/Presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ class RichPresenceAssets {
switch (platform) {
case 'mp':
return `https://media.discordapp.net/${id}`;
case 'spotify':
return `https://i.scdn.co/image/${id}`;
case 'youtube':
return `https://i.ytimg.com/vi/${id}/hqdefault_live.jpg`;
case 'twitch':
return `https://static-cdn.jtvnw.net/previews-ttv/live_user_${id}.png`;
default:
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/src/structures/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class User extends Base {
this.id === user.id &&
this.username === user.username &&
this.discriminator === user.discriminator &&
this.globalName === user.globalName &&
this.avatar === user.avatar &&
this.flags?.bitfield === user.flags?.bitfield &&
this.banner === user.banner &&
Expand All @@ -291,6 +292,7 @@ class User extends Base {
this.id === user.id &&
this.username === user.username &&
this.discriminator === user.discriminator &&
this.globalName === user.global_name &&
this.avatar === user.avatar &&
this.flags?.bitfield === user.public_flags &&
('banner' in user ? this.banner === user.banner : true) &&
Expand Down
69 changes: 36 additions & 33 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1162,10 +1162,10 @@ export class CommandInteractionOptionResolver<Cached extends CacheType = CacheTy
public getSubcommandGroup(required?: boolean): string | null;
public getBoolean(name: string, required: true): boolean;
public getBoolean(name: string, required?: boolean): boolean | null;
public getChannel<T extends ChannelType = ChannelType>(
public getChannel<const T extends ChannelType = ChannelType>(
name: string,
required: true,
channelTypes?: T[],
channelTypes?: readonly T[],
): Extract<
NonNullable<CommandInteractionOption<Cached>['channel']>,
{
Expand All @@ -1177,10 +1177,10 @@ export class CommandInteractionOptionResolver<Cached extends CacheType = CacheTy
: T;
}
>;
public getChannel<T extends ChannelType = ChannelType>(
public getChannel<const T extends ChannelType = ChannelType>(
name: string,
required?: boolean,
channelTypes?: T[],
channelTypes?: readonly T[],
): Extract<
NonNullable<CommandInteractionOption<Cached>['channel']>,
{
Expand Down Expand Up @@ -2228,17 +2228,15 @@ export interface TextInputModalData extends BaseModalData {

export interface ActionRowModalData {
type: ComponentType.ActionRow;
components: ModalData[];
components: TextInputModalData[];
}

export type ModalData = TextInputModalData | ActionRowModalData;

export class ModalSubmitFields {
constructor(components: ModalActionRowComponent[][]);
public components: ActionRow<ModalActionRowComponent>;
public components: ActionRowModalData[];
public fields: Collection<string, ModalActionRowComponent>;
public getField<T extends ComponentType>(customId: string, type: T): { type: T } & ModalData;
public getField(customId: string, type?: ComponentType): ModalData;
public getField<T extends ComponentType>(customId: string, type: T): { type: T } & TextInputModalData;
public getField(customId: string, type?: ComponentType): TextInputModalData;
public getTextInputValue(customId: string): string;
}

Expand Down Expand Up @@ -3713,9 +3711,11 @@ export class ApplicationCommandManager<
id?: Snowflake,
options?: FetchApplicationCommandOptions,
): Promise<Collection<Snowflake, ApplicationCommandScope>>;
public set(commands: ApplicationCommandDataResolvable[]): Promise<Collection<Snowflake, ApplicationCommandScope>>;
public set(
commands: ApplicationCommandDataResolvable[],
commands: readonly ApplicationCommandDataResolvable[],
): Promise<Collection<Snowflake, ApplicationCommandScope>>;
public set(
commands: readonly ApplicationCommandDataResolvable[],
guildId: Snowflake,
): Promise<Collection<Snowflake, ApplicationCommand>>;
private static transformCommand(command: ApplicationCommandDataResolvable): RESTPostAPIApplicationCommandsJSONBody;
Expand Down Expand Up @@ -3748,21 +3748,21 @@ export class ApplicationCommandPermissionsManager<
options:
| (FetchSingleOptions & {
token: string;
channels?: (GuildChannelResolvable | ChannelPermissionConstant)[];
roles?: (RoleResolvable | RolePermissionConstant)[];
users: UserResolvable[];
channels?: readonly (GuildChannelResolvable | ChannelPermissionConstant)[];
roles?: readonly (RoleResolvable | RolePermissionConstant)[];
users: readonly UserResolvable[];
})
| (FetchSingleOptions & {
token: string;
channels?: (GuildChannelResolvable | ChannelPermissionConstant)[];
roles: (RoleResolvable | RolePermissionConstant)[];
users?: UserResolvable[];
channels?: readonly (GuildChannelResolvable | ChannelPermissionConstant)[];
roles: readonly (RoleResolvable | RolePermissionConstant)[];
users?: readonly UserResolvable[];
})
| (FetchSingleOptions & {
token: string;
channels: (GuildChannelResolvable | ChannelPermissionConstant)[];
roles?: (RoleResolvable | RolePermissionConstant)[];
users?: UserResolvable[];
channels: readonly (GuildChannelResolvable | ChannelPermissionConstant)[];
roles?: readonly (RoleResolvable | RolePermissionConstant)[];
users?: readonly UserResolvable[];
}),
): Promise<ApplicationCommandPermissions[]>;
public set(
Expand Down Expand Up @@ -4321,7 +4321,7 @@ export interface ChatInputApplicationCommandData extends BaseApplicationCommandD
description: string;
descriptionLocalizations?: LocalizationMap;
type?: ApplicationCommandType.ChatInput;
options?: ApplicationCommandOptionData[];
options?: readonly ApplicationCommandOptionData[];
}

export type ApplicationCommandData =
Expand All @@ -4331,13 +4331,13 @@ export type ApplicationCommandData =

export interface ApplicationCommandChannelOptionData extends BaseApplicationCommandOptionsData {
type: CommandOptionChannelResolvableType;
channelTypes?: ApplicationCommandOptionAllowedChannelTypes[];
channel_types?: ApplicationCommandOptionAllowedChannelTypes[];
channelTypes?: readonly ApplicationCommandOptionAllowedChannelTypes[];
channel_types?: readonly ApplicationCommandOptionAllowedChannelTypes[];
}

export interface ApplicationCommandChannelOption extends BaseApplicationCommandOptionsData {
type: ApplicationCommandOptionType.Channel;
channelTypes?: ApplicationCommandOptionAllowedChannelTypes[];
channelTypes?: readonly ApplicationCommandOptionAllowedChannelTypes[];
}

export interface ApplicationCommandRoleOptionData extends BaseApplicationCommandOptionsData {
Expand Down Expand Up @@ -4407,14 +4407,14 @@ export interface ApplicationCommandAutocompleteStringOptionData
export interface ApplicationCommandChoicesData<Type extends string | number = string | number>
extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
type: CommandOptionChoiceResolvableType;
choices?: ApplicationCommandOptionChoiceData<Type>[];
choices?: readonly ApplicationCommandOptionChoiceData<Type>[];
autocomplete?: false;
}

export interface ApplicationCommandChoicesOption<Type extends string | number = string | number>
extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
type: CommandOptionChoiceResolvableType;
choices?: ApplicationCommandOptionChoiceData<Type>[];
choices?: readonly ApplicationCommandOptionChoiceData<Type>[];
autocomplete?: false;
}

Expand Down Expand Up @@ -4456,22 +4456,25 @@ export interface ApplicationCommandBooleanOption extends BaseApplicationCommandO

export interface ApplicationCommandSubGroupData extends Omit<BaseApplicationCommandOptionsData, 'required'> {
type: ApplicationCommandOptionType.SubcommandGroup;
options: ApplicationCommandSubCommandData[];
options: readonly ApplicationCommandSubCommandData[];
}

export interface ApplicationCommandSubGroup extends Omit<BaseApplicationCommandOptionsData, 'required'> {
type: ApplicationCommandOptionType.SubcommandGroup;
options?: ApplicationCommandSubCommand[];
options?: readonly ApplicationCommandSubCommand[];
}

export interface ApplicationCommandSubCommandData extends Omit<BaseApplicationCommandOptionsData, 'required'> {
type: ApplicationCommandOptionType.Subcommand;
options?: Exclude<ApplicationCommandOptionData, ApplicationCommandSubGroupData | ApplicationCommandSubCommandData>[];
options?: readonly Exclude<
ApplicationCommandOptionData,
ApplicationCommandSubGroupData | ApplicationCommandSubCommandData
>[];
}

export interface ApplicationCommandSubCommand extends Omit<BaseApplicationCommandOptionsData, 'required'> {
type: ApplicationCommandOptionType.Subcommand;
options?: Exclude<ApplicationCommandOption, ApplicationCommandSubGroup | ApplicationCommandSubCommand>[];
options?: readonly Exclude<ApplicationCommandOption, ApplicationCommandSubGroup | ApplicationCommandSubCommand>[];
}

export interface ApplicationCommandNonOptionsData extends BaseApplicationCommandOptionsData {
Expand Down Expand Up @@ -4527,11 +4530,11 @@ export interface ApplicationCommandPermissionsUpdateData {
id: Snowflake;
guildId: Snowflake;
applicationId: Snowflake;
permissions: ApplicationCommandPermissions[];
permissions: readonly ApplicationCommandPermissions[];
}

export interface EditApplicationCommandPermissionsMixin {
permissions: ApplicationCommandPermissions[];
permissions: readonly ApplicationCommandPermissions[];
token: string;
}

Expand Down
Loading

0 comments on commit 260179c

Please sign in to comment.