Skip to content

Commit

Permalink
feat: support GUILD_MEDIA channels (#96)
Browse files Browse the repository at this point in the history
* feat: support GUILD_MEDIA channels

Ref: discord/discord-api-docs@107de2d

* correct the word order

* add MediaChannel to package exports

* consistency - extract ForumChannel type into a type alias

* add missing intellisense hints to createChannel
  • Loading branch information
TTtie authored Aug 8, 2023
1 parent 5dc06e5 commit 1dab74a
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 16 deletions.
1 change: 1 addition & 0 deletions esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const {
GuildTemplate,
Interaction,
Invite,
MediaChannel,
Member,
Message,
ModalSubmitInteraction,
Expand Down
31 changes: 26 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ declare namespace Dysnomia {
type TextChannelTypes = GuildTextChannelTypes | PrivateChannelTypes;
type GuildTextChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "GUILD_TEXT" | "GUILD_ANNOUNCEMENT">];
type GuildThreadChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "ANNOUNCEMENT_THREAD" | "PRIVATE_THREAD" | "PUBLIC_THREAD">];
type GuildThreadOnlyChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "GUILD_FORUM" | "GUILD_MEDIA">];
type GuildPublicThreadChannelTypes = Exclude<GuildThreadChannelTypes, Constants["ChannelTypes"]["PRIVATE_THREAD"]>;
type GuildVoiceChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "GUILD_VOICE" | "GUILD_STAGE_VOICE">];
type PrivateChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "DM" | "GROUP_DM">];
Expand Down Expand Up @@ -1952,10 +1953,12 @@ declare namespace Dysnomia {
GUILD_STAGE_VOICE: 13;
GUILD_DIRECTORY: 14;
GUILD_FORUM: 15;
GUILD_MEDIA: 16;
};
ChannelFlags: {
PINNED: 2;
REQUIRE_TAG: 16;
PINNED: 2;
REQUIRE_TAG: 16;
HIDE_MEDIA_DOWNLOAD_OPTIONS: 32768;
};
ComponentTypes: {
ACTION_ROW: 1;
Expand Down Expand Up @@ -2548,6 +2551,18 @@ declare namespace Dysnomia {
type: Constants["ChannelTypes"]["GUILD_STAGE_VOICE"],
options?: CreateChannelOptions
): Promise<StageChannel>;
createChannel(
guildID: string,
name: string,
type: Constants["ChannelTypes"]["GUILD_FORUM"],
options?: CreateChannelOptions
): Promise<ForumChannel>;
createChannel(
guildID: string,
name: string,
type: Constants["ChannelTypes"]["GUILD_MEDIA"],
options?: CreateChannelOptions
): Promise<MediaChannel>;
createChannel(
guildID: string,
name: string,
Expand Down Expand Up @@ -2855,7 +2870,7 @@ declare namespace Dysnomia {
permissionOverwrites: Collection<PermissionOverwrite>;
rateLimitPerUser: number;
topic?: string | null;
type: Constants["ChannelTypes"]["GUILD_FORUM"];
type: GuildThreadOnlyChannelTypes;
createInvite(options?: CreateInviteOptions, reason?: string): Promise<Invite<"withMetadata", this>>;
createThread(options: CreateThreadWithoutMessageOptions): Promise<PublicThreadChannel>;
createWebhook(options: Omit<WebhookOptions, "channelID">, reason?: string): Promise<Webhook>;
Expand Down Expand Up @@ -2930,8 +2945,10 @@ declare namespace Dysnomia {
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_TEXT"], options?: CreateChannelOptions): Promise<TextChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_VOICE"], options?: CreateChannelOptions): Promise<TextVoiceChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_CATEGORY"], options?: CreateChannelOptions): Promise<CategoryChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_ANNOUNCEMENT"], options?: CreateChannelOptions | string): Promise<NewsChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_STAGE_VOICE"], options?: CreateChannelOptions | string): Promise<StageChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_ANNOUNCEMENT"], options?: CreateChannelOptions): Promise<NewsChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_STAGE_VOICE"], options?: CreateChannelOptions): Promise<StageChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_FORUM"], options: CreateChannelOptions): Promise<ForumChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_MEDIA"], options: CreateChannelOptions): Promise<MediaChannel>;
createChannel(name: string, type?: number, options?: CreateChannelOptions): Promise<unknown>;
createCommand<T extends ApplicationCommandStructure>(command: T): Promise<ApplicationCommandStructureConversion<T, true>>;
createEmoji(options: { image: string; name: string; roles?: string[] }, reason?: string): Promise<Emoji>;
Expand Down Expand Up @@ -3244,6 +3261,10 @@ declare namespace Dysnomia {
unban(reason?: string): Promise<void>;
}

