UNPKG

guilded.ts

Version:

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

256 lines 8.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChannelType = exports.Channel = void 0; const guilded_api_typings_1 = require("guilded-api-typings"); Object.defineProperty(exports, "ChannelType", { enumerable: true, get: function () { return guilded_api_typings_1.ChannelType; } }); const Base_1 = require("../Base"); const ChannelWebhookManager_1 = require("../../managers/channel/ChannelWebhookManager"); /** * Represents a channel on Guilded. * @example new Channel(client, rawChannel); */ class Channel extends Base_1.Base { raw; /** The type of the channel. */ type; /** The name of the channel. */ name; /** The topic of the channel. */ topic; /** The date the channel was created. */ createdAt; /** The ID of the user that created the channel. */ createdBy; /** The date the channel was edited. */ editedAt; /** The ID of the server the channel belongs to. */ serverId; /** The ID of the parent channel the channel belongs to. */ parantId; /** The ID of the category the channel belongs to. */ categoryId; /** The ID of the group the channel belongs to. */ groupId; /** Whether the channel is public. */ isPublic; /** The ID of the user that archived the channel. */ archivedBy; /** The date the channel was archived. */ archivedAt; /** The manager of webhooks that belong to the channel. */ webhooks; /** * @param client The client the channel belongs to. * @param raw The raw data of the channel. * @param cache Whether to cache the channel. */ constructor(client, raw, cache = client.options.cacheChannels ?? true) { super(client, raw.id); this.raw = raw; this.webhooks = new ChannelWebhookManager_1.ChannelWebhookManager(this); this.type = raw.type; this.name = raw.name; this.topic = raw.topic; this.createdAt = new Date(raw.createdAt); this.createdBy = raw.createdBy; this.editedAt = raw.updatedAt ? new Date(raw.updatedAt) : undefined; this.serverId = raw.serverId; this.parantId = raw.parentId; this.categoryId = raw.categoryId; this.groupId = raw.groupId; this.isPublic = raw.isPublic; this.archivedBy = raw.archivedBy; this.archivedAt = raw.archivedAt ? new Date(raw.archivedAt) : undefined; if (cache) client.channels.cache.set(this.id, this); } /** Whether the channel is cached. */ get isCached() { return this.client.channels.cache.has(this.id); } /** The timestamp the channel was created. */ get createdTimestamp() { return this.createdAt.getTime(); } /** The server member that created the channel. */ get creator() { return this.server?.members.cache.get(this.createdBy); } /** The timestamp the channel was edited. */ get editedTimestamp() { return this.editedAt?.getTime(); } /** The server the channel belongs to. */ get server() { return this.client.servers.cache.get(this.serverId); } /** The parent channel the channel belongs to. */ get parent() { return this.parantId ? this.client.channels.cache.get(this.parantId) : undefined; } /** The group the channel belongs to. */ get group() { return this.client.groups.cache.get(this.groupId); } /** The server member that archived the channel. */ get archiver() { return this.archivedBy ? this.server?.members.cache.get(this.archivedBy) : undefined; } /** The timestamp the channel was archived. */ get archivedTimestamp() { return this.archivedAt ? this.archivedAt.getTime() : undefined; } /** Whether the channel is archived. */ get isArchived() { return !!this.archivedBy; } /** Whether the channel is a announcement channel. */ get isAnnouncement() { return this.type === guilded_api_typings_1.ChannelType.Announcements; } /** Whther the channel is a chat channel. */ get isChat() { return this.type === guilded_api_typings_1.ChannelType.Chat; } /** Whether the channel is chat based. */ get isChatBased() { return (this.type === guilded_api_typings_1.ChannelType.Chat || this.type === guilded_api_typings_1.ChannelType.Stream || this.type === guilded_api_typings_1.ChannelType.Voice); } /** Whther the channel is a calendar channel. */ get isCalendar() { return this.type === guilded_api_typings_1.ChannelType.Calendar; } /** Whther the channel is a forum channel. */ get isForum() { return this.type === guilded_api_typings_1.ChannelType.Forums; } /** Whther the channel is a media channel. */ get isMedia() { return this.type === guilded_api_typings_1.ChannelType.Media; } /** Whther the channel is a doc channel. */ get isDoc() { return this.type === guilded_api_typings_1.ChannelType.Docs; } /** Whther the channel is a voice channel. */ get isVoice() { return this.type === guilded_api_typings_1.ChannelType.Voice; } /** Whther the channel is a list channel. */ get isList() { return this.type === guilded_api_typings_1.ChannelType.List; } /** Whther the channel is a schedule channel. */ get isSchedule() { return this.type === guilded_api_typings_1.ChannelType.Scheduling; } /** Whther the channel is a stream channel. */ get isStream() { return this.type === guilded_api_typings_1.ChannelType.Stream; } /** * Fetch the channel. * @param options The options to fetch the channel with. * @returns The fetched channel. * @example channel.fetch(); */ fetch(options) { return this.client.channels.fetch(this, options); } /** * Fetch the server member that created the channel. * @param options The options to fetch the server member with. * @returns The fetched server member. * @example channel.fetchCreator(); */ async fetchCreator(options) { const server = await this.fetchServer(); return server.members.fetch(this.createdBy, options); } /** * Fetch the server the channel belongs to. * @param options The options to fetch the server with. * @returns The fetched server. * @example channel.fetchServer(); */ fetchServer(options) { return this.client.servers.fetch(this.serverId, options); } /** * Fetch the parent channel the channel belongs to. * @param options The options to fetch the channel with. * @returns The fetched channel. * @example channel.fetchParent(); */ fetchParent(options) { return this.parantId ? this.client.channels.fetch(this.parantId, options) : undefined; } /** * Fetch the group the channel belongs to. * @param options The options to fetch the group with. * @returns The fetched group. * @example channel.fetchGroup(); */ fetchGroup(options) { return this.client.groups.fetch(this.groupId, options); } /** * Fetch the server member that archived the channel. * @param options The options to fetch the server member with. * @returns The fetched server member. * @example channel.fetchArchiver(); */ async fetchArchiver(options) { const server = await this.fetchServer(); return this.archivedBy ? server.members.fetch(this.archivedBy, options) : undefined; } /** * Edit the channel. * @param payload The payload of the channel. * @returns The edited channel. * @example channel.edit({ name: 'Chat' }); */ edit(payload) { return this.client.channels.edit(this, payload); } /** * Set the name of the channel. * @param name The name of the channel. * @returns The edited channel. * @example channel.setName('Chat'); */ setName(name) { return this.edit({ name }); } /** * Set the topic of the channel. * @param topic The topic of the channel. * @returns The edited channel. * @example channel.setTopic('This is a topic'); */ setTopic(topic) { return this.edit({ topic }); } /** * Set whether the channel is public. * @param isPublic Whether the channel is public. * @returns The edited channel. * @example channel.setPublic(true); */ setPublic(isPublic) { return this.edit({ isPublic }); } /** * Delete the channel. * @returns The deleted channel. * @example channel.delete(); */ async delete() { await this.client.channels.delete(this); return this; } } exports.Channel = Channel; //# sourceMappingURL=Channel.js.map