Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add guild directory support (v13) #7777

Merged
merged 1 commit into from Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/structures/Channel.js
Expand Up @@ -10,6 +10,7 @@ let StoreChannel;
let TextChannel;
let ThreadChannel;
let VoiceChannel;
let DirectoryChannel;
const { ChannelTypes, ThreadChannelTypes, VoiceBasedChannelTypes } = require('../util/Constants');
const SnowflakeUtil = require('../util/SnowflakeUtil');

Expand Down Expand Up @@ -164,6 +165,14 @@ class Channel extends Base {
return ThreadChannelTypes.includes(this.type);
}

/**
* Indicates whether this channel is a {@link DirectoryChannel}
* @returns {boolean}
*/
isDirectory() {
return this.type === 'GUILD_DIRECTORY';
}

static create(client, data, guild, { allowUnknownGuild, fromInteraction } = {}) {
CategoryChannel ??= require('./CategoryChannel');
DMChannel ??= require('./DMChannel');
Expand All @@ -173,6 +182,7 @@ class Channel extends Base {
TextChannel ??= require('./TextChannel');
ThreadChannel ??= require('./ThreadChannel');
VoiceChannel ??= require('./VoiceChannel');
DirectoryChannel ??= require('./DirectoryChannel');

let channel;
if (!data.guild_id && !guild) {
Expand Down Expand Up @@ -218,6 +228,10 @@ class Channel extends Base {
if (!allowUnknownGuild) channel.parent?.threads.cache.set(channel.id, channel);
break;
}

case ChannelTypes.GUILD_DIRECTORY:
channel = new DirectoryChannel(client, data);
break;
}
if (channel && !allowUnknownGuild) guild.channels?.cache.set(channel.id, channel);
}
Expand Down
19 changes: 19 additions & 0 deletions src/structures/DirectoryChannel.js
@@ -0,0 +1,19 @@
'use strict';

const { Channel } = require('./Channel');

/**
* Represents a channel that displays a directory of guilds
*/
class DirectoryChannel extends Channel {
_patch(data) {
super._patch(data);
/**
* The channel's name
* @type {string}
*/
this.name = data.name;
}
}

module.exports = DirectoryChannel;
2 changes: 2 additions & 0 deletions src/util/Constants.js
Expand Up @@ -529,6 +529,7 @@ exports.ActivityTypes = createEnum(['PLAYING', 'STREAMING', 'LISTENING', 'WATCHI
* * `GUILD_PUBLIC_THREAD` - a guild text channel's public thread channel
* * `GUILD_PRIVATE_THREAD` - a guild text channel's private thread channel
* * `GUILD_STAGE_VOICE` - a guild stage voice channel
* * `GUILD_DIRECTORY` - the channel in a hub containing guilds
* * `UNKNOWN` - a generic channel of unknown type, could be Channel or GuildChannel
* @typedef {string} ChannelType
* @see {@link https://discord.com/developers/docs/resources/channel#channel-object-channel-types}
Expand All @@ -547,6 +548,7 @@ exports.ChannelTypes = createEnum([
'GUILD_PUBLIC_THREAD',
'GUILD_PRIVATE_THREAD',
'GUILD_STAGE_VOICE',
'GUILD_DIRECTORY',
]);

/**
Expand Down
1 change: 1 addition & 0 deletions typings/enums.d.ts
Expand Up @@ -48,6 +48,7 @@ export const enum ChannelTypes {
GUILD_PUBLIC_THREAD = 11,
GUILD_PRIVATE_THREAD = 12,
GUILD_STAGE_VOICE = 13,
GUILD_DIRECTORY = 14,
}

export const enum MessageTypes {
Expand Down
4 changes: 4 additions & 0 deletions typings/index.d.ts
Expand Up @@ -522,6 +522,7 @@ export type CategoryChannelTypes = ExcludeEnum<
| 'GUILD_NEWS_THREAD'
| 'GUILD_PRIVATE_THREAD'
| 'GUILD_CATEGORY'
| 'GUILD_DIRECTORY'
>;

export class CategoryChannel extends GuildChannel {
Expand Down Expand Up @@ -556,6 +557,7 @@ export abstract class Channel extends Base {
public isText(): this is TextBasedChannel;
public isVoice(): this is BaseGuildVoiceChannel;
public isThread(): this is ThreadChannel;
public isDirectory(): this is DirectoryChannel;
public toString(): ChannelMention;
}

Expand Down Expand Up @@ -2236,6 +2238,8 @@ export class StageChannel extends BaseGuildVoiceChannel {
public setTopic(topic: string): Promise<StageChannel>;
}

export class DirectoryChannel extends Channel {}

export class StageInstance extends Base {
private constructor(client: Client, data: RawStageInstanceData, channel: StageChannel);
public id: Snowflake;
Expand Down