Files
discord.js/src/structures/AnonymousGuild.js

80 lines
1.9 KiB
JavaScript

'use strict';
const BaseGuild = require('./BaseGuild');
const { VerificationLevels, NSFWLevels } = require('../util/Constants');
/**
* Bundles common attributes and methods between {@link Guild} and {@link InviteGuild}
* @extends {BaseGuild}
* @abstract
*/
class AnonymousGuild extends BaseGuild {
constructor(client, data, immediatePatch = true) {
super(client, data);
if (immediatePatch) this._patch(data);
}
_patch(data) {
this.features = data.features;
/**
* The hash of the guild invite splash image
* @type {?string}
*/
this.splash = data.splash;
/**
* The hash of the guild banner
* @type {?string}
*/
this.banner = data.banner;
/**
* The description of the guild, if any
* @type {?string}
*/
this.description = data.description;
/**
* The verification level of the guild
* @type {VerificationLevel}
*/
this.verificationLevel = VerificationLevels[data.verification_level];
/**
* The vanity invite code of the guild, if any
* @type {?string}
*/
this.vanityURLCode = data.vanity_url_code;
if ('nsfw_level' in data) {
/**
* The NSFW level of this guild
* @type {NSFWLevel}
*/
this.nsfwLevel = NSFWLevels[data.nsfw_level];
}
}
/**
* The URL to this guild's banner.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @returns {?string}
*/
bannerURL({ format, size } = {}) {
if (!this.banner) return null;
return this.client.rest.cdn.Banner(this.id, this.banner, format, size);
}
/**
* The URL to this guild's invite splash image.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @returns {?string}
*/
splashURL({ format, size } = {}) {
if (!this.splash) return null;
return this.client.rest.cdn.Splash(this.id, this.splash, format, size);
}
}
module.exports = AnonymousGuild;