UNPKG

guilded.ts

Version:

A powerful NPM module that allows you to easily interact with the Guilded API.

66 lines 2.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ServerBanManager = void 0; const BaseManager_1 = require("../BaseManager"); const ServerBan_1 = require("../../structures/server/ServerBan"); const collection_1 = require("@discordjs/collection"); const ServerMember_1 = require("../../structures/server/ServerMember"); /** * The manager of bans that belong to a server. * @example new ServerBanManager(server); */ class ServerBanManager extends BaseManager_1.BaseManager { server; /** @param server The server the bans belongs to. */ constructor(server) { super(server.client, server.client.options.maxServerBanCache); this.server = server; } fetch(arg1, arg2) { if (typeof arg1 === 'string' || arg1 instanceof ServerBan_1.ServerBan) return this.fetchSingle(arg1, arg2); return this.fetchMany(arg1); } /** @ignore */ async fetchSingle(ban, options) { ban = ban instanceof ServerBan_1.ServerBan ? ban.id : ban; const cached = this.cache.get(ban); if (cached && !options?.force) return cached; const raw = await this.client.api.serverBans.fetch(this.server.id, ban); return new ServerBan_1.ServerBan(this.server, raw, options?.cache); } /** @ignore */ async fetchMany(options) { const raw = await this.client.api.serverBans.fetch(this.server.id); const bans = new collection_1.Collection(); for (const data of raw) { const ban = new ServerBan_1.ServerBan(this.server, data, options?.cache); bans.set(ban.user.id, ban); } return bans; } /** * Create a ban in the server. * @param member The member the ban belongs to. * @param reason The reason of the ban. * @returns The created ban. * @example bans.create(member); */ async create(member, reason) { member = member instanceof ServerMember_1.ServerMember ? member.id : member; const raw = await this.client.api.serverBans.create(this.server.id, member, reason); return new ServerBan_1.ServerBan(this.server, raw); } /** * Remove a ban in the server. * @param ban The ban to remove. * @example bans.remove(ban); */ remove(ban) { ban = ban instanceof ServerBan_1.ServerBan ? ban.id : ban; return this.client.api.serverBans.delete(this.server.id, ban); } } exports.ServerBanManager = ServerBanManager; //# sourceMappingURL=ServerBanManager.js.map