mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +01:00
feat(Guild): backport misc properties and setRolePositions (#3337)
* feat(Guild): backport misc properties and setRolePositions PRs: * #3168 * #3317 * typings
This commit is contained in:
@@ -499,6 +499,10 @@ class RESTMethods {
|
||||
.then(data => this.client.actions.GuildMemberGet.handle(guild, data).member);
|
||||
}
|
||||
|
||||
getGuild(guild) {
|
||||
return this.rest.makeRequest('get', Endpoints.Guild(guild), true);
|
||||
}
|
||||
|
||||
getGuildMember(guild, userID, cache) {
|
||||
return this.rest.makeRequest('get', Endpoints.Guild(guild).Member(userID), true).then(data => {
|
||||
if (cache) return this.client.actions.GuildMemberGet.handle(guild, data).member;
|
||||
@@ -886,23 +890,6 @@ class RESTMethods {
|
||||
.then(() => user);
|
||||
}
|
||||
|
||||
updateChannelPositions(guildID, channels) {
|
||||
const data = new Array(channels.length);
|
||||
for (let i = 0; i < channels.length; i++) {
|
||||
data[i] = {
|
||||
id: this.client.resolver.resolveChannelID(channels[i].channel),
|
||||
position: channels[i].position,
|
||||
};
|
||||
}
|
||||
|
||||
return this.rest.makeRequest('patch', Endpoints.Guild(guildID).channels, true, data).then(() =>
|
||||
this.client.actions.GuildChannelsPositionUpdate.handle({
|
||||
guild_id: guildID,
|
||||
channels,
|
||||
}).guild
|
||||
);
|
||||
}
|
||||
|
||||
updateEmbed(guildID, embed, reason) {
|
||||
return this.rest.makeRequest('patch', Endpoints.Guild(guildID).embed, true, {
|
||||
enabled: embed.enabled,
|
||||
|
||||
@@ -184,6 +184,61 @@ class Guild {
|
||||
this.defaultMessageNotifications = Constants.DefaultMessageNotifications[data.default_message_notifications] ||
|
||||
data.default_message_notifications;
|
||||
|
||||
/**
|
||||
* 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 embed channel ID, if enabled
|
||||
* @type {?string}
|
||||
* @name Guild#embedChannelID
|
||||
*/
|
||||
if (typeof data.embed_channel_id !== 'undefined') this.embedChannelID = data.embed_channel_id;
|
||||
|
||||
/**
|
||||
* The maximum amount of members the guild can have
|
||||
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
|
||||
* @type {?number}
|
||||
* @name Guild#maximumMembers
|
||||
*/
|
||||
if (typeof data.max_members !== 'undefined') this.maximumMembers = data.max_members || 250000;
|
||||
|
||||
/**
|
||||
* The maximum amount of presences the guild can have
|
||||
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
|
||||
* @type {?number}
|
||||
* @name Guild#maximumPresences
|
||||
*/
|
||||
if (typeof data.max_presences !== 'undefined') this.maximumPresences = data.max_presences || 5000;
|
||||
|
||||
/**
|
||||
* Whether widget images are enabled on this guild
|
||||
* @type {?boolean}
|
||||
* @name Guild#widgetEnabled
|
||||
*/
|
||||
if (typeof data.widget_enabled !== 'undefined') this.widgetEnabled = data.widget_enabled;
|
||||
|
||||
/**
|
||||
* The widget channel ID, if enabled
|
||||
* @type {?string}
|
||||
* @name Guild#widgetChannelID
|
||||
*/
|
||||
if (typeof data.widget_channel_id !== 'undefined') this.widgetChannelID = data.widget_channel_id;
|
||||
|
||||
/**
|
||||
* The vanity URL code of the guild, if any
|
||||
* @type {?string}
|
||||
*/
|
||||
this.vanityURLCode = data.vanity_url_code;
|
||||
|
||||
this.id = data.id;
|
||||
this.available = !data.unavailable;
|
||||
this.features = data.features || this.features || [];
|
||||
@@ -272,6 +327,24 @@ class Guild {
|
||||
return new Date(this.createdTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Embed channel for this guild
|
||||
* @type {?TextChannel}
|
||||
* @readonly
|
||||
*/
|
||||
get embedChannel() {
|
||||
return this.channels.get(this.embedChannelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget channel for this guild
|
||||
* @type {?TextChannel}
|
||||
* @readonly
|
||||
*/
|
||||
get widgetChannel() {
|
||||
return this.channels.get(this.widgetChannelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The time the client user joined the guild
|
||||
* @type {Date}
|
||||
@@ -300,6 +373,16 @@ class Guild {
|
||||
return Constants.Endpoints.Guild(this).Icon(this.client.options.http.cdn, this.icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* The URL to this guild's banner.
|
||||
* @type {?string}
|
||||
* @readonly
|
||||
*/
|
||||
get bannerURL() {
|
||||
if (!this.banner) return null;
|
||||
return Constants.Endpoints.Guild(this).Banner(this.client.options.http.cdn, this.banner);
|
||||
}
|
||||
|
||||
/**
|
||||
* The acronym that shows up in place of a guild icon.
|
||||
* @type {string}
|
||||
@@ -473,6 +556,18 @@ class Guild {
|
||||
return this.client.resolver.resolveGuildMember(this, user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches this guild.
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
fetch() {
|
||||
return this.client.rest.methods.getGuild(this).then(data => {
|
||||
this.setup(data);
|
||||
|
||||
return this;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* An object containing information about a guild member's ban.
|
||||
* @typedef {Object} BanInfo
|
||||
@@ -1115,7 +1210,25 @@ class Guild {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setChannelPositions(channelPositions) {
|
||||
return this.client.rest.methods.updateChannelPositions(this.id, channelPositions);
|
||||
channelPositions = channelPositions.map(({ channel, position }) => ({ id: channel.id || channel, position }));
|
||||
return this.client.rest.methods.setChannelPositions(this.id, channelPositions);
|
||||
}
|
||||
|
||||
/**
|
||||
* The data needed for updating a role's position.
|
||||
* @typedef {Object} RolePosition
|
||||
* @property {RoleResolvable} role Role to update
|
||||
* @property {number} position New position for the role
|
||||
*/
|
||||
|
||||
/**
|
||||
* Batch-updates the guild's role's positions.
|
||||
* @param {RolePosition[]} rolePositions Role positions to update
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
setRolePositions(rolePositions) {
|
||||
rolePositions = rolePositions.map(({ role, position }) => ({ id: role.id || role, position }));
|
||||
return this.client.rest.methods.setRolePositions(this.id, rolePositions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1396,7 +1509,7 @@ class Guild {
|
||||
|
||||
Util.moveElementInArray(updatedChannels, channel, position, relative);
|
||||
|
||||
updatedChannels = updatedChannels.map((r, i) => ({ id: r.id, position: i }));
|
||||
updatedChannels = updatedChannels.map((c, i) => ({ id: c.id, position: i }));
|
||||
return this.client.rest.methods.setChannelPositions(this.id, updatedChannels);
|
||||
}
|
||||
|
||||
|
||||
@@ -152,6 +152,7 @@ const Endpoints = exports.Endpoints = {
|
||||
auditLogs: `${base}/audit-logs`,
|
||||
Emoji: emojiID => `${base}/emojis/${emojiID}`,
|
||||
Icon: (root, hash) => Endpoints.CDN(root).Icon(guildID, hash),
|
||||
Banner: (root, hash) => Endpoints.CDN(root).Banner(guildID, hash),
|
||||
Splash: (root, hash) => Endpoints.CDN(root).Splash(guildID, hash),
|
||||
Role: roleID => `${base}/roles/${roleID}`,
|
||||
Member: memberID => {
|
||||
@@ -210,6 +211,7 @@ const Endpoints = exports.Endpoints = {
|
||||
Asset: name => `${root}/assets/${name}`,
|
||||
Avatar: (userID, hash) => `${root}/avatars/${userID}/${hash}.${hash.startsWith('a_') ? 'gif' : 'png?size=2048'}`,
|
||||
Icon: (guildID, hash) => `${root}/icons/${guildID}/${hash}.jpg`,
|
||||
Banner: (guildID, hash) => `${root}/banners/${guildID}/${hash}.jpg`,
|
||||
AppIcon: (clientID, hash) => `${root}/app-icons/${clientID}/${hash}.png`,
|
||||
AppAsset: (clientID, hash) => `${root}/app-assets/${clientID}/${hash}.png`,
|
||||
GDMIcon: (channelID, hash) => `${root}/channel-icons/${channelID}/${hash}.jpg?size=2048`,
|
||||
|
||||
Reference in New Issue
Block a user