UNPKG

guilded.ts

Version:

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

183 lines 5.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ForumTopic = void 0; const Base_1 = require("./Base"); /** * Represents a topic on Guilded. * @example new ForumTopic(channel, rawForumTopic); */ class ForumTopic extends Base_1.Base { channel; raw; /** The ID of the server the forum topic belongs to. */ serverId; /** The ID of the channel the forum topic belongs to. */ channelId; /** The title of the forum topic. */ title; /** The date the forum topic was created. */ createdAt; /** The ID of the user that created the forum topic. */ createdBy; /** The ID of the webhook that created the forum topic. */ createdByWebhookId; /** The date the forum topic was edited. */ editedAt; /** The date the forum topic was bumped. */ bumpedAt; /** The content of the forum topic. */ content; /** The mentions of the forum topic. */ mentions; /** * @param channel The forum channel the topic belongs to. * @param raw The raw data of the forum topic. * @param cache Whether to cache the forum topic. */ constructor(channel, raw, cache = channel.client.options.cacheForumTopics ?? 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.createdAt = new Date(raw.createdAt); this.createdBy = raw.createdBy; this.createdByWebhookId = raw.createdByWebhookId; this.editedAt = raw.updatedAt ? new Date(raw.updatedAt) : undefined; this.bumpedAt = raw.bumpedAt ? new Date(raw.bumpedAt) : undefined; this.content = 'content' in raw ? raw.content : undefined; this.mentions = 'mentions' in raw ? raw.mentions : undefined; if (cache) channel.topics.cache.set(this.id, this); } /** Whether the forum topic is cached. */ get isCached() { return this.channel.topics.cache.has(this.id); } /** The server the forum topic belongs to. */ get server() { return this.channel.server; } /** The timestamp the forum topic was created. */ get createdTimestamp() { return this.createdAt.getTime(); } /** The server member that created the forum topic. */ get author() { return this.server?.members.cache.get(this.createdBy); } /** The webhook that created the forun topic. */ get webhook() { return this.createdByWebhookId ? this.channel.webhooks.cache.get(this.createdByWebhookId) : undefined; } /** The ID of the user that created the forum topic. */ get authorId() { return this.createdByWebhookId || this.createdBy; } /** The timestamp the forum topic was edited. */ get editedTimestamp() { return this.editedAt?.getTime(); } /** The timestamp the forum topic was bumped. */ get bumpedTimestamp() { return this.bumpedAt?.getTime(); } /** * Fetch the forum topic. * @param options The options to fetch the forum topic with. * @returns The fetched forum topic. * @example forumTopic.fetch(); */ fetch(options) { return this.channel.topics.fetch(this, options); } /** * Fetch the server the forum topic belongs to. * @param options The options to fetch the server with. * @returns The fetched server. * @example forumTopic.fetchServer(); */ fetchServer(options) { return this.channel.fetchServer(options); } /** * Fetch the server member that created the forum topic. * @param options The options to fetch the server member with. * @returns The fetched server member. * @example forumTopic.fetchAuthor(); */ async fetchAuthor(options) { const server = await this.fetchServer(); return server.members.fetch(this.createdBy, options); } /** * Fetch the webhook that created the forum topic. * @param options The options to fetch the webhook with. * @returns The fetched webhook. * @example forumTopic.fetchWebhook(); */ fetchWebhook(options) { return this.createdByWebhookId ? this.channel.webhooks.fetch(this.createdByWebhookId, options) : undefined; } /** * Edit the forum topic. * @param payload The payload of the forum topic. * @returns The edited forum topic. * @example forumTopic.edit({ title: 'New title' }); */ edit(payload) { return this.channel.topics.edit(this, payload); } /** * Delete the forum topic. * @returns The deleted forum topic. * @example forumTopic.delete(); */ async delete() { await this.channel.topics.delete(this); return this; } /** * Pin the forum topic. * @returns The pinned forum topic. * @example forumTopic.pin(); */ async pin() { await this.channel.topics.pin(this); return this; } /** * Unpin the forum topic. * @returns The unpinned forum topic. * @example forumTopic.unpin(); */ async unpin() { await this.channel.topics.unpin(this); return this; } /** * Lock the forum topic. * @returns The locked forum topic. * @example forumTopic.lock(); */ async lock() { await this.channel.topics.lock(this); return this; } /** * Unlock the forum topic. * @returns The unlocked forum topic. * @example forumTopic.unlock(); */ async unlock() { await this.channel.topics.unlock(this); return this; } } exports.ForumTopic = ForumTopic; //# sourceMappingURL=ForumTopic.js.map