summaryrefslogtreecommitdiff
path: root/node_modules/discord.js/src/structures/GuildPreview.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/discord.js/src/structures/GuildPreview.js')
-rw-r--r--node_modules/discord.js/src/structures/GuildPreview.js157
1 files changed, 157 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/structures/GuildPreview.js b/node_modules/discord.js/src/structures/GuildPreview.js
new file mode 100644
index 0000000..681ff60
--- /dev/null
+++ b/node_modules/discord.js/src/structures/GuildPreview.js
@@ -0,0 +1,157 @@
+'use strict';
+
+const Base = require('./Base');
+const GuildPreviewEmoji = require('./GuildPreviewEmoji');
+const Collection = require('../util/Collection');
+
+/**
+ * Represents the data about the guild any bot can preview, connected to the specified public guild.
+ * @extends {Base}
+ */
+class GuildPreview extends Base {
+ constructor(client, data) {
+ super(client);
+
+ if (!data) return;
+
+ this._patch(data);
+ }
+
+ /**
+ * Builds the public guild with the provided data.
+ * @param {*} data The raw data of the public guild
+ * @private
+ */
+ _patch(data) {
+ /**
+ * The id of this public guild
+ * @type {string}
+ */
+ this.id = data.id;
+
+ /**
+ * The name of this public guild
+ * @type {string}
+ */
+ this.name = data.name;
+
+ /**
+ * The icon of this public guild
+ * @type {?string}
+ */
+ this.icon = data.icon;
+
+ /**
+ * The splash icon of this public guild
+ * @type {?string}
+ */
+ this.splash = data.splash;
+
+ /**
+ * The discovery splash icon of this public guild
+ * @type {?string}
+ */
+ this.discoverySplash = data.discovery_splash;
+
+ /**
+ * An array of enabled guild features
+ * @type {Features[]}
+ */
+ this.features = data.features;
+
+ /**
+ * The approximate count of members in this public guild
+ * @type {number}
+ */
+ this.approximateMemberCount = data.approximate_member_count;
+
+ /**
+ * The approximate count of online members in this public guild
+ * @type {number}
+ */
+ this.approximatePresenceCount = data.approximate_presence_count;
+
+ /**
+ * The description for this public guild
+ * @type {?string}
+ */
+ this.description = data.description;
+
+ if (!this.emojis) {
+ /**
+ * Collection of emojis belonging to this public guild
+ * @type {Collection<Snowflake, GuildPreviewEmoji>}
+ */
+ this.emojis = new Collection();
+ } else {
+ this.emojis.clear();
+ }
+ for (const emoji of data.emojis) {
+ this.emojis.set(emoji.id, new GuildPreviewEmoji(this.client, emoji, this));
+ }
+ }
+
+ /**
+ * The URL to this public guild's splash.
+ * @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);
+ }
+
+ /**
+ * The URL to this public guild's discovery splash.
+ * @param {ImageURLOptions} [options={}] Options for the Image URL
+ * @returns {?string}
+ */
+ discoverySplashURL({ format, size } = {}) {
+ if (!this.discoverySplash) return null;
+ return this.client.rest.cdn.DiscoverySplash(this.id, this.discoverySplash, format, size);
+ }
+
+ /**
+ * The URL to this public guild's icon.
+ * @param {ImageURLOptions} [options={}] Options for the Image URL
+ * @returns {?string}
+ */
+ iconURL({ format, size, dynamic } = {}) {
+ if (!this.icon) return null;
+ return this.client.rest.cdn.Icon(this.id, this.icon, format, size, dynamic);
+ }
+
+ /**
+ * Fetches this public guild.
+ * @returns {Promise<GuildPreview>}
+ */
+ fetch() {
+ return this.client.api
+ .guilds(this.id)
+ .preview.get()
+ .then(data => {
+ this._patch(data);
+ return this;
+ });
+ }
+
+ /**
+ * When concatenated with a string, this automatically returns the guild's name instead of the Guild object.
+ * @returns {string}
+ * @example
+ * // Logs: Hello from My Guild!
+ * console.log(`Hello from ${previewGuild}!`);
+ */
+ toString() {
+ return this.name;
+ }
+
+ toJSON() {
+ const json = super.toJSON();
+ json.iconURL = this.iconURL();
+ json.splashURL = this.splashURL();
+ return json;
+ }
+}
+
+module.exports = GuildPreview;