UNPKG

guilded.ts

Version:

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

138 lines 4.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Doc = void 0; const Base_1 = require("./Base"); /** * Represents a doc on Guilded. * @example new Doc(channel, rawDoc); */ class Doc extends Base_1.Base { channel; raw; /** The ID of the server the doc belongs to. */ serverId; /** The ID of the channel the doc belongs to. */ channelId; /** The title of the doc. */ title; /** The content of the doc. */ content; /** The mentions of the doc. */ mentions; /** The date the doc was created. */ createdAt; /** The ID of the user that created the doc. */ createdBy; /** The date the doc was edited. */ editedAt; /** The ID of the user that edited the doc. */ editedBy; /** * @param channel The doc channel the doc belongs to. * @param raw The raw data of the doc. * @param cache Whether to cache the doc. */ constructor(channel, raw, cache = channel.client.options.cacheDocs ?? true) { super(channel.client, raw.id); this.channel = channel; this.raw = raw; this.serverId = raw.serverId; this.channelId = raw.channelId; this.title = raw.title; this.content = raw.content; this.mentions = raw.mentions; this.createdAt = new Date(raw.createdAt); this.createdBy = raw.createdBy; this.editedAt = raw.updatedAt ? new Date(raw.updatedAt) : undefined; this.editedBy = raw.updatedBy; if (cache) channel.docs.cache.set(this.id, this); } /** Whether the doc is cached. */ get isCached() { return this.channel.docs.cache.has(this.id); } /** The server the doc belongs to. */ get server() { return this.channel.server; } /** The timestamp the doc was created. */ get createdTimestamp() { return this.createdAt.getTime(); } /** The server member that created the doc. */ get author() { return this.server?.members.cache.get(this.createdBy); } /** The ID of the user that created the doc. */ get authorId() { return this.createdBy; } /** The timestamp the doc was edited. */ get editedTimestamp() { return this.editedAt?.getTime(); } /** The server member that edited the doc. */ get editor() { return this.editedBy ? this.server?.members.cache.get(this.editedBy) : undefined; } /** * Fetch the doc. * @param options The options to fetch the doc with. * @returns The fetched doc. * @example doc.fetch(); */ fetch(options) { return this.channel.docs.fetch(this, options); } /** * Fetch the server the doc belongs to. * @param options The options to fetch the server with. * @returns The fetched server. * @example doc.fetchServer(); */ fetchServer(options) { return this.channel.fetchServer(options); } /** * Fetch the server member that created the doc. * @param options The options to fetch the server member with. * @returns The fetched server member. * @example doc.fetchAuthor(); */ async fetchAuthor(options) { const server = await this.fetchServer(); return server.members.fetch(this.createdBy, options); } /** * Fetch the server member that edited the doc. * @param options The options to fetch the server member with. * @returns The fetched server member. * @example doc.fetchEditor(); */ async fetchEditor(options) { const server = await this.fetchServer(); return this.editedBy ? server.members.fetch(this.editedBy, options) : undefined; } /** * Edit the doc. * @param title The title of the doc. * @param content The content of the doc. * @returns The edited doc. * @example doc.edit('New title', 'New content'); */ edit(title, content) { return this.channel.docs.edit(this, title, content); } /** * Delete the doc. * @returns The deleted doc. * @example doc.delete(); */ async delete() { await this.channel.docs.delete(this); return this; } } exports.Doc = Doc; //# sourceMappingURL=Doc.js.map