UNPKG

guilded.ts

Version:

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

78 lines 3.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ServerRoleManager = void 0; const BaseManager_1 = require("../BaseManager"); const ServerRole_1 = require("../../structures/server/ServerRole"); const ServerMemberRole_1 = require("../../structures/server/ServerMemberRole"); const collection_1 = require("@discordjs/collection"); const ServerMember_1 = require("../../structures/server/ServerMember"); /** * A manager of roles that belong to a server. * @example new ServerRoleManager(server); */ class ServerRoleManager extends BaseManager_1.BaseManager { server; /** @param server The server the roles belong to. */ constructor(server) { super(server.client, server.client.options.maxServerRoleCache); this.server = server; } /** * Fetch roles that belong to a member. * @param member The member the roles belong to. * @param options The options to fetch the roles with. * @returns The fetched roles that belong to the member. * @example roles.fetch(member); */ async fetch(member, options) { member = member instanceof ServerMember_1.ServerMember ? member.id : member; const raw = await this.client.api.serverMembers.fetchRoles(this.server.id, member); const roles = new collection_1.Collection(); const cachedMember = this.server.members.cache.get(member); for (const roleId of raw) { const role = new ServerRole_1.ServerRole(this.server, { id: roleId }, options?.cache); if (cachedMember) new ServerMemberRole_1.ServerMemberRole(cachedMember, { id: roleId }, options?.cacheMemberRoles); roles.set(roleId, role); } return roles; } /** * Assign a role to a member. * @param member The member the role belongs to. * @param role The role to add to the member. * @returns The role that was added to the member. * @example roles.assign(member, role); */ async assign(member, role) { member = member instanceof ServerMember_1.ServerMember ? member.id : member; role = role instanceof ServerRole_1.ServerRole ? role.id : role; await this.client.api.serverMembers.addRole(this.server.id, member, role); return new ServerRole_1.ServerRole(this.server, { id: role }); } /** * Unassign a role from a member. * @param member The member the role belongs to. * @param role The role to remove from the member. * @returns The role that was removed from the member. * @example roles.unassign(member, role); */ async unassign(member, role) { member = member instanceof ServerMember_1.ServerMember ? member.id : member; role = role instanceof ServerRole_1.ServerRole ? role.id : role; await this.client.api.serverMembers.removeRole(this.server.id, member, role); return new ServerRole_1.ServerRole(this.server, { id: role }); } /** * Award XP to a role. * @param role The role to award XP to. * @param amount The amount of XP to award to the role. * @example roles.awardXp(role, 100); */ awardXp(role, amount) { role = role instanceof ServerRole_1.ServerRole ? role.id : role; return this.client.api.serverRoles.awardXp(this.server.id, role, amount); } } exports.ServerRoleManager = ServerRoleManager; //# sourceMappingURL=ServerRoleManager.js.map