feat(Guild): add the new nsfw_level property (#5660)

Co-authored-by: Jan <66554238+vaporox@users.noreply.github.com>
Co-authored-by: Noel <icrawltogo@gmail.com>
This commit is contained in:
Shubham Parihar
2021-05-27 16:42:52 +05:30
committed by GitHub
parent b40027beb9
commit 3fe7add2c5
3 changed files with 30 additions and 9 deletions

View File

@@ -24,6 +24,7 @@ const {
PartialTypes, PartialTypes,
VerificationLevels, VerificationLevels,
ExplicitContentFilterLevels, ExplicitContentFilterLevels,
NSFWLevels,
} = require('../util/Constants'); } = require('../util/Constants');
const DataResolver = require('../util/DataResolver'); const DataResolver = require('../util/DataResolver');
const SnowflakeUtil = require('../util/SnowflakeUtil'); const SnowflakeUtil = require('../util/SnowflakeUtil');
@@ -115,14 +116,6 @@ class Guild extends Base {
* @type {number} * @type {number}
*/ */
this.shardID = data.shardID; 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; 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) * Whether the guild is "large" (has more than large_threshold members, 50 by default)
* @type {boolean} * @type {boolean}

View File

@@ -819,6 +819,16 @@ exports.InteractionResponseTypes = createEnum([
'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE', '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) { function keyMirror(arr) {
let tmp = Object.create(null); let tmp = Object.create(null);
for (const value of arr) tmp[value] = value; for (const value of arr) tmp[value] = value;

12
typings/index.d.ts vendored
View File

@@ -37,6 +37,13 @@ declare enum InviteTargetType {
EMBEDDED_APPLICATION = 2, EMBEDDED_APPLICATION = 2,
} }
declare enum NSFWLevels {
DEFAULT = 0,
EXPLICIT = 1,
SAFE = 2,
AGE_RESTRICTED = 3,
}
declare enum OverwriteTypes { declare enum OverwriteTypes {
role = 0, role = 0,
member = 1, member = 1,
@@ -647,6 +654,7 @@ declare module 'discord.js' {
ApplicationCommandPermissionTypes: typeof ApplicationCommandPermissionTypes; ApplicationCommandPermissionTypes: typeof ApplicationCommandPermissionTypes;
InteractionTypes: typeof InteractionTypes; InteractionTypes: typeof InteractionTypes;
InteractionResponseTypes: typeof InteractionResponseTypes; InteractionResponseTypes: typeof InteractionResponseTypes;
NSFWLevels: typeof NSFWLevels;
}; };
export class DataResolver { export class DataResolver {
@@ -731,7 +739,7 @@ declare module 'discord.js' {
public mfaLevel: number; public mfaLevel: number;
public name: string; public name: string;
public readonly nameAcronym: string; public readonly nameAcronym: string;
public nsfw: boolean; public nsfwLevel: NSFWLevel;
public ownerID: Snowflake; public ownerID: Snowflake;
public readonly partnered: boolean; public readonly partnered: boolean;
public preferredLocale: string; public preferredLocale: string;
@@ -3299,6 +3307,8 @@ declare module 'discord.js' {
| 'REPLY' | 'REPLY'
| 'APPLICATION_COMMAND'; | 'APPLICATION_COMMAND';
type NSFWLevel = keyof typeof NSFWLevels;
interface OverwriteData { interface OverwriteData {
allow?: PermissionResolvable; allow?: PermissionResolvable;
deny?: PermissionResolvable; deny?: PermissionResolvable;