feat: add guild directory support (#6788)

This commit is contained in:
Suneet Tipirneni
2022-04-14 06:49:33 -04:00
committed by GitHub
parent fc2a8bb675
commit b01f4147d4
5 changed files with 43 additions and 6 deletions

View File

@@ -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",

View File

@@ -11,6 +11,7 @@ let StageChannel;
let TextChannel;
let ThreadChannel;
let VoiceChannel;
let DirectoryChannel;
/**
* Represents any channel on Discord.
@@ -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}
@@ -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) {
@@ -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);
}

View File

@@ -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;

View File

@@ -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<
@@ -692,6 +693,7 @@ export type CategoryChannelType = Exclude<
| ChannelType.GuildNewsThread
| ChannelType.GuildPrivateThread
| ChannelType.GuildCategory
| ChannelType.GuildDirectory
>;
export class CategoryChannel extends GuildChannel {
@@ -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;
@@ -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;