UNPKG

guilded.ts

Version:

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

77 lines 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DocManager = void 0; const BaseManager_1 = require("./BaseManager"); const Doc_1 = require("../structures/Doc"); const collection_1 = require("@discordjs/collection"); /** * The manager of docs that belong to a doc channel. * @example new DocManager(channel); */ class DocManager extends BaseManager_1.BaseManager { channel; /** @param channel The doc channel the docs belong to. */ constructor(channel) { super(channel.client, channel.client.options.maxDocCache); this.channel = channel; } fetch(arg1, arg2) { if (typeof arg1 === 'number' || arg1 instanceof Doc_1.Doc) return this.fetchSingle(arg1, arg2); return this.fetchMany(arg1); } /** @ignore */ async fetchSingle(doc, options) { doc = doc instanceof Doc_1.Doc ? doc.id : doc; const cached = this.cache.get(doc); if (cached && !options?.force) return cached; const raw = await this.client.api.docs.fetch(this.channel.id, doc); return new Doc_1.Doc(this.channel, raw, options?.cache); } /** @ignore */ async fetchMany(options) { const raw = await this.client.api.docs.fetch(this.channel.id, options); const docs = new collection_1.Collection(); for (const data of raw) { const doc = new Doc_1.Doc(this.channel, data, options?.cache); docs.set(data.id, doc); } return docs; } /** * Create a doc in the channel. * @param title The title of the doc. * @param content The content of the doc. * @returns The created doc. * @example docs.create('Title', 'Content'); */ async create(title, content) { const raw = await this.client.api.docs.create(this.channel.id, title, content); return new Doc_1.Doc(this.channel, raw); } /** * Edit a doc in the channel. * @param doc The doc to edit. * @param title The title of the doc. * @param content The content of the doc. * @returns The edited doc. * @example docs.edit(doc, 'Title', 'Content'); */ async edit(doc, title, content) { doc = doc instanceof Doc_1.Doc ? doc.id : doc; const raw = await this.client.api.docs.edit(this.channel.id, doc, title, content); return new Doc_1.Doc(this.channel, raw); } /** * Delete a doc from the channel. * @param doc The doc to delete. * @example docs.delete(doc); */ delete(doc) { doc = doc instanceof Doc_1.Doc ? doc.id : doc; return this.client.api.docs.delete(this.channel.id, doc); } } exports.DocManager = DocManager; //# sourceMappingURL=DocManager.js.map