export class MediaChannel extends ForumChannel {
type: Constants["ChannelTypes"]["GUILD_MEDIA"];
}

export class Message<T extends PossiblyUncachedTextable = TextableChannel> extends Base {
activity?: MessageActivity;
application?: MessageApplication;
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Dysnomia.GuildScheduledEvent = require("./lib/structures/GuildScheduledEvent");
Dysnomia.GuildTemplate = require("./lib/structures/GuildTemplate");
Dysnomia.Interaction = require("./lib/structures/Interaction");
Dysnomia.Invite = require("./lib/structures/Invite");
Dysnomia.MediaChannel = require("./lib/structures/MediaChannel");
Dysnomia.Member = require("./lib/structures/Member");
Dysnomia.Message = require("./lib/structures/Message");
Dysnomia.ModalSubmitInteraction = require("./lib/structures/ModalSubmitInteraction.js");
Expand Down
6 changes: 3 additions & 3 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,9 @@ class Client extends EventEmitter {
* @arg {String} channelID The ID of the channel
* @arg {Object} options The thread options
* @arg {Number} [options.autoArchiveDuration] Duration in minutes to automatically archive the thread after recent activity, either 60, 1440, 4320 or 10080
* @arg {Array<String>} [options.appliedTags] The tags to apply to the thread (available only for threads created in a `GUILD_FORUM` channel)
* @arg {Array<String>} [options.appliedTags] The tags to apply to the thread (available only in threads in thread-only channels)
* @arg {Boolean} [options.invitable] Whether non-moderators can add other non-moderators to the thread (private threads only)
* @arg {Object} [options.message] The message to attach to the thread (set only if creating a thread in a `GUILD_FORUM` channel)
* @arg {Object} [options.message] The message to attach to the thread (set only if creating a thread in a thread-only channel)
* @arg {Object} [options.message.allowedMentions] A list of mentions to allow (overrides default)
* @arg {Boolean} [options.message.allowedMentions.everyone] Whether or not to allow @everyone/@here.
* @arg {Boolean | Array<String>} [options.message.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow.
Expand Down Expand Up @@ -1184,7 +1184,7 @@ class Client extends EventEmitter {
* @arg {String} channelID The ID of the channel
* @arg {Object} options The properties to edit
* @arg {Boolean} [options.archived] The archive status of the channel (thread channels only)
* @arg {Array<String>} [options.appliedTags] An array of applied tag IDs for the thread (available in `GUILD_FORUM` threads only)
* @arg {Array<String>} [options.appliedTags] An array of applied tag IDs for the thread (available only in threads in thread-only channels)
* @arg {Number} [options.autoArchiveDuration] The duration in minutes to automatically archive the thread after recent activity, either 60, 1440, 4320 or 10080 (thread channels only)
* @arg {Array<Object>} [options.availableTags] Available tags for a forum channel
* @arg {Number} [options.bitrate] The bitrate of the channel (guild voice channels only)
Expand Down
8 changes: 5 additions & 3 deletions lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ module.exports.ButtonStyles = {
};

module.exports.ChannelFlags = {
PINNED: 1 << 1,
REQUIRE_TAG: 1 << 4
PINNED: 1 << 1,
REQUIRE_TAG: 1 << 4,
HIDE_MEDIA_DOWNLOAD_OPTIONS: 1 << 15
};

module.exports.ChannelTypes = {
Expand All @@ -197,7 +198,8 @@ module.exports.ChannelTypes = {
PRIVATE_THREAD: 12,
GUILD_STAGE_VOICE: 13,
GUILD_DIRECTORY: 14,
GUILD_FORUM: 15
GUILD_FORUM: 15,
GUILD_MEDIA: 16
};

module.exports.ComponentTypes = {
Expand Down
5 changes: 3 additions & 2 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const GuildScheduledEvent = require("../structures/GuildScheduledEvent");
const GuildAuditLogEntry = require("../structures/GuildAuditLogEntry");
const AutoModerationRule = require("../structures/AutoModerationRule");
const GuildIntegration = require("../structures/GuildIntegration");
const ForumChannel = require("../structures/ForumChannel");

const WebSocket = typeof window !== "undefined" ? require("../util/BrowserWebSocket") : require("ws");

Expand Down Expand Up @@ -1831,7 +1832,7 @@ class Shard extends EventEmitter {
break;
}
const parent = this.client.getChannel(packet.d.parent_id);
if(parent?.type === ChannelTypes.GUILD_FORUM) {
if(parent instanceof ForumChannel) {
parent.lastThreadID = packet.d.id;
}

Expand Down Expand Up @@ -1871,7 +1872,7 @@ class Shard extends EventEmitter {
* @event Client#threadUpdate
* @prop {NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel} channel The updated channel
* @prop {Object?} oldChannel The old thread channel. This will be null if the channel was uncached
* @prop {Array<String>?} oldChannel.appliedTags An array of applied tag IDs for the thread (available in `GUILD_FORUM` threads only)
* @prop {Array<String>?} oldChannel.appliedTags An array of applied tag IDs for the thread (available only in threads in thread-only channels)
* @prop {Number?} oldChannel.flags The flags of the channel
* @prop {String} oldChannel.name The name of the channel
* @prop {Number} oldChannel.rateLimitPerUser The ratelimit of the channel, in seconds. 0 means no ratelimit is enabled
Expand Down
4 changes: 4 additions & 0 deletions lib/structures/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Channel extends Base {
case ChannelTypes.GUILD_FORUM: {
return new ForumChannel(data, client);
}
case ChannelTypes.GUILD_MEDIA: {
return new MediaChannel(data, client);
}
}
if(data.guild_id) {
if(data.last_message_id !== undefined) {
Expand Down Expand Up @@ -81,6 +84,7 @@ module.exports = Channel;
const CategoryChannel = require("./CategoryChannel");
const ForumChannel = require("./ForumChannel");
const GuildChannel = require("./GuildChannel");
const MediaChannel = require("./MediaChannel");
const NewsChannel = require("./NewsChannel");
const NewsThreadChannel = require("./NewsThreadChannel");
const PrivateChannel = require("./PrivateChannel");
Expand Down
2 changes: 1 addition & 1 deletion lib/structures/ForumChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ForumChannel extends GuildChannel {
* @arg {Number} [options.autoArchiveDuration] Duration in minutes to automatically archive the thread after recent activity, either 60, 1440, 4320 or 10080
* @arg {Array<String>} [options.appliedTags] The tags to apply to the thread
* @arg {String} options.name The thread channel name
* @arg {Object} options.message The message to attach to the thread (set only if creating a thread in a `GUILD_FORUM` channel)
* @arg {Object} options.message The message to attach to the thread (set only if creating a thread in a thread-only channel)
* @arg {Object} [options.message.allowedMentions] A list of mentions to allow (overrides default)
* @arg {Boolean} [options.message.allowedMentions.everyone] Whether or not to allow @everyone/@here.
* @arg {Boolean | Array<String>} [options.message.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow.
Expand Down
2 changes: 1 addition & 1 deletion lib/structures/GuildChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class GuildChannel extends Channel {
* Edit the channel's properties
* @arg {Object} options The properties to edit
* @arg {Boolean} [options.archived] The archive status of the channel (thread channels only)
* @arg {Array<String>} [options.appliedTags] An array of applied tag IDs for the thread (available in `GUILD_FORUM` threads only)
* @arg {Array<String>} [options.appliedTags] An array of applied tag IDs for the thread (available only in threads in thread-only channels)
* @arg {Number} [options.autoArchiveDuration] The duration in minutes to automatically archive the thread after recent activity, either 60, 1440, 4320 or 10080 (thread channels only)
* @arg {Array<Object>} [options.availableTags] Available tags for a forum channel
* @arg {Number} [options.bitrate] The bitrate of the channel (guild voice channels only)
Expand Down
11 changes: 11 additions & 0 deletions lib/structures/MediaChannel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";

const ForumChannel = require("./ForumChannel");

/**
* Represents a media channel. See ForumChannel for available properties and methods.
* @extends ForumChannel
*/
class MediaChannel extends ForumChannel {}

module.exports = MediaChannel;
2 changes: 1 addition & 1 deletion lib/structures/PublicThreadChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const ThreadChannel = require("./ThreadChannel");
/**
* Represents a public thread channel. See ThreadChannel for extra properties.
* @extends ThreadChannel
* @prop {Array<String>} appliedTags An array of applied tag IDs for the thread (available in `GUILD_FORUM` threads only)
* @prop {Array<String>} appliedTags An array of applied tag IDs for the thread (available only in threads in thread-only channels)
*/
class PublicThreadChannel extends ThreadChannel {
constructor(data, client, messageLimit) {
Expand Down

0 comments on commit 1dab74a

Please sign in to comment.