feat: backport guild forum support to v13 (#8651)

Co-authored-by: Jaworek <jaworekwiadomosci@gmail.com>
Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
This commit is contained in:
Elysia
2023-01-02 22:21:15 +07:00
committed by GitHub
parent 56e67185fc
commit 546ac43911
24 changed files with 903 additions and 127 deletions

12
typings/enums.d.ts vendored
View File

@@ -49,6 +49,18 @@ export const enum ChannelTypes {
GUILD_PRIVATE_THREAD = 12,
GUILD_STAGE_VOICE = 13,
GUILD_DIRECTORY = 14,
GUILD_FORUM = 15,
}
export const enum SortOrderType {
LATEST_ACTIVITY = 1,
CREATION_DATE = 2,
}
export const enum ForumLayoutType {
NOT_SET = 0,
LIST_VIEW = 1,
GALLERY_VIEW = 2,
}
export const enum MessageTypes {

147
typings/index.d.ts vendored
View File

@@ -90,6 +90,8 @@ import {
GuildScheduledEventStatuses,
GuildScheduledEventPrivacyLevels,
VideoQualityModes,
SortOrderType,
ForumLayoutType,
} from './enums';
import {
RawActivityData,
@@ -442,7 +444,7 @@ export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel) {
public defaultAutoArchiveDuration?: ThreadAutoArchiveDuration;
public rateLimitPerUser: number | null;
public nsfw: boolean;
public threads: ThreadManager<AllowedThreadTypeForTextChannel | AllowedThreadTypeForNewsChannel>;
public threads: GuildTextThreadManager<AllowedThreadTypeForTextChannel | AllowedThreadTypeForNewsChannel>;
public topic: string | null;
public createInvite(options?: CreateInviteOptions): Promise<Invite>;
public fetchInvites(cache?: boolean): Promise<Collection<string, Invite>>;
@@ -525,6 +527,7 @@ export type MappedChannelCategoryTypes = EnumValueMapped<
GUILD_TEXT: TextChannel;
GUILD_STORE: StoreChannel;
GUILD_STAGE_VOICE: StageChannel;
GUILD_FORUM: ForumChannel;
}
>;
@@ -567,6 +570,7 @@ export abstract class Channel extends Base {
public id: Snowflake;
public readonly partial: false;
public type: keyof typeof ChannelTypes;
public flags: Readonly<ChannelFlags> | null;
public delete(): Promise<this>;
public fetch(force?: boolean): Promise<this>;
public isText(): this is TextBasedChannel;
@@ -701,6 +705,14 @@ export interface CollectorEventTypes<K, V, F extends unknown[] = []> {
end: [collected: Collection<K, V>, reason: string];
}
export type ChannelFlagsString =
| 'PINNED'
| 'REQUIRE_TAG';
export class ChannelFlags extends BitField<ChannelFlagsString> {
public static FLAGS: Record<ChannelFlagsString, number>;
public static resolve(bit?: BitFieldResolvable<ChannelFlagsString, number>): number;
}
export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmitter {
protected constructor(client: Client, options?: CollectorOptions<[V, ...F]>);
private _timeout: NodeJS.Timeout | null;
@@ -907,6 +919,7 @@ export class DMChannel extends TextBasedChannelMixin(Channel, [
private constructor(client: Client, data?: RawDMChannelData);
public recipient: User;
public type: 'DM';
public flags: Readonly<ChannelFlags>;
public fetch(force?: boolean): Promise<this>;
}
@@ -978,7 +991,7 @@ export class Guild extends AnonymousGuild {
public vanityURLUses: number | null;
public readonly voiceAdapterCreator: InternalDiscordGatewayAdapterCreator;
public readonly voiceStates: VoiceStateManager;
public readonly widgetChannel: TextChannel | null;
public readonly widgetChannel: TextChannel | NewsChannel | VoiceBasedChannel | ForumChannel | null;
public widgetChannelId: Snowflake | null;
public widgetEnabled: boolean | null;
public readonly maximumBitrate: number;
@@ -1111,6 +1124,7 @@ export abstract class GuildChannel extends Channel {
public readonly position: number;
public rawPosition: number;
public type: Exclude<keyof typeof ChannelTypes, 'DM' | 'GROUP_DM' | 'UNKNOWN'>;
public flags: Readonly<ChannelFlags>;
public readonly viewable: boolean;
public clone(options?: GuildChannelCloneOptions): Promise<this>;
public delete(reason?: string): Promise<this>;
@@ -1593,6 +1607,7 @@ export class Message<Cached extends boolean = boolean> extends Base {
public webhookId: Snowflake | null;
public flags: Readonly<MessageFlags>;
public reference: MessageReference | null;
public position: number | null;
public awaitMessageComponent<T extends MessageComponentTypeResolvable = 'ACTION_ROW'>(
options?: AwaitMessageCollectorOptionsParams<T, Cached>,
): Promise<MappedInteractionTypes<Cached>[T]>;
@@ -1972,7 +1987,7 @@ export class ModalSubmitInteraction<Cached extends CacheType = CacheType> extend
}
export class NewsChannel extends BaseGuildTextChannel {
public threads: ThreadManager<AllowedThreadTypeForNewsChannel>;
public threads: GuildTextThreadManager<AllowedThreadTypeForNewsChannel>;
public type: 'GUILD_NEWS';
public addFollower(channel: TextChannelResolvable, reason?: string): Promise<NewsChannel>;
}
@@ -1987,6 +2002,7 @@ export class PartialGroupDMChannel extends Channel {
private constructor(client: Client, data: RawPartialGroupDMChannelData);
public name: string | null;
public icon: string | null;
public flags: null;
public recipients: PartialRecipient[];
public iconURL(options?: StaticImageURLOptions): string | null;
}
@@ -2273,7 +2289,9 @@ export class StageChannel extends BaseGuildVoiceChannel {
public setTopic(topic: string): Promise<StageChannel>;
}
export class DirectoryChannel extends Channel {}
export class DirectoryChannel extends Channel {
public flags: Readonly<ChannelFlags>;
}
export class StageInstance extends Base {
private constructor(client: Client, data: RawStageInstanceData, channel: StageChannel);
@@ -2447,10 +2465,65 @@ export class TeamMember extends Base {
export class TextChannel extends BaseGuildTextChannel {
public rateLimitPerUser: number;
public threads: ThreadManager<AllowedThreadTypeForTextChannel>;
public threads: GuildTextThreadManager<AllowedThreadTypeForTextChannel>;
public type: 'GUILD_TEXT';
}
export interface GuildForumTagEmoji {
id: Snowflake | null;
name: string | null;
}
export interface GuildForumTag {
id: Snowflake;
name: string;
moderated: boolean;
emoji: GuildForumTagEmoji | null;
}
export type GuildForumTagData = Partial<GuildForumTag> & { name: string };
export interface DefaultReactionEmoji {
id: Snowflake | null;
name: string | null;
}
export class ForumChannel extends TextBasedChannelMixin(GuildChannel, [
'send',
'lastMessage',
'lastPinAt',
'bulkDelete',
'sendTyping',
'createMessageCollector',
'awaitMessages',
'createMessageComponentCollector',
'awaitMessageComponent',
]) {
public type: 'GUILD_FORUM';
public threads: GuildForumThreadManager;
public availableTags: GuildForumTag[];
public defaultReactionEmoji: DefaultReactionEmoji | null;
public defaultThreadRateLimitPerUser: number | null;
public rateLimitPerUser: number | null;
public defaultAutoArchiveDuration: ThreadAutoArchiveDuration | null;
public nsfw: boolean;
public topic: string | null;
public defaultSortOrder: SortOrderType | null;
public defaultForumLayout: ForumLayoutType;
public setAvailableTags(tags: GuildForumTagData[], reason?: string): Promise<this>;
public setDefaultReactionEmoji(emojiId: DefaultReactionEmoji | null, reason?: string): Promise<this>;
public setDefaultThreadRateLimitPerUser(rateLimit: number, reason?: string): Promise<this>;
public createInvite(options?: CreateInviteOptions): Promise<Invite>;
public fetchInvites(cache?: boolean): Promise<Collection<string, Invite>>;
public setDefaultAutoArchiveDuration(
defaultAutoArchiveDuration: ThreadAutoArchiveDuration,
reason?: string,
): Promise<this>;
public setTopic(topic: string | null, reason?: string): Promise<this>;
public setDefaultSortOrder(defaultSortOrder: SortOrderType | null, reason?: string): Promise<this>;
public setDefaultForumLayout(defaultForumLayout: ForumLayoutType, reason?: string): Promise<this>;
}
export class TextInputComponent extends BaseMessageComponent {
public constructor(data?: TextInputComponent | TextInputComponentOptions);
public customId: string | null;
@@ -2498,10 +2571,13 @@ export class ThreadChannel extends TextBasedChannelMixin(Channel, ['fetchWebhook
public members: ThreadMemberManager;
public name: string;
public ownerId: Snowflake | null;
public readonly parent: TextChannel | NewsChannel | null;
public readonly parent: TextChannel | NewsChannel | ForumChannel | null;
public parentId: Snowflake | null;
public rateLimitPerUser: number | null;
public type: ThreadChannelTypes;
public flags: Readonly<ChannelFlags>;
public appliedTags: Snowflake[];
public totalMessageSent: number | null;
public readonly unarchivable: boolean;
public isPrivate(): this is this & {
readonly createdTimestamp: number;
@@ -2527,6 +2603,9 @@ export class ThreadChannel extends TextBasedChannelMixin(Channel, ['fetchWebhook
public setInvitable(invitable?: boolean, reason?: string): Promise<ThreadChannel>;
public setLocked(locked?: boolean, reason?: string): Promise<ThreadChannel>;
public setName(name: string, reason?: string): Promise<ThreadChannel>;
public setAppliedTags(appliedTags: Snowflake[], reason?: string): Promise<ThreadChannel>;
public pin(reason?: string): Promise<ThreadChannel>;
public unpin(reason?: string): Promise<ThreadChannel>;
}
export class ThreadMember extends Base {
@@ -2652,6 +2731,7 @@ export class Util extends null {
): Promise<{ id: Snowflake; position: number }[]>;
/** @deprecated This will be removed in the next major version. */
public static splitMessage(text: string, options?: SplitOptions): string[];
/** @deprecated This will be removed in the next major version. */
public static resolveAutoArchiveMaxLimit(guild: Guild): Exclude<ThreadAutoArchiveDuration, 60>;
}
@@ -2893,7 +2973,7 @@ export class WelcomeChannel extends Base {
public channelId: Snowflake;
public guild: Guild | InviteGuild;
public description: string;
public readonly channel: TextChannel | NewsChannel | StoreChannel | null;
public readonly channel: TextChannel | NewsChannel | StoreChannel | ForumChannel | null;
public readonly emoji: GuildEmoji | Emoji;
}
@@ -3479,16 +3559,23 @@ export class StageInstanceManager extends CachedManager<Snowflake, StageInstance
public delete(channel: StageChannelResolvable): Promise<void>;
}
export class ThreadManager<AllowedThreadType> extends CachedManager<Snowflake, ThreadChannel, ThreadChannelResolvable> {
private constructor(channel: TextChannel | NewsChannel, iterable?: Iterable<RawThreadChannelData>);
export class ThreadManager extends CachedManager<Snowflake, ThreadChannel, ThreadChannelResolvable> {
protected constructor(channel: TextChannel | NewsChannel, iterable?: Iterable<RawThreadChannelData>);
public channel: TextChannel | NewsChannel;
public create(options: ThreadCreateOptions<AllowedThreadType>): Promise<ThreadChannel>;
public fetch(options: ThreadChannelResolvable, cacheOptions?: BaseFetchOptions): Promise<ThreadChannel | null>;
public fetch(options?: FetchThreadsOptions, cacheOptions?: { cache?: boolean }): Promise<FetchedThreads>;
public fetchArchived(options?: FetchArchivedThreadOptions, cache?: boolean): Promise<FetchedThreads>;
public fetchActive(cache?: boolean): Promise<FetchedThreads>;
}
export class GuildTextThreadManager<AllowedThreadType> extends ThreadManager {
public create(options: GuildTextThreadCreateOptions<AllowedThreadType>): Promise<ThreadChannel>;
}
export class GuildForumThreadManager extends ThreadManager {
public create(options: GuildForumThreadCreateOptions): Promise<ThreadChannel>;
}
export class ThreadMemberManager extends CachedManager<Snowflake, ThreadMember, ThreadMemberResolvable> {
private constructor(thread: ThreadChannel, iterable?: Iterable<RawThreadMemberData>);
public thread: ThreadChannel;
@@ -4111,7 +4198,6 @@ export type CacheWithLimitsOptions = {
? LimitedCollectionOptions<K, V> | number
: never;
};
export interface CategoryCreateChannelOptions {
permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
topic?: string;
@@ -4131,6 +4217,11 @@ export interface CategoryCreateChannelOptions {
rateLimitPerUser?: number;
position?: number;
rtcRegion?: string;
videoQualityMode?: VideoQualityMode;
availableTags?: GuildForumTagData[];
defaultReactionEmoji?: DefaultReactionEmoji;
defaultSortOrder?: SortOrderType;
defaultForumLayout?: ForumLayoutType;
reason?: string;
}
@@ -4155,6 +4246,12 @@ export interface ChannelData {
defaultAutoArchiveDuration?: ThreadAutoArchiveDuration | 'MAX';
rtcRegion?: string | null;
videoQualityMode?: VideoQualityMode | null;
availableTags?: GuildForumTagData[];
defaultReactionEmoji?: DefaultReactionEmoji;
defaultThreadRateLimitPerUser?: number;
defaultSortOrder?: SortOrderType | null;
defaultForumLayout?: ForumLayoutType;
flags?: ChannelFlagsResolvable;
}
export interface ChannelLogsQueryOptions {
@@ -4258,7 +4355,7 @@ export interface ClientEvents extends BaseClientEvents {
typingStart: [typing: Typing];
userUpdate: [oldUser: User | PartialUser, newUser: User];
voiceStateUpdate: [oldState: VoiceState, newState: VoiceState];
webhookUpdate: [channel: TextChannel | NewsChannel | VoiceChannel];
webhookUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel];
/** @deprecated Use interactionCreate instead */
interaction: [interaction: Interaction];
interactionCreate: [interaction: Interaction];
@@ -5378,6 +5475,9 @@ export type MessageComponentType = keyof typeof MessageComponentTypes;
export type MessageComponentTypeResolvable = MessageComponentType | MessageComponentTypes;
export type GuildForumThreadMessageCreateOptions = MessageOptions &
Pick<MessageOptions, 'flags' | 'stickers'>;
export interface MessageEditOptions {
attachments?: MessageAttachment[];
content?: string | null;
@@ -5690,6 +5790,9 @@ export interface PartialChannelData {
videoQualityMode?: VideoQualityMode;
permissionOverwrites?: PartialOverwriteData[];
rateLimitPerUser?: number;
availableTags?: GuildForumTagData[];
defaultReactionEmoji?: DefaultReactionEmoji;
defaultThreadRateLimitPerUser?: number;
}
export type Partialize<
@@ -5863,6 +5966,8 @@ export type SystemChannelFlagsString =
export type SystemChannelFlagsResolvable = BitFieldResolvable<SystemChannelFlagsString, number>;
export type ChannelFlagsResolvable = BitFieldResolvable<ChannelFlagsString, number>;
export type SystemMessageType = Exclude<
MessageType,
'DEFAULT' | 'REPLY' | 'APPLICATION_COMMAND' | 'CONTEXT_MENU_COMMAND'
@@ -5935,9 +6040,10 @@ export type AnyChannel =
| StoreChannel
| TextChannel
| ThreadChannel
| VoiceChannel;
| VoiceChannel
| ForumChannel;
export type TextBasedChannel = Extract<AnyChannel, { messages: MessageManager }>;
export type TextBasedChannel = Exclude<Extract<AnyChannel, { messages: MessageManager }>, ForumChannel>;
export type TextBasedChannelTypes = TextBasedChannel['type'];
@@ -5966,7 +6072,7 @@ export type GuildBasedChannel = Extract<AnyChannel, { guild: Guild }>;
export type NonThreadGuildBasedChannel = Exclude<GuildBasedChannel, ThreadChannel>;
export type GuildTextBasedChannel = Extract<GuildBasedChannel, TextBasedChannel>;
export type GuildTextBasedChannel = Exclude<Extract<GuildBasedChannel, TextBasedChannel>, ForumChannel>;
export type TextChannelResolvable = Snowflake | TextChannel;
@@ -5978,13 +6084,18 @@ export type ThreadChannelResolvable = ThreadChannel | Snowflake;
export type ThreadChannelTypes = 'GUILD_NEWS_THREAD' | 'GUILD_PUBLIC_THREAD' | 'GUILD_PRIVATE_THREAD';
export interface ThreadCreateOptions<AllowedThreadType> extends StartThreadOptions {
export interface GuildTextThreadCreateOptions<AllowedThreadType> extends StartThreadOptions {
startMessage?: MessageResolvable;
type?: AllowedThreadType;
invitable?: AllowedThreadType extends 'GUILD_PRIVATE_THREAD' | 12 ? boolean : never;
rateLimitPerUser?: number;
}
export interface GuildForumThreadCreateOptions extends StartThreadOptions {
message: GuildForumThreadMessageCreateOptions | MessagePayload;
appliedTags?: Snowflake[];
}
export interface ThreadEditData {
name?: string;
archived?: boolean;
@@ -5992,6 +6103,8 @@ export interface ThreadEditData {
rateLimitPerUser?: number;
locked?: boolean;
invitable?: boolean;
threadName?: string;
flags?: ChannelFlagsResolvable;
}
export type ThreadMemberFlagsString = '';
@@ -6104,7 +6217,7 @@ export interface WidgetChannel {
export interface WelcomeChannelData {
description: string;
channel: TextChannel | NewsChannel | StoreChannel | Snowflake;
channel: TextChannel | NewsChannel | StoreChannel | ForumChannel | Snowflake;
emoji?: EmojiIdentifierResolvable;
}

View File

@@ -97,6 +97,7 @@ import {
InteractionResponseFields,
GuildBan,
GuildBanManager,
ForumChannel,
} from '.';
import type { ApplicationCommandOptionTypes } from './enums';
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
@@ -897,7 +898,7 @@ declare const categoryChannel: CategoryChannel;
declare const guildChannelManager: GuildChannelManager;
{
type AnyChannel = TextChannel | VoiceChannel | CategoryChannel | NewsChannel | StoreChannel | StageChannel;
type AnyChannel = TextChannel | VoiceChannel | CategoryChannel | NewsChannel | StoreChannel | StageChannel | ForumChannel;
expectType<Promise<TextChannel>>(guildChannelManager.create('name'));
expectType<Promise<TextChannel>>(guildChannelManager.create('name', {}));
@@ -1333,10 +1334,10 @@ expectType<
| 'GUILD_VOICE'
>(TextBasedChannelTypes);
expectType<StageChannel | VoiceChannel>(VoiceBasedChannel);
expectType<CategoryChannel | NewsChannel | StageChannel | StoreChannel | TextChannel | ThreadChannel | VoiceChannel>(
expectType<CategoryChannel | NewsChannel | StageChannel | StoreChannel | TextChannel | ThreadChannel | VoiceChannel | ForumChannel>(
GuildBasedChannel,
);
expectType<CategoryChannel | NewsChannel | StageChannel | StoreChannel | TextChannel | VoiceChannel>(
expectType<CategoryChannel | NewsChannel | StageChannel | StoreChannel | TextChannel | VoiceChannel | ForumChannel>(
NonThreadGuildBasedChannel,
);
expectType<NewsChannel | TextChannel | ThreadChannel | VoiceChannel>(GuildTextBasedChannel);