refactor: move Guild setPositions methods to managers (#6875)

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
Rodry
2021-10-26 20:28:56 +01:00
committed by GitHub
parent b27888455f
commit e12a5b6a0c
4 changed files with 61 additions and 28 deletions

View File

@@ -1187,24 +1187,14 @@ class Guild extends AnonymousGuild {
* <info>Only one channel's parent can be changed at a time</info>
* @param {ChannelPosition[]} channelPositions Channel positions to update
* @returns {Promise<Guild>}
* @deprecated Use {@link GuildChannelManager#setPositions} instead
* @example
* guild.setChannelPositions([{ channel: channelId, position: newChannelIndex }])
* .then(guild => console.log(`Updated channel positions for ${guild}`))
* .catch(console.error);
*/
async setChannelPositions(channelPositions) {
const updatedChannels = channelPositions.map(r => ({
id: this.client.channels.resolveId(r.channel),
position: r.position,
lock_permissions: r.lockPermissions,
parent_id: typeof r.parent !== 'undefined' ? this.channels.resolveId(r.parent) : undefined,
}));
await this.client.api.guilds(this.id).channels.patch({ data: updatedChannels });
return this.client.actions.GuildChannelsPositionUpdate.handle({
guild_id: this.id,
channels: updatedChannels,
}).guild;
setChannelPositions(channelPositions) {
return this.channels.setPositions(channelPositions);
}
/**
@@ -1218,26 +1208,14 @@ class Guild extends AnonymousGuild {
* Batch-updates the guild's role positions
* @param {GuildRolePosition[]} rolePositions Role positions to update
* @returns {Promise<Guild>}
* @deprecated Use {@link RoleManager#setPositions} instead
* @example
* guild.setRolePositions([{ role: roleId, position: updatedRoleIndex }])
* .then(guild => console.log(`Role positions updated for ${guild}`))
* .catch(console.error);
*/
async setRolePositions(rolePositions) {
// Make sure rolePositions are prepared for API
rolePositions = rolePositions.map(o => ({
id: this.roles.resolveId(o.role),
position: o.position,
}));
// Call the API to update role positions
await this.client.api.guilds(this.id).roles.patch({
data: rolePositions,
});
return this.client.actions.GuildRolesPositionUpdate.handle({
guild_id: this.id,
roles: rolePositions,
}).guild;
setRolePositions(rolePositions) {
return this.roles.setPositions(rolePositions);
}
/**