diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js index d959375a3..c26292fc1 100644 --- a/src/structures/ClientUser.js +++ b/src/structures/ClientUser.js @@ -88,9 +88,7 @@ class ClientUser extends User { this.guildSettings = new Collection(); if (data.user_guild_settings) { for (const settings of data.user_guild_settings) { - settings.client = this.client; - const guild = this.client.guilds.get(settings.guild_id); - this.guildSettings.set(settings.guild_id, new ClientUserGuildSettings(settings, guild)); + this.guildSettings.set(settings.guild_id, new ClientUserGuildSettings(settings, this.client)); } } } diff --git a/src/structures/ClientUserChannelOverride.js b/src/structures/ClientUserChannelOverride.js index 72414fee5..c9fe03de7 100644 --- a/src/structures/ClientUserChannelOverride.js +++ b/src/structures/ClientUserChannelOverride.js @@ -4,8 +4,7 @@ const Constants = require('../util/Constants'); * A wrapper around the ClientUser's channel overrides. */ class ClientUserChannelOverride { - constructor(user, data) { - this.user = user; + constructor(data) { this.patch(data); } @@ -14,8 +13,7 @@ class ClientUserChannelOverride { * @param {Object} data Data to patch this with */ patch(data) { - for (const key of Object.keys(Constants.UserChannelOverrideMap)) { - const value = Constants.UserChannelOverrideMap[key]; + for (const [key, value] of Object.entries(Constants.UserChannelOverrideMap)) { if (!data.hasOwnProperty(key)) continue; if (typeof value === 'function') { this[value.name] = value(data[key]); diff --git a/src/structures/ClientUserGuildSettings.js b/src/structures/ClientUserGuildSettings.js index 75d2f8332..dc7fd1ca6 100644 --- a/src/structures/ClientUserGuildSettings.js +++ b/src/structures/ClientUserGuildSettings.js @@ -6,9 +6,19 @@ const ClientUserChannelOverride = require('./ClientUserChannelOverride'); * A wrapper around the ClientUser's guild settings. */ class ClientUserGuildSettings { - constructor(data, guild) { - this.guild = guild; - this.client = data.client; + constructor(data, client) { + /** + * The client that created the instance of the the user + * @name ClientUserGuildSettings#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: client }); + /** + * The ID of the guild this settings are for + * @type {Snowflake} + */ + this.guildID = data.guild_id; this.channelOverrides = new Collection(); this.patch(data); } @@ -18,13 +28,12 @@ class ClientUserGuildSettings { * @param {Object} data Data to patch this with */ patch(data) { - for (const key of Object.keys(Constants.UserGuildSettingsMap)) { - const value = Constants.UserGuildSettingsMap[key]; + for (const [key, value] of Object.entries(Constants.UserGuildSettingsMap)) { if (!data.hasOwnProperty(key)) continue; if (key === 'channel_overrides') { for (const channel of data[key]) { this.channelOverrides.set(channel.channel_id, - new ClientUserChannelOverride(this.client.user, channel)); + new ClientUserChannelOverride(channel)); } } else if (typeof value === 'function') { this[value.name] = value(data[key]); @@ -41,7 +50,7 @@ class ClientUserGuildSettings { * @returns {Promise} */ update(name, value) { - return this.guild.client.api.guilds(this.guild.id).settings.patch({ data: { [name]: value } }); + return this.client.api.users('@me').guilds(this.guildID).settings.patch({ data: { [name]: value } }); } } diff --git a/src/structures/Guild.js b/src/structures/Guild.js index ff7f5d5bd..76f91a525 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -316,6 +316,7 @@ class Guild { * The position of this guild * This is only available when using a user account. * @type {?number} + * @readonly */ get position() { if (this.client.user.bot) return null; @@ -327,6 +328,7 @@ class Guild { * Whether the guild is muted * This is only available when using a user account. * @type {?boolean} + * @readonly */ get muted() { if (this.client.user.bot) return null; @@ -341,7 +343,8 @@ class Guild { * The type of message that should notify you * one of `EVERYTHING`, `MENTIONS`, `NOTHING` * This is only available when using a user account. - * @type {string} + * @type {?string} + * @readonly */ get messageNotifications() { if (this.client.user.bot) return null; @@ -355,7 +358,8 @@ class Guild { /** * Whether to receive mobile push notifications * This is only available when using a user account. - * @type {boolean} + * @type {?boolean} + * @readonly */ get mobilePush() { if (this.client.user.bot) return null; @@ -369,9 +373,11 @@ class Guild { /** * Whether to suppress everyone messages * This is only available when using a user account. - * @type {boolean} + * @type {?boolean} + * @readonly */ get suppressEveryone() { + if (this.client.user.bot) return null; try { return this.client.user.guildSettings.get(this.id).suppressEveryone; } catch (err) { diff --git a/src/structures/GuildChannel.js b/src/structures/GuildChannel.js index 20b18376a..20356722d 100644 --- a/src/structures/GuildChannel.js +++ b/src/structures/GuildChannel.js @@ -365,10 +365,11 @@ class GuildChannel extends Channel { } /** - * Whether the channel is muted - * This is only available when using a user account. - * @type {boolean} - */ + * Whether the channel is muted + * This is only available when using a user account. + * @type {?boolean} + * @readonly + */ get muted() { if (this.client.user.bot) return null; try { @@ -382,7 +383,8 @@ class GuildChannel extends Channel { * The type of message that should notify you * one of `EVERYTHING`, `MENTIONS`, `NOTHING`, `INHERIT` * This is only available when using a user account. - * @type {string} + * @type {?string} + * @readonly */ get messageNotifications() { if (this.client.user.bot) return null; diff --git a/src/structures/User.js b/src/structures/User.js index 022f51f60..8b0daa3fc 100644 --- a/src/structures/User.js +++ b/src/structures/User.js @@ -14,7 +14,7 @@ class User { /** * The client that created the instance of the the user * @name User#client - * @type {} + * @type {Client} * @readonly */ Object.defineProperty(this, 'client', { value: client }); diff --git a/src/util/Constants.js b/src/util/Constants.js index 0a2a72e31..fddd8934f 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -534,14 +534,14 @@ exports.UserChannelOverrideMap = { /** * The type of message that should notify you * one of `EVERYTHING`, `MENTIONS`, `NOTHING`, `INHERIT` - * @name ClientUserChannelOverrides#messageNotifications + * @name ClientUserChannelOverride#messageNotifications * @type {string} */ return exports.MessageNotificationTypes[type]; }, /** * Whether the guild is muted or not - * @name ClientUserChannelOverrides#muted + * @name ClientUserChannelOverride#muted * @type {boolean} */ muted: 'muted',