summaryrefslogtreecommitdiff
path: root/node_modules/discord.js/src/structures/GuildPreview.js
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2023-09-02 19:12:47 -0400
committersowgro <tpoke.ferrari@gmail.com>2023-09-02 19:12:47 -0400
commite4450c8417624b71d779cb4f41692538f9165e10 (patch)
treeb70826542223ecdf8a7a259f61b0a1abb8a217d8 /node_modules/discord.js/src/structures/GuildPreview.js
downloadsowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.gz
sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.bz2
sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.zip
first commit
Diffstat (limited to 'node_modules/discord.js/src/structures/GuildPreview.js')
-rw-r--r--node_modules/discord.js/src/structures/GuildPreview.js193
1 files changed, 193 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..6ff2026
--- /dev/null
+++ b/node_modules/discord.js/src/structures/GuildPreview.js
@@ -0,0 +1,193 @@
+'use strict';
+
+const { Collection } = require('@discordjs/collection');
+const { DiscordSnowflake } = require('@sapphire/snowflake');
+const { Routes } = require('discord-api-types/v10');
+const Base = require('./Base');
+const GuildPreviewEmoji = require('./GuildPreviewEmoji');
+const { Sticker } = require('./Sticker');
+
+/**
+ * Represents the data about the guild any bot can preview, connected to the specified guild.
+ * @extends {Base}
+ */
+class GuildPreview extends Base {
+ constructor(client, data) {
+ super(client);
+
+ if (!data) return;
+
+ this._patch(data);
+ }
+
+ _patch(data) {
+ /**
+ * The id of this guild
+ * @type {string}
+ */
+ this.id = data.id;
+
+ if ('name' in data) {
+ /**
+ * The name of this guild
+ * @type {string}
+ */
+ this.name = data.name;
+ }
+
+ if ('icon' in data) {
+ /**
+ * The icon of this guild
+ * @type {?string}
+ */
+ this.icon = data.icon;
+ }
+
+ if ('splash' in data) {
+ /**
+ * The splash icon of this guild
+ * @type {?string}
+ */
+ this.splash = data.splash;
+ }
+
+ if ('discovery_splash' in data) {
+ /**
+ * The discovery splash icon of this guild
+ * @type {?string}
+ */
+ this.discoverySplash = data.discovery_splash;
+ }
+
+ if ('features' in data) {
+ /**
+ * An array of enabled guild features
+ * @type {GuildFeature[]}
+ */
+ this.features = data.features;
+ }
+
+ if ('approximate_member_count' in data) {
+ /**
+ * The approximate count of members in this guild
+ * @type {number}
+ */
+ this.approximateMemberCount = data.approximate_member_count;
+ }
+
+ if ('approximate_presence_count' in data) {
+ /**
+ * The approximate count of online members in this guild
+ * @type {number}
+ */
+ this.approximatePresenceCount = data.approximate_presence_count;
+ }
+
+ if ('description' in data) {
+ /**
+ * The description for this guild
+ * @type {?string}
+ */
+ this.description = data.description;
+ } else {
+ this.description ??= null;
+ }
+
+ if (!this.emojis) {
+ /**
+ * Collection of emojis belonging to this 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));
+ }
+
+ /**
+ * Collection of stickers belonging to this guild
+ * @type {Collection<Snowflake, Sticker>}
+ */
+ this.stickers = data.stickers.reduce(
+ (stickers, sticker) => stickers.set(sticker.id, new Sticker(this.client, sticker)),
+ new Collection(),
+ );
+ }
+
+ /**
+ * The timestamp this guild was created at
+ * @type {number}
+ * @readonly
+ */
+ get createdTimestamp() {
+ return DiscordSnowflake.timestampFrom(this.id);
+ }
+
+ /**
+ * The time this guild was created at
+ * @type {Date}
+ * @readonly
+ */
+ get createdAt() {
+ return new Date(this.createdTimestamp);
+ }
+
+ /**
+ * The URL to this guild's splash.
+ * @param {ImageURLOptions} [options={}] Options for the image URL
+ * @returns {?string}
+ */
+ splashURL(options = {}) {
+ return this.splash && this.client.rest.cdn.splash(this.id, this.splash, options);
+ }
+
+ /**
+ * The URL to this guild's discovery splash.
+ * @param {ImageURLOptions} [options={}] Options for the image URL
+ * @returns {?string}
+ */
+ discoverySplashURL(options = {}) {
+ return this.discoverySplash && this.client.rest.cdn.discoverySplash(this.id, this.discoverySplash, options);
+ }
+
+ /**
+ * The URL to this guild's icon.
+ * @param {ImageURLOptions} [options={}] Options for the image URL
+ * @returns {?string}
+ */
+ iconURL(options = {}) {
+ return this.icon && this.client.rest.cdn.icon(this.id, this.icon, options);
+ }
+
+ /**
+ * Fetches this guild.
+ * @returns {Promise<GuildPreview>}
+ */
+ async fetch() {
+ const data = await this.client.rest.get(Routes.guildPreview(this.id));
+ 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;