From 37d3b4aa3307c407b2f83bc52bf49cbaadee8f7e Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Thu, 11 Jan 2024 18:11:17 +0700 Subject: [PATCH] Update ThreadManager.js --- src/managers/ThreadManager.js | 57 ++++++++--------------------------- 1 file changed, 12 insertions(+), 45 deletions(-) diff --git a/src/managers/ThreadManager.js b/src/managers/ThreadManager.js index a9c6dd1..aa096f7 100644 --- a/src/managers/ThreadManager.js +++ b/src/managers/ThreadManager.js @@ -2,7 +2,6 @@ const { Collection } = require('@discordjs/collection'); const CachedManager = require('./CachedManager'); -const { TypeError } = require('../errors'); const ThreadChannel = require('../structures/ThreadChannel'); /** @@ -119,34 +118,8 @@ class ThreadManager extends CachedManager { * @param {boolean} [cache=true] Whether to cache the new thread objects if they aren't already * @returns {Promise} */ - async fetchArchived(options = {}, cache = true) { - if (this.client.user.bot) { - let { type = 'public', fetchAll = false, before, limit } = options; - let path = this.client.api.channels(this.channel.id); - if (type === 'private' && !fetchAll) { - path = path.users('@me'); - } - let timestamp; - let id; - if (typeof before !== 'undefined') { - if (before instanceof ThreadChannel || /^\d{17,19}$/.test(String(before))) { - id = this.resolveId(before); - timestamp = this.resolve(before)?.archivedAt?.toISOString(); - } else { - try { - timestamp = new Date(before).toISOString(); - } catch { - throw new TypeError('INVALID_TYPE', 'before', 'DateResolvable or ThreadChannelResolvable'); - } - } - } - const raw = await path.threads - .archived(type) - .get({ query: { before: type === 'private' && !fetchAll ? id : timestamp, limit } }); - return this.constructor._mapThreads(raw, this.client, { parent: this.channel, cache }); - } else { - return this.fetchActive(cache, { archived: true, ...options }); - } + fetchArchived(options = {}, cache = true) { + return this.fetchActive(cache, { archived: true, ...options }); } /** @@ -165,22 +138,16 @@ class ThreadManager extends CachedManager { * @param {FetchChannelThreadsOptions} [options] Options for self-bots where advanced users can specify further options * @returns {Promise} */ - async fetchActive(cache = true, options = null) { - if (options && this.client.user.bot) { - throw new Error('INVALID_BOT_OPTIONS: Options can only be specified for user accounts.'); - } - - const raw = this.client.user.bot - ? await this.client.api.guilds(this.channel.guild.id).threads.active.get() - : await this.client.api.channels(this.channel.id).threads.search.get({ - query: { - archived: options?.archived ?? false, - limit: options?.limit ?? 25, - offset: options?.offset ?? 0, - sort_by: options?.sortBy ?? 'last_message_time', - sort_order: options?.sortOrder ?? 'desc', - }, - }); + async fetchActive(cache = true, options = {}) { + const raw = await this.client.api.channels(this.channel.id).threads.search.get({ + query: { + archived: options?.archived ?? false, + limit: options?.limit ?? 25, + offset: options?.offset ?? 0, + sort_by: options?.sortBy ?? 'last_message_time', + sort_order: options?.sortOrder ?? 'desc', + }, + }); return this.constructor._mapThreads(raw, this.client, { parent: this.channel, cache }); }