Skip to content

Commit

Permalink
feat(ForumChannels): Support Forum Channels (#1452)
Browse files Browse the repository at this point in the history
Co-authored-by: bsian03 <[email protected]>
  • Loading branch information
conorwastakenwastaken and bsian03 authored Feb 7, 2024
1 parent 8a2b212 commit 6084d6a
Show file tree
Hide file tree
Showing 17 changed files with 546 additions and 59 deletions.
1 change: 1 addition & 0 deletions esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const {
DiscordHTTPError,
DiscordRESTError,
ExtendedUser,
ForumChannel,
GroupChannel,
Guild,
GuildChannel,
Expand Down
122 changes: 105 additions & 17 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ declare namespace Eris {

// Channel
type AnyChannel = AnyGuildChannel | PrivateChannel;
type AnyGuildChannel = GuildTextableChannel | AnyVoiceChannel | CategoryChannel;
type AnyGuildChannel = GuildTextableChannel | AnyVoiceChannel | CategoryChannel | ForumChannel;
type AnyThreadChannel = NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel | ThreadChannel;
type AnyVoiceChannel = TextVoiceChannel | StageChannel;
type ChannelTypeConversion<T extends GuildChannelTypes> =
Expand All @@ -59,7 +59,8 @@ declare namespace Eris {
T extends Constants["ChannelTypes"]["GUILD_CATEGORY"] ? CategoryChannel :
T extends Constants["ChannelTypes"]["GUILD_NEWS"] ? NewsChannel :
T extends Constants["ChannelTypes"]["GUILD_STAGE_VOICE"] ? StageChannel :
never;
T extends Constants["ChannelTypes"]["GUILD_FORUM"] ? ForumChannel :
never;
type GuildTextableChannel = TextChannel | TextVoiceChannel | NewsChannel;
type GuildTextableWithThreads = GuildTextableChannel | AnyThreadChannel;
type InviteChannel = InvitePartialChannel | Exclude<AnyGuildChannel, CategoryChannel | AnyThreadChannel>;
Expand Down Expand Up @@ -170,8 +171,11 @@ declare namespace Eris {
type StickerFormats = Constants["StickerFormats"][keyof Constants["StickerFormats"]];
type StickerTypes = Constants["StickerTypes"][keyof Constants["StickerTypes"]];

// Thread
// Thread/Forum
type AutoArchiveDuration = 60 | 1440 | 4320 | 10080;
type ChannelFlags = Constants["ChannelFlags"][keyof Constants["ChannelFlags"]];
type ForumLayoutTypes = Constants["ForumLayoutTypes"][keyof Constants["ForumLayoutTypes"]];
type SortOrderTypes = Constants["SortOrderTypes"][keyof Constants["SortOrderTypes"]];

// User
type PremiumTypes = Constants["PremiumTypes"][keyof Constants["PremiumTypes"]];
Expand Down Expand Up @@ -347,6 +351,7 @@ declare namespace Eris {
/** valid for KEYWORD_PRESET */
presets: AutoModerationKeywordPresetType[];
}

// Channel
interface ChannelFollow {
channel_id: string;
Expand All @@ -359,7 +364,13 @@ declare namespace Eris {
position: number;
}
interface CreateChannelOptions {
availableTags?: ForumTag[];
bitrate?: number;
defaultAutoArchiveDuration?: AutoArchiveDuration;
defaultForumLayout?: ForumLayoutTypes;
defaultReactionEmoji?: DefaultReactionEmoji;
defaultSortOrder?: SortOrderTypes;
defaultThreadRateLimitPerUser?: number;
nsfw?: boolean;
parentID?: string;
permissionOverwrites?: Overwrite[];
Expand All @@ -370,9 +381,16 @@ declare namespace Eris {
userLimit?: number;
}
interface EditChannelOptions extends Omit<CreateChannelOptions, "reason"> {
appliedTags?: string[];
archived?: boolean;
autoArchiveDuration?: AutoArchiveDuration;
availableTags?: ForumTag[];
defaultAutoArchiveDuration?: AutoArchiveDuration;
defaultForumLayout?: ForumLayoutTypes;
defaultReactionEmoji?: DefaultReactionEmoji;
defaultSortOrder?: SortOrderTypes;
defaultThreadRateLimitPerUser?: number;
flags?: number;
icon?: string;
invitable?: boolean;
locked?: boolean;
Expand Down Expand Up @@ -673,6 +691,14 @@ declare namespace Eris {
ringing: string[];
unavailable: boolean;
}
interface OldForumChannel extends OldGuildChannel {
availableTags: ForumTag[];
defaultAutoArchiveDuration: AutoArchiveDuration;
defaultForumLayout: ForumLayoutTypes;
defaultReactionEmoji: DefaultReactionEmoji;
defaultSortOrder: SortOrderTypes;
defaultThreadRateLimitPerUser: number;
}
interface OldGroupChannel {
icon: string;
name: string;
Expand Down Expand Up @@ -720,6 +746,7 @@ declare namespace Eris {
}
interface OldGuildChannel {
bitrate?: number;
flags?: number;
name: string;
nsfw?: boolean;
parentID: string | null;
Expand Down Expand Up @@ -796,6 +823,8 @@ declare namespace Eris {
videoQualityMode: VideoQualityMode;
}
interface OldThread {
appliedTags: string[];
autoArchiveDuration: number;
name: string;
rateLimitPerUser: number;
threadMetadata: ThreadMetadata;
Expand Down Expand Up @@ -826,7 +855,7 @@ declare namespace Eris {
channelPinUpdate: [channel: TextableChannel, timestamp: number, oldTimestamp: number];
channelRecipientAdd: [channel: GroupChannel, user: User];
channelRecipientRemove: [channel: GroupChannel, user: User];
channelUpdate: [channel: AnyGuildChannel, oldChannel: OldGuildChannel | OldGuildTextChannel | OldVoiceChannel]
channelUpdate: [channel: AnyGuildChannel, oldChannel: OldGuildChannel | OldForumChannel | OldGuildTextChannel | OldVoiceChannel]
| [channel: GroupChannel, oldChannel: OldGroupChannel];
connect: [id: number];
debug: [message: string, id?: number];
Expand Down Expand Up @@ -1626,14 +1655,29 @@ declare namespace Eris {
guild_connections?: true;
}

// Thread
// Forum/Thread
interface CreateThreadOptions {
autoArchiveDuration: AutoArchiveDuration;
autoArchiveDuration?: AutoArchiveDuration;
name: string;
rateLimitPerUser?: number;
reason?: string;
}
interface CreateForumThreadOptions extends CreateThreadOptions {
appliedTags?: string[];
message: Omit<AdvancedMessageContent, "messageReference" | "messageReferenceID" | "tts"> & FileContent[];
}
interface CreateThreadWithoutMessageOptions<T = AnyThreadChannel["type"]> extends CreateThreadOptions {
invitable: T extends PrivateThreadChannel["type"] ? boolean : never;
type: T;
invitable?: T extends PrivateThreadChannel["type"] ? boolean : never;
type?: T;
}
interface DefaultReactionEmoji {
emoji_id?: string;
emoji_name?: string;
}
interface ForumTag extends DefaultReactionEmoji {
id: string;
name: string;
moderated: boolean;
}
interface GetArchivedThreadsOptions {
before?: Date;
Expand Down Expand Up @@ -1912,6 +1956,10 @@ declare namespace Eris {
DANGER: 4;
LINK: 5;
};
ChannelFlags: {
PINNED: 1,
REQUIRE_TAG: 16
},
ChannelTypes: {
GUILD_TEXT: 0;
DM: 1;
Expand All @@ -1926,6 +1974,8 @@ declare namespace Eris {
GUILD_STAGE_VOICE: 13;
/** @deprecated */
GUILD_STAGE: 13;

GUILD_FORUM: 15;
};
ComponentTypes: {
ACTION_ROW: 1;
Expand All @@ -1937,10 +1987,19 @@ declare namespace Eris {
NONE: 0;
EVERYONE: 1;
};
ForumLayoutTypes: {
NOT_SET: 0,
LIST_VIEW: 1,
GALLERY_VIEW: 2
};
DefaultMessageNotificationLevels: {
ALL_MESSAGES: 0;
ONLY_MENTIONS: 1;
};
SortOrderTypes: {
LATEST_ACTIVITY: 0,
CREATION_DATE: 1
};
ExplicitContentFilterLevels: {
DISABLED: 0;
MEMBERS_WITHOUT_ROLES: 1;
Expand Down Expand Up @@ -2645,7 +2704,7 @@ declare namespace Eris {
): Promise<Invite<"withoutCount">>;
createChannelWebhook(
channelID: string,
options: { name: string; avatar?: string | null },
options: WebhookCreateOptions,
reason?: string
): Promise<Webhook>;
createCommand<T extends ApplicationCommandTypes>(command: ApplicationCommandCreateOptions<false, T>): Promise<ApplicationCommand<false, T>>;
Expand All @@ -2661,8 +2720,11 @@ declare namespace Eris {
createMessage(channelID: string, content: MessageContent, file?: FileContent | FileContent[]): Promise<Message>;
createRole(guildID: string, options?: Role | RoleOptions, reason?: string): Promise<Role>;
createStageInstance(channelID: string, options: StageInstanceOptions): Promise<StageInstance>;
createThread(channelID: string, options: CreateForumThreadOptions, file?: FileContent | FileContent[]): Promise<PublicThreadChannel<true>>;
createThread(channelID: string, options: CreateThreadWithoutMessageOptions, file?: FileContent | FileContent[]): Promise<NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>;
createThreadWithMessage(channelID: string, messageID: string, options: CreateThreadOptions): Promise<NewsThreadChannel | PublicThreadChannel>;
createThreadWithoutMessage(channelID: string, options: CreateThreadWithoutMessageOptions): Promise<PrivateThreadChannel>;
/** @deprecated */
createThreadWithoutMessage(channelID: string, options: CreateThreadWithoutMessageOptions): Promise<NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>;
crosspostMessage(channelID: string, messageID: string): Promise<Message>;
deleteAutoModerationRule(guildID: string, ruleID: string, reason?: string): Promise<void>;
deleteChannel(channelID: string, reason?: string): Promise<void>;
Expand Down Expand Up @@ -2768,7 +2830,7 @@ declare namespace Eris {
followChannel(channelID: string, webhookChannelID: string): Promise<ChannelFollow>;
getActiveGuildThreads(guildID: string): Promise<ListedGuildThreads>;
getArchivedThreads(channelID: string, type: "private", options?: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PrivateThreadChannel>>;
getArchivedThreads(channelID: string, type: "public", options?: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PublicThreadChannel>>;
getArchivedThreads(channelID: string, type: "public", options?: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PublicThreadChannel<boolean>>>;
getAutoModerationRule(guildID: string, ruleID: string): Promise<AutoModerationRule>;
getAutoModerationRules(guildID: string): Promise<AutoModerationRule[]>;
getBotGateway(): Promise<{ session_start_limit: { max_concurrency: number; remaining: number; reset_after: number; total: number }; shards: number; url: string }>;
Expand Down Expand Up @@ -3029,6 +3091,25 @@ declare namespace Eris {
verified: boolean;
}

export class ForumChannel extends GuildChannel {
availableTags: ForumTag[];
defaultAutoArchiveDuration: AutoArchiveDuration;
defaultForumLayout: ForumLayoutTypes;
defaultReactionEmoji: DefaultReactionEmoji;
defaultSortOrder: SortOrderTypes;
defaultThreadRateLimitPerUser: number;
lastMessageID: string;
rateLimitPerUser: number;
threads: PublicThreadChannel<true>[];
topic?: string;
createInvite(options?: CreateInviteOptions, reason?: string): Promise<Invite<"withMetadata", this>>;
createThread(options: CreateForumThreadOptions, file?: FileContent | FileContent[]): Promise<PublicThreadChannel<true>>;
createWebhook(options: WebhookCreateOptions, reason?: string): Promise<Webhook>;
getArchivedThreads(options?: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PublicThreadChannel<true>>>;
getInvites(): Promise<Invite<"withMetadata", this>[]>;
getWebhooks(): Promise<Webhook[]>;
}

export class GroupChannel extends PrivateChannel {
icon: string | null;
iconURL: string | null;
Expand Down Expand Up @@ -3235,6 +3316,7 @@ declare namespace Eris {
export class GuildChannel extends Channel {
guild: Guild;
name: string;
flags?: number;
parentID: string | null;
permissionOverwrites: Collection<PermissionOverwrite>;
position: number;
Expand Down Expand Up @@ -3606,7 +3688,7 @@ declare namespace Eris {
crosspostMessage(messageID: string): Promise<Message<this>>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<this>>;
follow(webhookChannelID: string): Promise<ChannelFollow>;
getInvites(): Promise<(Invite<"withMetadata", this>)[]>;
getInvites(): Promise<Invite<"withMetadata", this>[]>;
getMessage(messageID: string): Promise<Message<this>>;
getMessages(options?: GetMessagesOptions): Promise<Message<this>[]>;
/** @deprecated */
Expand Down Expand Up @@ -3686,7 +3768,9 @@ declare namespace Eris {
type: Constants["ChannelTypes"]["GUILD_PRIVATE_THREAD"];
}

export class PublicThreadChannel extends ThreadChannel {
/** Generic T is true if the PublicThreadChannel's parent channel is a Forum Channel */
export class PublicThreadChannel<T = false> extends ThreadChannel {
appliedTags: T extends true ? string[] : never;
type: GuildPublicThreadChannelTypes;
edit(options: Pick<EditChannelOptions, "archived" | "autoArchiveDuration" | "locked" | "name" | "rateLimitPerUser">, reason?: string): Promise<this>;
}
Expand Down Expand Up @@ -3896,16 +3980,18 @@ declare namespace Eris {
addMessageReaction(messageID: string, reaction: string, userID: string): Promise<void>;
createInvite(options?: CreateInviteOptions, reason?: string): Promise<Invite<"withMetadata", this>>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<this>>;
createThreadWithMessage(messageID: string, options: CreateThreadOptions): Promise<PublicThreadChannel>;
createThreadWithoutMessage(options: CreateThreadWithoutMessageOptions): Promise<PrivateThreadChannel>;
createThread(options: CreateThreadWithoutMessageOptions): Promise<NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>;
createThreadWithMessage(messageID: string, options: CreateThreadOptions): Promise<NewsThreadChannel | PublicThreadChannel>;
/** @deprecated */
createThreadWithoutMessage(options: CreateThreadWithoutMessageOptions): Promise<NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>;
createWebhook(options: WebhookCreateOptions, reason?: string): Promise<Webhook>;
deleteMessage(messageID: string, reason?: string): Promise<void>;
deleteMessages(messageIDs: string[], reason?: string): Promise<void>;
edit(options: Omit<EditChannelOptions, "icon" | "ownerID">, reason?: string): Promise<this>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<this>>;
getArchivedThreads(type: "private", options?: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PrivateThreadChannel>>;
getArchivedThreads(type: "public", options?: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PublicThreadChannel>>;
getInvites(): Promise<(Invite<"withMetadata", this>)[]>;
getInvites(): Promise<Invite<"withMetadata", this>[]>;
getJoinedPrivateArchivedThreads(options: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PrivateThreadChannel>>;
getMessage(messageID: string): Promise<Message<this>>;
getMessageReaction(messageID: string, reaction: string, options?: GetMessageReactionOptions): Promise<User[]>;
Expand Down Expand Up @@ -3968,8 +4054,10 @@ declare namespace Eris {
messageCount: number;
messages: Collection<Message<this>>;
ownerID: string;
parentID: string;
rateLimitPerUser: number;
threadMetadata: ThreadMetadata;
totalMessageSent: number;
type: GuildThreadChannelTypes;
constructor(data: BaseData, client: Client, messageLimit?: number);
addMessageReaction(messageID: string, reaction: string): Promise<void>;
Expand Down Expand Up @@ -4054,7 +4142,7 @@ declare namespace Eris {
type: GuildVoiceChannelTypes;
voiceMembers: Collection<Member>;
createInvite(options?: CreateInviteOptions, reason?: string): Promise<Invite<"withMetadata", VoiceChannel>>;
getInvites(): Promise<(Invite<"withMetadata", VoiceChannel>)[]>;
getInvites(): Promise<Invite<"withMetadata", VoiceChannel>[]>;
join(options?: JoinVoiceChannelOptions): Promise<VoiceConnection>;
leave(): void;
}
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Eris.Constants = require("./lib/Constants");
Eris.DiscordHTTPError = require("./lib/errors/DiscordHTTPError");
Eris.DiscordRESTError = require("./lib/errors/DiscordRESTError");
Eris.ExtendedUser = require("./lib/structures/ExtendedUser");
Eris.ForumChannel = require("./lib/structures/ForumChannel");
Eris.GroupChannel = require("./lib/structures/GroupChannel");
Eris.Guild = require("./lib/structures/Guild");
Eris.GuildChannel = require("./lib/structures/GuildChannel");
Expand Down
Loading

0 comments on commit 6084d6a

Please sign in to comment.