From ac71697a3a5ca8688987f6dbd68ac3e909fb60c8 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Sat, 22 May 2021 12:26:30 +0530 Subject: [PATCH 1/8] feat(Guild): add the new nsfw_level property --- src/structures/Guild.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 43c0b08e4573..b1a605f26bb3 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -116,12 +116,21 @@ class Guild extends Base { */ this.shardID = data.shardID; - if ('nsfw' in data) { + if ('nsfw_level' in data) { /** - * Whether the guild is designated as not safe for work - * @type {boolean} + * NSFW level of a Guild + * * 0: DEFAULT + * * 1: EXPLICIT + * * 2: SAFE + * * 3: AGE_RESTRICTED + * @typedef {number} NsfwLevel + */ + + /** + * The nsfw level of this guild + * @type {NsfwLevel} */ - this.nsfw = data.nsfw; + this.nsfwLevel = data.nsfw_level; } } From 1cfe09cc772cfd9222c3c650307a76b2a0683205 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Sat, 22 May 2021 12:38:48 +0530 Subject: [PATCH 2/8] types(Guild): add typings for nsfwLevel --- typings/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 0e574ac27145..bcee3345573e 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -732,7 +732,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; @@ -3294,6 +3294,8 @@ declare module 'discord.js' { type?: OverwriteType; } + type NsfwLevel = 0 | 1 | 2 | 3; + type OverwriteResolvable = PermissionOverwrites | OverwriteData; type OverwriteType = 'member' | 'role'; From 57556ca5835f2dc586539f6aa62efbd54c180f75 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Sat, 22 May 2021 12:44:21 +0530 Subject: [PATCH 3/8] feat(Constants): add an enum for NsfwLevel --- src/util/Constants.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/Constants.js b/src/util/Constants.js index 9d7aead77721..fe5ab4964b05 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -818,6 +818,8 @@ exports.InteractionResponseTypes = createEnum([ 'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE', ]); +exports.NsfwLevel = createEnum(['DEFAULT', 'EXPLICIT', 'SAFE', 'AGE_RESTRICTED']); + function keyMirror(arr) { let tmp = Object.create(null); for (const value of arr) tmp[value] = value; From 606376b258a888d9b3d96ca2f43464a875000da6 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Sat, 22 May 2021 13:14:16 +0530 Subject: [PATCH 4/8] refactor: use the new enum like other enums --- src/structures/Guild.js | 12 ++---------- src/util/Constants.js | 10 +++++++++- typings/index.d.ts | 8 ++++++++ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index b1a605f26bb3..6bf402a12fab 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'); @@ -117,20 +118,11 @@ class Guild extends Base { this.shardID = data.shardID; if ('nsfw_level' in data) { - /** - * NSFW level of a Guild - * * 0: DEFAULT - * * 1: EXPLICIT - * * 2: SAFE - * * 3: AGE_RESTRICTED - * @typedef {number} NsfwLevel - */ - /** * The nsfw level of this guild * @type {NsfwLevel} */ - this.nsfwLevel = data.nsfw_level; + this.nsfwLevel = NsfwLevels[data.nsfw_level]; } } diff --git a/src/util/Constants.js b/src/util/Constants.js index fe5ab4964b05..d5057bad355d 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -818,7 +818,15 @@ exports.InteractionResponseTypes = createEnum([ 'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE', ]); -exports.NsfwLevel = createEnum(['DEFAULT', 'EXPLICIT', 'SAFE', 'AGE_RESTRICTED']); +/** + * 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); diff --git a/typings/index.d.ts b/typings/index.d.ts index bcee3345573e..03f8e1ecdbf5 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, @@ -648,6 +655,7 @@ declare module 'discord.js' { ApplicationCommandPermissionTypes: typeof ApplicationCommandPermissionTypes; InteractionTypes: typeof InteractionTypes; InteractionResponseTypes: typeof InteractionResponseTypes; + NsfwLevels: typeof NsfwLevels; }; export class DataResolver { From 66f59a555ac3c0e56fc62353eaeaa4305a18dd31 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Sat, 22 May 2021 13:23:48 +0530 Subject: [PATCH 5/8] types: update typings for NsfwLevel --- typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 03f8e1ecdbf5..75527e7e7225 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3302,7 +3302,7 @@ declare module 'discord.js' { type?: OverwriteType; } - type NsfwLevel = 0 | 1 | 2 | 3; + type NsfwLevel = 'DEFAULT' | 'EXPLICIT' | 'SAFE' | 'AGE_RESTRICTED'; type OverwriteResolvable = PermissionOverwrites | OverwriteData; From 2493caf4f2059d85ab0edc2cc032496844efb2ba Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Sat, 22 May 2021 15:57:38 +0530 Subject: [PATCH 6/8] refactor(Guild): assign nsfw_level property inside #_patch --- src/structures/Guild.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 6bf402a12fab..55e7dd38c042 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -116,14 +116,6 @@ class Guild extends Base { * @type {number} */ this.shardID = data.shardID; - - if ('nsfw_level' in data) { - /** - * The nsfw level of this guild - * @type {NsfwLevel} - */ - this.nsfwLevel = NsfwLevels[data.nsfw_level]; - } } /** @@ -177,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} From 6e0e86ebb2cbdceb4b46b61a669a641e2f6b2f70 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Sat, 22 May 2021 19:02:14 +0530 Subject: [PATCH 7/8] refactor: add suggestions from the review Co-authored-by: Jan <66554238+vaporox@users.noreply.github.com> Co-authored-by: Noel --- src/structures/Guild.js | 4 ++-- src/util/Constants.js | 2 +- typings/index.d.ts | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 55e7dd38c042..0890b10d73c5 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -171,10 +171,10 @@ class Guild extends Base { if ('nsfw_level' in data) { /** - * The nsfw level of this guild + * The NSFW level of this guild * @type {NsfwLevel} */ - this.nsfwLevel = NsfwLevels[data.nsfw_level]; + this.nsfwLevel = NSFWLevels[data.nsfw_level]; } /** diff --git a/src/util/Constants.js b/src/util/Constants.js index d5057bad355d..404fc2bd9c6d 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -826,7 +826,7 @@ exports.InteractionResponseTypes = createEnum([ * * AGE_RESTRICTED * @typedef {string} NsfwLevel */ -exports.NsfwLevels = createEnum(['DEFAULT', 'EXPLICIT', 'SAFE', 'AGE_RESTRICTED']); +exports.NSFWLevels = createEnum(['DEFAULT', 'EXPLICIT', 'SAFE', 'AGE_RESTRICTED']); function keyMirror(arr) { let tmp = Object.create(null); diff --git a/typings/index.d.ts b/typings/index.d.ts index 75527e7e7225..cb0662f9d605 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -37,7 +37,7 @@ declare enum InviteTargetType { EMBEDDED_APPLICATION = 2, } -declare enum NsfwLevels { +declare enum NSFWLevels { DEFAULT = 0, EXPLICIT = 1, SAFE = 2, @@ -655,7 +655,7 @@ declare module 'discord.js' { ApplicationCommandPermissionTypes: typeof ApplicationCommandPermissionTypes; InteractionTypes: typeof InteractionTypes; InteractionResponseTypes: typeof InteractionResponseTypes; - NsfwLevels: typeof NsfwLevels; + NSFWLevels: typeof NSFWLevels; }; export class DataResolver { @@ -740,7 +740,7 @@ declare module 'discord.js' { public mfaLevel: number; public name: string; public readonly nameAcronym: string; - public nsfwLevel: NsfwLevel; + public nsfwLevel: NSFWLevel; public ownerID: Snowflake; public readonly partnered: boolean; public preferredLocale: string; @@ -3302,7 +3302,7 @@ declare module 'discord.js' { type?: OverwriteType; } - type NsfwLevel = 'DEFAULT' | 'EXPLICIT' | 'SAFE' | 'AGE_RESTRICTED'; + type NSFWLevel = keyof typeof NSFWLevels; type OverwriteResolvable = PermissionOverwrites | OverwriteData; From 3d496bacec0bf4627aa89a33eed49d341917fe1a Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Sat, 22 May 2021 19:11:20 +0530 Subject: [PATCH 8/8] fix: linter errors --- src/structures/Guild.js | 4 ++-- src/util/Constants.js | 2 +- typings/index.d.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 0890b10d73c5..80a2b0ea9b31 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -24,7 +24,7 @@ const { PartialTypes, VerificationLevels, ExplicitContentFilterLevels, - NsfwLevels, + NSFWLevels, } = require('../util/Constants'); const DataResolver = require('../util/DataResolver'); const SnowflakeUtil = require('../util/SnowflakeUtil'); @@ -172,7 +172,7 @@ class Guild extends Base { if ('nsfw_level' in data) { /** * The NSFW level of this guild - * @type {NsfwLevel} + * @type {NSFWLevel} */ this.nsfwLevel = NSFWLevels[data.nsfw_level]; } diff --git a/src/util/Constants.js b/src/util/Constants.js index 404fc2bd9c6d..ad980952dde6 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -824,7 +824,7 @@ exports.InteractionResponseTypes = createEnum([ * * EXPLICIT * * SAFE * * AGE_RESTRICTED - * @typedef {string} NsfwLevel + * @typedef {string} NSFWLevel */ exports.NSFWLevels = createEnum(['DEFAULT', 'EXPLICIT', 'SAFE', 'AGE_RESTRICTED']); diff --git a/typings/index.d.ts b/typings/index.d.ts index cb0662f9d605..7e05b3802aa5 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3295,6 +3295,8 @@ declare module 'discord.js' { | 'REPLY' | 'APPLICATION_COMMAND'; + type NSFWLevel = keyof typeof NSFWLevels; + interface OverwriteData { allow?: PermissionResolvable; deny?: PermissionResolvable; @@ -3302,8 +3304,6 @@ declare module 'discord.js' { type?: OverwriteType; } - type NSFWLevel = keyof typeof NSFWLevels; - type OverwriteResolvable = PermissionOverwrites | OverwriteData; type OverwriteType = 'member' | 'role';