guilded.ts
Version:
A powerful NPM module that allows you to easily interact with the Guilded API.
111 lines • 4.58 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ForumTopicManager = void 0;
const BaseManager_1 = require("./BaseManager");
const ForumTopic_1 = require("../structures/ForumTopic");
const collection_1 = require("@discordjs/collection");
/**
* The manager of topics that belong to a forum channel.
* @example new ForumTopicManager(channel);
*/
class ForumTopicManager extends BaseManager_1.BaseManager {
channel;
/** @param channel The forum channel the topics belong to. */
constructor(channel) {
super(channel.client, channel.client.options.maxForumTopicCache);
this.channel = channel;
}
fetch(arg1, arg2) {
if (typeof arg1 === 'number' || arg1 instanceof ForumTopic_1.ForumTopic)
return this.fetchSingle(arg1, arg2);
return this.fetchMany(arg1);
}
/** @ignore */
async fetchSingle(forumTopic, options) {
forumTopic = forumTopic instanceof ForumTopic_1.ForumTopic ? forumTopic.id : forumTopic;
const cached = this.cache.get(forumTopic);
if (cached && !options?.force)
return cached;
const raw = await this.client.api.forumTopics.fetch(this.channel.id, forumTopic);
return new ForumTopic_1.ForumTopic(this.channel, raw, options?.cache);
}
/** @ignore */
async fetchMany(options) {
const raw = await this.client.api.forumTopics.fetch(this.channel.id, options);
const forumTopics = new collection_1.Collection();
for (const data of raw) {
const forumTopic = new ForumTopic_1.ForumTopic(this.channel, data, options?.cache);
forumTopics.set(forumTopic.id, forumTopic);
}
return forumTopics;
}
/**
* Create a topic in the forum channel.
* @param payload The payload of the forum topic.
* @returns The created forum topic.
* @example topics.create({ title: 'My Topic' });
*/
async create(payload) {
const raw = await this.client.api.forumTopics.create(this.channel.id, payload);
return new ForumTopic_1.ForumTopic(this.channel, raw);
}
/**
* Edit a forum topic in the channel.
* @param forumTopic The forum topic to edit.
* @param payload The payload of the forum topic.
* @returns The edited forum topic.
* @example topics.edit(forumTopic, { title: 'My Topic' });
*/
async edit(forumTopic, payload) {
forumTopic = forumTopic instanceof ForumTopic_1.ForumTopic ? forumTopic.id : forumTopic;
const raw = await this.client.api.forumTopics.edit(this.channel.id, forumTopic, payload);
return new ForumTopic_1.ForumTopic(this.channel, raw);
}
/**
* Delete a forum topic from the channel.
* @param forumTopic The forum topic to delete.
* @example topics.delete(forumTopic);
*/
delete(forumTopic) {
forumTopic = forumTopic instanceof ForumTopic_1.ForumTopic ? forumTopic.id : forumTopic;
return this.client.api.forumTopics.delete(this.channel.id, forumTopic);
}
/**
* Pin a forum topic in the channel.
* @param forumTopic The forum topic to pin.
* @example topics.pin(forumTopic);
*/
pin(forumTopic) {
forumTopic = forumTopic instanceof ForumTopic_1.ForumTopic ? forumTopic.id : forumTopic;
return this.client.api.forumTopics.pin(this.channel.id, forumTopic);
}
/**
* Unpin a forum topic from the channel.
* @param forumTopic The forum topic to unpin.
* @example topics.unpin(forumTopic);
*/
unpin(forumTopic) {
forumTopic = forumTopic instanceof ForumTopic_1.ForumTopic ? forumTopic.id : forumTopic;
return this.client.api.forumTopics.unpin(this.channel.id, forumTopic);
}
/**
* Lock a forum topic in the channel.
* @param forumTopic The forum topic to lock.
* @example topics.lock(forumTopic);
*/
lock(forumTopic) {
forumTopic = forumTopic instanceof ForumTopic_1.ForumTopic ? forumTopic.id : forumTopic;
return this.client.api.forumTopics.lock(this.channel.id, forumTopic);
}
/**
* Unlock a forum topic in the channel.
* @param forumTopic The forum topic to unlock.
* @example topics.unlock(forumTopic);
*/
unlock(forumTopic) {
forumTopic = forumTopic instanceof ForumTopic_1.ForumTopic ? forumTopic.id : forumTopic;
return this.client.api.forumTopics.unlock(this.channel.id, forumTopic);
}
}
exports.ForumTopicManager = ForumTopicManager;
//# sourceMappingURL=ForumTopicManager.js.map