From 3fe7add2c5c07023d3cc83c06bba846c1328e446 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Thu, 27 May 2021 16:42:52 +0530 Subject: [PATCH] feat(Guild): add the new nsfw_level property (#5660) Co-authored-by: Jan <66554238+vaporox@users.noreply.github.com> Co-authored-by: Noel --- src/structures/Guild.js | 17 +++++++++-------- src/util/Constants.js | 10 ++++++++++ typings/index.d.ts | 12 +++++++++++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 43c0b08e4..80a2b0ea9 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -24,6 +24,7 @@ const { PartialTypes, VerificationLevels, ExplicitContentFilterLevels, + NSFWLevels, } = require('../util/Constants'); const DataResolver = require('../util/DataResolver'); const SnowflakeUtil = require('../util/SnowflakeUtil'); @@ -115,14 +116,6 @@ class Guild extends Base { * @type {number} */ this.shardID = data.shardID; - - if ('nsfw' in data) { - /** - * Whether the guild is designated as not safe for work - * @type {boolean} - */ - this.nsfw = data.nsfw; - } } /** @@ -176,6 +169,14 @@ class Guild extends Base { */ this.memberCount = data.member_count || this.memberCount; + if ('nsfw_level' in data) { + /** + * The NSFW level of this guild + * @type {NSFWLevel} + */ + this.nsfwLevel = NSFWLevels[data.nsfw_level]; + } + /** * Whether the guild is "large" (has more than large_threshold members, 50 by default) * @type {boolean} diff --git a/src/util/Constants.js b/src/util/Constants.js index 240292d77..7b1d94016 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -819,6 +819,16 @@ exports.InteractionResponseTypes = createEnum([ 'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE', ]); +/** + * NSFW level of a Guild + * * DEFAULT + * * EXPLICIT + * * SAFE + * * AGE_RESTRICTED + * @typedef {string} NSFWLevel + */ +exports.NSFWLevels = createEnum(['DEFAULT', 'EXPLICIT', 'SAFE', 'AGE_RESTRICTED']); + function keyMirror(arr) { let tmp = Object.create(null); for (const value of arr) tmp[value] = value; diff --git a/typings/index.d.ts b/typings/index.d.ts index 76e70ce84..ba64668da 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -37,6 +37,13 @@ declare enum InviteTargetType { EMBEDDED_APPLICATION = 2, } +declare enum NSFWLevels { + DEFAULT = 0, + EXPLICIT = 1, + SAFE = 2, + AGE_RESTRICTED = 3, +} + declare enum OverwriteTypes { role = 0, member = 1, @@ -647,6 +654,7 @@ declare module 'discord.js' { ApplicationCommandPermissionTypes: typeof ApplicationCommandPermissionTypes; InteractionTypes: typeof InteractionTypes; InteractionResponseTypes: typeof InteractionResponseTypes; + NSFWLevels: typeof NSFWLevels; }; export class DataResolver { @@ -731,7 +739,7 @@ declare module 'discord.js' { public mfaLevel: number; public name: string; public readonly nameAcronym: string; - public nsfw: boolean; + public nsfwLevel: NSFWLevel; public ownerID: Snowflake; public readonly partnered: boolean; public preferredLocale: string; @@ -3299,6 +3307,8 @@ declare module 'discord.js' { | 'REPLY' | 'APPLICATION_COMMAND'; + type NSFWLevel = keyof typeof NSFWLevels; + interface OverwriteData { allow?: PermissionResolvable; deny?: PermissionResolvable;