Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/structures/Guild.js
Expand Up @@ -24,6 +24,7 @@ const {
PartialTypes,
VerificationLevels,
ExplicitContentFilterLevels,
NsfwLevels,
iShibi marked this conversation as resolved.
Show resolved Hide resolved
} = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const SnowflakeUtil = require('../util/SnowflakeUtil');
Expand Down Expand Up @@ -116,12 +117,12 @@ 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}
* The nsfw level of this guild
* @type {NsfwLevel}
*/
this.nsfw = data.nsfw;
this.nsfwLevel = NsfwLevels[data.nsfw_level];
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/util/Constants.js
Expand Up @@ -818,6 +818,16 @@ exports.InteractionResponseTypes = createEnum([
'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE',
]);

/**
* NSFW level of a Guild
* * DEFAULT
* * EXPLICIT
* * SAFE
* * AGE_RESTRICTED
* @typedef {string} NsfwLevel
iShibi marked this conversation as resolved.
Show resolved Hide resolved
*/
exports.NsfwLevels = createEnum(['DEFAULT', 'EXPLICIT', 'SAFE', 'AGE_RESTRICTED']);
iShibi marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Up @@ -37,6 +37,13 @@ declare enum InviteTargetType {
EMBEDDED_APPLICATION = 2,
}

declare enum NsfwLevels {
iShibi marked this conversation as resolved.
Show resolved Hide resolved
DEFAULT = 0,
EXPLICIT = 1,
SAFE = 2,
AGE_RESTRICTED = 3,
}

declare enum OverwriteTypes {
role = 0,
member = 1,
Expand Down Expand Up @@ -648,6 +655,7 @@ declare module 'discord.js' {
ApplicationCommandPermissionTypes: typeof ApplicationCommandPermissionTypes;
InteractionTypes: typeof InteractionTypes;
InteractionResponseTypes: typeof InteractionResponseTypes;
NsfwLevels: typeof NsfwLevels;
iShibi marked this conversation as resolved.
Show resolved Hide resolved
};

export class DataResolver {
Expand Down Expand Up @@ -732,7 +740,7 @@ declare module 'discord.js' {
public mfaLevel: number;
public name: string;
public readonly nameAcronym: string;
public nsfw: boolean;
public nsfwLevel: NsfwLevel;
iShibi marked this conversation as resolved.
Show resolved Hide resolved
public ownerID: Snowflake;
public readonly partnered: boolean;
public preferredLocale: string;
Expand Down Expand Up @@ -3294,6 +3302,8 @@ declare module 'discord.js' {
type?: OverwriteType;
}

type NsfwLevel = 'DEFAULT' | 'EXPLICIT' | 'SAFE' | 'AGE_RESTRICTED';
iShibi marked this conversation as resolved.
Show resolved Hide resolved

type OverwriteResolvable = PermissionOverwrites | OverwriteData;

type OverwriteType = 'member' | 'role';
Expand Down