UNPKG

guilded.ts

Version:

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

64 lines 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChannelManager = void 0; const BaseManager_1 = require("../BaseManager"); const Channel_1 = require("../../structures/channel/Channel"); const util_1 = require("../../util"); /** * The manager of channels that belong to the client. * @example new ChannelManager(client); */ class ChannelManager extends BaseManager_1.BaseManager { /** @param client The client the channels belong to. */ constructor(client) { super(client, client.options.maxChannelCache); } /** * Fetch a channel from Guilded, or cache. * @param channel The channel to fetch. * @param options The options to fetch the channel with. * @returns The fetched channel. * @example channels.fetch(channel); */ async fetch(channel, options) { channel = channel instanceof Channel_1.Channel ? channel.id : channel; const cached = this.cache.get(channel); if (cached && !options?.force) return cached; const raw = await this.client.api.channels.fetch(channel); return (0, util_1.createChannel)(this.client, raw, options?.cache); } /** * Create a channel on Guilded. * @param payload The payload of the channel. * @returns The created channel. * @example channels.create({ name: 'Chat', type: 'chat' }); */ async create(payload) { const raw = await this.client.api.channels.create(payload); return (0, util_1.createChannel)(this.client, raw); } /** * Edit a channel on Guilded. * @param channel The channel to edit. * @param payload The payload of the channel. * @returns The edited channel. * @example channels.edit(channel, { name: 'Chat' }); */ async edit(channel, payload) { channel = channel instanceof Channel_1.Channel ? channel.id : channel; const raw = await this.client.api.channels.edit(channel, payload); return (0, util_1.createChannel)(this.client, raw); } /** * Delete a channel from Guilded. * @param channel The channel to delete. * @example channels.delete(channel); */ delete(channel) { channel = channel instanceof Channel_1.Channel ? channel.id : channel; return this.client.api.channels.delete(channel); } } exports.ChannelManager = ChannelManager; //# sourceMappingURL=ChannelManager.js.map