Skip to content

Commit

Permalink
feat: add guild directory support (#6788)
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Apr 14, 2022
1 parent fc2a8bb commit b01f414
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/discord.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@discordjs/rest": "workspace:^",
"@sapphire/snowflake": "^3.1.0",
"@types/ws": "^8.2.2",
"discord-api-types": "^0.31.0",
"discord-api-types": "^0.31.1",
"fast-deep-equal": "^3.1.3",
"lodash.snakecase": "^4.1.1",
"undici": "^4.14.1",
Expand Down
13 changes: 13 additions & 0 deletions packages/discord.js/src/structures/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let StageChannel;
let TextChannel;
let ThreadChannel;
let VoiceChannel;
let DirectoryChannel;

/**
* Represents any channel on Discord.
Expand Down Expand Up @@ -173,6 +174,14 @@ class Channel extends Base {
return this.type === ChannelType.GuildStageVoice;
}

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

/**
* Indicates whether this channel is {@link TextBasedChannels text-based}.
* @returns {boolean}
Expand Down Expand Up @@ -205,6 +214,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 @@ -246,6 +256,9 @@ class Channel extends Base {
if (!allowUnknownGuild) channel.parent?.threads.cache.set(channel.id, channel);
break;
}
case ChannelType.GuildDirectory:
channel = new DirectoryChannel(client, data);
break;
}
if (channel && !allowUnknownGuild) guild.channels?.cache.set(channel.id, channel);
}
Expand Down
19 changes: 19 additions & 0 deletions packages/discord.js/src/structures/DirectoryChannel.js
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ export interface MappedChannelCategoryTypes {
[ChannelType.GuildVoice]: VoiceChannel;
[ChannelType.GuildText]: TextChannel;
[ChannelType.GuildStageVoice]: StageChannel;
[ChannelType.GuildForum]: never; // TODO: Fix when guild forums come out
}

export type CategoryChannelType = Exclude<
Expand All @@ -692,6 +693,7 @@ export type CategoryChannelType = Exclude<
| ChannelType.GuildNewsThread
| ChannelType.GuildPrivateThread
| ChannelType.GuildCategory
| ChannelType.GuildDirectory
>;

export class CategoryChannel extends GuildChannel {
Expand Down Expand Up @@ -719,6 +721,7 @@ export abstract class Channel extends Base {
public isNews(): this is NewsChannel;
public isThread(): this is ThreadChannel;
public isStage(): this is StageChannel;
public isDirectory(): this is DirectoryChannel;
public isTextBased(): this is TextBasedChannel;
public isDMBased(): this is PartialGroupDMChannel | DMChannel | PartialDMChannel;
public isVoiceBased(): this is VoiceBasedChannel;
Expand Down Expand Up @@ -2218,6 +2221,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
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4429,10 +4429,10 @@ __metadata:
languageName: node
linkType: hard

"discord-api-types@npm:^0.31.0":
version: 0.31.0
resolution: "discord-api-types@npm:0.31.0"
checksum: 7ac466df8f3b62ebfa18296ef8cbf7a35ae295b775184b01f4357409cff89aa4e85a67e7fb3363b4a4ff796ff7313865e0266706b3d7908ef2238147a196a806
"discord-api-types@npm:^0.31.1":
version: 0.31.1
resolution: "discord-api-types@npm:0.31.1"
checksum: 5a18e512b549b75d55892b0dbc2dc7c46526bee0d001b73d41d144f4653de847c96b9c57342a32479af738f46acd80ee21686dced9fe0184dcac86b669b31f18
languageName: node
linkType: hard

Expand All @@ -4447,7 +4447,7 @@ __metadata:
"@sapphire/snowflake": ^3.1.0
"@types/node": ^16.11.24
"@types/ws": ^8.2.2
discord-api-types: ^0.31.0
discord-api-types: ^0.31.1
dtslint: ^4.2.1
eslint: ^8.9.0
eslint-config-prettier: ^8.3.0
Expand Down

0 comments on commit b01f414

Please sign in to comment.