mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
* Fix docs for Guild#pruneMembers * ClientApplication returns * Guild#deleteEmoji * Guild#setRolePosition takes RoleResolvable * Client#fetchApplication returns ClientApplication not Oauth2Application * ClientDataResolver#resolveImage can return null * ClientApplication#toString small example * Guild#allowDMs now has a only for user accounts warning * ClientUserSettings#patch is private and setGuildPosition has a user account warning * Role#setPermissions can take PermissionResolvable, not just String * ChannelCreationOverwrites is for a role or a member, not for a "group" * Fix ChannelData#userlimit string being wrong "The user limit of voice the channel" :lul: * ChannelResolvable is only for Channel or Snowflake * EmojiIdentifierResolvable supports Snowflakes * UserResolvable doesn't take a guild * Make patch functions private * Remove examples * Webhoox#edit options.name defaults to the webhook name * Make VoiceConnection functions private * Am dum The whole ClientUserSettings category is only for self bots soo * Value for update functions is * * Make update functions be private * Fix GuildEditData missing Ssytemchannel property * PermissionOverwriteOptions can accept null as an option (Why did no-one document this?)
81 lines
2.4 KiB
JavaScript
81 lines
2.4 KiB
JavaScript
const Constants = require('../util/Constants');
|
|
const Util = require('../util/Util');
|
|
const { Error } = require('../errors');
|
|
|
|
/**
|
|
* A wrapper around the ClientUser's settings.
|
|
*/
|
|
class ClientUserSettings {
|
|
constructor(user, data) {
|
|
this.user = user;
|
|
this.patch(data);
|
|
}
|
|
|
|
/**
|
|
* Patch the data contained in this class with new partial data.
|
|
* @param {Object} data Data to patch this with
|
|
* @private
|
|
*/
|
|
patch(data) {
|
|
for (const [key, value] of Object.entries(Constants.UserSettingsMap)) {
|
|
if (!data.hasOwnProperty(key)) continue;
|
|
if (typeof value === 'function') {
|
|
this[value.name] = value(data[key]);
|
|
} else {
|
|
this[value] = data[key];
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update a specific property of of user settings.
|
|
* @param {string} name Name of property
|
|
* @param {*} value Value to patch
|
|
* @returns {Promise<Object>}
|
|
* @private
|
|
*/
|
|
update(name, value) {
|
|
return this.user.client.api.users['@me'].settings.patch({ data: { [name]: value } });
|
|
}
|
|
|
|
/**
|
|
* Sets the position of the guild in the guild listing.
|
|
* @param {Guild} guild The guild to move
|
|
* @param {number} position Absolute or relative position
|
|
* @param {boolean} [relative=false] Whether to position relatively or absolutely
|
|
* @returns {Promise<Guild>}
|
|
*/
|
|
setGuildPosition(guild, position, relative) {
|
|
const temp = Object.assign([], this.guildPositions);
|
|
Util.moveElementInArray(temp, guild.id, position, relative);
|
|
return this.update('guild_positions', temp).then(() => guild);
|
|
}
|
|
|
|
/**
|
|
* Add a guild to the list of restricted guilds.
|
|
* @param {Guild} guild The guild to add
|
|
* @returns {Promise<Guild>}
|
|
*/
|
|
addRestrictedGuild(guild) {
|
|
const temp = Object.assign([], this.restrictedGuilds);
|
|
if (temp.includes(guild.id)) return Promise.reject(new Error('GUILD_RESTRICTED', true));
|
|
temp.push(guild.id);
|
|
return this.update('restricted_guilds', temp).then(() => guild);
|
|
}
|
|
|
|
/**
|
|
* Remove a guild from the list of restricted guilds.
|
|
* @param {Guild} guild The guild to remove
|
|
* @returns {Promise<Guild>}
|
|
*/
|
|
removeRestrictedGuild(guild) {
|
|
const temp = Object.assign([], this.restrictedGuilds);
|
|
const index = temp.indexOf(guild.id);
|
|
if (index < 0) return Promise.reject(new Error('GUILD_RESTRICTED'));
|
|
temp.splice(index, 1);
|
|
return this.update('restricted_guilds', temp).then(() => guild);
|
|
}
|
|
}
|
|
|
|
module.exports = ClientUserSettings;
|