Skip to content

Commit

Permalink
feat(Guild): add the new nsfw_level property (#5660)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan <[email protected]>
Co-authored-by: Noel <[email protected]>
  • Loading branch information
3 people authored May 27, 2021
1 parent b40027b commit 3fe7add
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const {
PartialTypes,
VerificationLevels,
ExplicitContentFilterLevels,
NSFWLevels,
} = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const SnowflakeUtil = require('../util/SnowflakeUtil');
Expand Down Expand Up @@ -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;
}
}

/**
Expand Down Expand Up @@ -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}
Expand Down
10 changes: 10 additions & 0 deletions src/util/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -647,6 +654,7 @@ declare module 'discord.js' {
ApplicationCommandPermissionTypes: typeof ApplicationCommandPermissionTypes;
InteractionTypes: typeof InteractionTypes;
InteractionResponseTypes: typeof InteractionResponseTypes;
NSFWLevels: typeof NSFWLevels;
};

export class DataResolver {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3299,6 +3307,8 @@ declare module 'discord.js' {
| 'REPLY'
| 'APPLICATION_COMMAND';

type NSFWLevel = keyof typeof NSFWLevels;

interface OverwriteData {
allow?: PermissionResolvable;
deny?: PermissionResolvable;
Expand Down

0 comments on commit 3fe7add

Please sign in to comment.