Update ThreadManager.js
This commit is contained in:
parent
11d6cef551
commit
37d3b4aa33
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
const { Collection } = require('@discordjs/collection');
|
const { Collection } = require('@discordjs/collection');
|
||||||
const CachedManager = require('./CachedManager');
|
const CachedManager = require('./CachedManager');
|
||||||
const { TypeError } = require('../errors');
|
|
||||||
const ThreadChannel = require('../structures/ThreadChannel');
|
const ThreadChannel = require('../structures/ThreadChannel');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,35 +118,9 @@ class ThreadManager extends CachedManager {
|
|||||||
* @param {boolean} [cache=true] Whether to cache the new thread objects if they aren't already
|
* @param {boolean} [cache=true] Whether to cache the new thread objects if they aren't already
|
||||||
* @returns {Promise<FetchedThreads>}
|
* @returns {Promise<FetchedThreads>}
|
||||||
*/
|
*/
|
||||||
async fetchArchived(options = {}, cache = true) {
|
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 });
|
return this.fetchActive(cache, { archived: true, ...options });
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Discord.js self-bot specific options field for fetching active threads.
|
* Discord.js self-bot specific options field for fetching active threads.
|
||||||
@ -165,14 +138,8 @@ class ThreadManager extends CachedManager {
|
|||||||
* @param {FetchChannelThreadsOptions} [options] Options for self-bots where advanced users can specify further options
|
* @param {FetchChannelThreadsOptions} [options] Options for self-bots where advanced users can specify further options
|
||||||
* @returns {Promise<FetchedThreads>}
|
* @returns {Promise<FetchedThreads>}
|
||||||
*/
|
*/
|
||||||
async fetchActive(cache = true, options = null) {
|
async fetchActive(cache = true, options = {}) {
|
||||||
if (options && this.client.user.bot) {
|
const raw = await this.client.api.channels(this.channel.id).threads.search.get({
|
||||||
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: {
|
query: {
|
||||||
archived: options?.archived ?? false,
|
archived: options?.archived ?? false,
|
||||||
limit: options?.limit ?? 25,
|
limit: options?.limit ?? 25,
|
||||||
|
Loading…
Reference in New Issue
Block a user