This commit is contained in:
MARCROCK22 2025-06-13 13:30:49 -04:00
commit 84806f3c54
3 changed files with 50 additions and 29 deletions

View File

@ -1,15 +1,16 @@
import { CacheFrom } from '../..'; import { CacheFrom } from '../..';
import type { ThreadChannelStructure } from '../../client/transformers'; import type { ThreadChannelStructure } from '../../client/transformers';
import { channelFrom } from '../../structures'; import { channelFrom } from '../../structures';
import type { import {
APIThreadChannel, type APIThreadChannel,
APIThreadMember, type APIThreadMember,
RESTGetAPIChannelThreadMembersQuery, ChannelType,
RESTGetAPIChannelThreadsArchivedQuery, type RESTGetAPIChannelThreadMembersQuery,
RESTPatchAPIChannelJSONBody, type RESTGetAPIChannelThreadsArchivedQuery,
RESTPostAPIChannelMessagesThreadsJSONBody, type RESTPatchAPIChannelJSONBody,
RESTPostAPIChannelThreadsJSONBody, type RESTPostAPIChannelMessagesThreadsJSONBody,
RESTPostAPIGuildForumThreadsJSONBody, type RESTPostAPIChannelThreadsJSONBody,
type RESTPostAPIGuildForumThreadsJSONBody,
} from '../../types'; } from '../../types';
import type { MakeRequired, When } from '../types/util'; import type { MakeRequired, When } from '../types/util';
import { BaseShorter } from './base'; import { BaseShorter } from './base';
@ -44,18 +45,14 @@ export class ThreadShorter extends BaseShorter {
); );
} }
fromMessage( async fromMessage(
channelId: string, channelId: string,
messageId: string, messageId: string,
options: RESTPostAPIChannelMessagesThreadsJSONBody & { reason?: string }, options: RESTPostAPIChannelMessagesThreadsJSONBody & { reason?: string },
): Promise<ThreadChannelStructure> { ): Promise<ThreadChannelStructure> {
const { reason, ...body } = options; const { reason, ...body } = options;
return this.client.proxy const thread = await this.client.proxy.channels(channelId).messages(messageId).threads.post({ body, reason });
.channels(channelId)
.messages(messageId)
.threads.post({ body, reason })
.then(async thread => {
await this.client.cache.channels?.setIfNI( await this.client.cache.channels?.setIfNI(
CacheFrom.Rest, CacheFrom.Rest,
'Guilds', 'Guilds',
@ -63,8 +60,7 @@ export class ThreadShorter extends BaseShorter {
(thread as APIThreadChannel).guild_id!, (thread as APIThreadChannel).guild_id!,
thread, thread,
); );
return channelFrom(thread, this.client) as ThreadChannelStructure; return await (channelFrom(thread, this.client) as ThreadChannelStructure);
});
} }
join(threadId: string) { join(threadId: string) {
@ -75,8 +71,9 @@ export class ThreadShorter extends BaseShorter {
return this.client.proxy.channels(threadId)['thread-members']('@me').delete(); return this.client.proxy.channels(threadId)['thread-members']('@me').delete();
} }
lock(threadId: string, locked = true, reason?: string): Promise<ThreadChannelStructure> { async lock(threadId: string, locked = true, reason?: string): Promise<ThreadChannelStructure> {
return this.edit(threadId, { locked }, reason).then(x => channelFrom(x, this.client) as ThreadChannelStructure); const x = await this.edit(threadId, { locked }, reason);
return channelFrom(x, this.client) as ThreadChannelStructure;
} }
async edit(threadId: string, body: RESTPatchAPIChannelJSONBody, reason?: string): Promise<ThreadChannelStructure> { async edit(threadId: string, body: RESTPatchAPIChannelJSONBody, reason?: string): Promise<ThreadChannelStructure> {
@ -110,7 +107,7 @@ export class ThreadShorter extends BaseShorter {
return this.client.proxy.channels(threadId)['thread-members'].get({ query }) as never; return this.client.proxy.channels(threadId)['thread-members'].get({ query }) as never;
} }
async listArchivedThreads( async listArchived(
channelId: string, channelId: string,
type: 'public' | 'private', type: 'public' | 'private',
query?: RESTGetAPIChannelThreadsArchivedQuery, query?: RESTGetAPIChannelThreadsArchivedQuery,
@ -128,6 +125,25 @@ export class ThreadShorter extends BaseShorter {
}; };
} }
async listGuildActive(guildId: string, force = false): Promise<ThreadChannelStructure[]> {
if (!force) {
const cached = await this.client.cache.channels?.valuesRaw(guildId);
if (cached)
return cached
.filter(x =>
[ChannelType.PublicThread, ChannelType.PrivateThread, ChannelType.AnnouncementThread].includes(x.type),
)
.map(x => channelFrom(x, this.client) as ThreadChannelStructure);
}
const data = await this.client.proxy.guilds(guildId).threads.active.get();
return Promise.all(
data.threads.map(async thread => {
await this.client.cache.channels?.setIfNI(CacheFrom.Rest, 'Guilds', thread.id, guildId, thread);
return channelFrom(thread, this.client) as ThreadChannelStructure;
}),
);
}
async listJoinedArchivedPrivate( async listJoinedArchivedPrivate(
channelId: string, channelId: string,
query?: RESTGetAPIChannelThreadsArchivedQuery, query?: RESTGetAPIChannelThreadsArchivedQuery,

View File

@ -14,6 +14,7 @@ export const LangRouter = (userLocale: string, defaultLang: string, langs: Parti
function getValue(locale?: string) { function getValue(locale?: string) {
if (typeof locale === 'undefined') throw new Error('Undefined locale'); if (typeof locale === 'undefined') throw new Error('Undefined locale');
let value = langs[locale] as Record<string, any>; let value = langs[locale] as Record<string, any>;
if (typeof value === 'undefined') throw new Error(`Locale "${locale}" not found`);
for (const i of route) value = value[i]; for (const i of route) value = value[i];
return value; return value;
} }
@ -51,4 +52,4 @@ export type __InternalParseLocale<T extends Record<string, any>> = {
}; };
export type ParseLocales<T extends Record<string, any>> = T; export type ParseLocales<T extends Record<string, any>> = T;
/**Idea inspiration from: FreeAoi */ /**Idea inspiration from: FreeAoi | Fixed by: Drylozu */

View File

@ -1,4 +1,4 @@
import type { GuildMemberStructure, GuildStructure } from '../client'; import type { GuildMemberStructure, GuildStructure, ThreadChannelStructure } from '../client';
import type { UsingClient } from '../commands'; import type { UsingClient } from '../commands';
import type { CreateInviteFromChannel } from '../common'; import type { CreateInviteFromChannel } from '../common';
import type { ObjectToLower, StructPropState, StructStates, ToClass } from '../common/types/util'; import type { ObjectToLower, StructPropState, StructStates, ToClass } from '../common/types/util';
@ -71,6 +71,10 @@ export class Guild<State extends StructStates = 'api'> extends (BaseGuild as unk
return this.members.fetch(this.ownerId, force); return this.members.fetch(this.ownerId, force);
} }
async listActiveThreads(force = false): Promise<ThreadChannelStructure[]> {
return this.client.threads.listGuildActive(this.id, force);
}
templates = GuildTemplate.methods({ client: this.client, guildId: this.id }); templates = GuildTemplate.methods({ client: this.client, guildId: this.id });
stickers = Sticker.methods({ client: this.client, guildId: this.id }); stickers = Sticker.methods({ client: this.client, guildId: this.id });
members = GuildMember.methods({ client: this.client, guildId: this.id }); members = GuildMember.methods({ client: this.client, guildId: this.id });