feat: GuildBanManager (#5276)

Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
Co-authored-by: Jan <66554238+vaporox@users.noreply.github.com>
Co-authored-by: izexi <43889168+izexi@users.noreply.github.com>
Co-authored-by: Shubham Parihar <shubhamparihar391@gmail.com>
This commit is contained in:
MBR-0001
2021-05-10 12:35:25 +02:00
committed by GitHub
parent 4a06dd1295
commit 6d09160f5b
11 changed files with 320 additions and 88 deletions

View File

@@ -10,6 +10,7 @@ const VoiceRegion = require('./VoiceRegion');
const Webhook = require('./Webhook');
const { Error, TypeError } = require('../errors');
const GuildApplicationCommandManager = require('../managers/GuildApplicationCommandManager');
const GuildBanManager = require('../managers/GuildBanManager');
const GuildChannelManager = require('../managers/GuildChannelManager');
const GuildEmojiManager = require('../managers/GuildEmojiManager');
const GuildMemberManager = require('../managers/GuildMemberManager');
@@ -61,6 +62,12 @@ class Guild extends Base {
*/
this.channels = new GuildChannelManager(this);
/**
* A manager of the bans belonging to this guild
* @type {GuildBanManager}
*/
this.bans = new GuildBanManager(this);
/**
* A manager of the roles belonging to this guild
* @type {RoleManager}
@@ -632,50 +639,6 @@ class Guild extends Base {
});
}
/**
* An object containing information about a guild member's ban.
* @typedef {Object} BanInfo
* @property {User} user User that was banned
* @property {?string} reason Reason the user was banned
*/
/**
* Fetches information on a banned user from this guild.
* @param {UserResolvable} user The User to fetch the ban info of
* @returns {Promise<BanInfo>}
*/
fetchBan(user) {
const id = this.client.users.resolveID(user);
if (!id) throw new Error('FETCH_BAN_RESOLVE_ID');
return this.client.api
.guilds(this.id)
.bans(id)
.get()
.then(ban => ({
reason: ban.reason,
user: this.client.users.add(ban.user),
}));
}
/**
* Fetches a collection of banned users in this guild.
* @returns {Promise<Collection<Snowflake, BanInfo>>}
*/
fetchBans() {
return this.client.api
.guilds(this.id)
.bans.get()
.then(bans =>
bans.reduce((collection, ban) => {
collection.set(ban.user.id, {
reason: ban.reason,
user: this.client.users.add(ban.user),
});
return collection;
}, new Collection()),
);
}
/**
* Fetches a collection of integrations to this guild.
* Resolves with a collection mapping integrations by their ids.