mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 12:36:08 +00:00
Merge branch 'main' of https://github.com/tiramisulabs/seyfert
This commit is contained in:
commit
84806f3c54
@ -1,15 +1,16 @@
|
||||
import { CacheFrom } from '../..';
|
||||
import type { ThreadChannelStructure } from '../../client/transformers';
|
||||
import { channelFrom } from '../../structures';
|
||||
import type {
|
||||
APIThreadChannel,
|
||||
APIThreadMember,
|
||||
RESTGetAPIChannelThreadMembersQuery,
|
||||
RESTGetAPIChannelThreadsArchivedQuery,
|
||||
RESTPatchAPIChannelJSONBody,
|
||||
RESTPostAPIChannelMessagesThreadsJSONBody,
|
||||
RESTPostAPIChannelThreadsJSONBody,
|
||||
RESTPostAPIGuildForumThreadsJSONBody,
|
||||
import {
|
||||
type APIThreadChannel,
|
||||
type APIThreadMember,
|
||||
ChannelType,
|
||||
type RESTGetAPIChannelThreadMembersQuery,
|
||||
type RESTGetAPIChannelThreadsArchivedQuery,
|
||||
type RESTPatchAPIChannelJSONBody,
|
||||
type RESTPostAPIChannelMessagesThreadsJSONBody,
|
||||
type RESTPostAPIChannelThreadsJSONBody,
|
||||
type RESTPostAPIGuildForumThreadsJSONBody,
|
||||
} from '../../types';
|
||||
import type { MakeRequired, When } from '../types/util';
|
||||
import { BaseShorter } from './base';
|
||||
@ -44,27 +45,22 @@ export class ThreadShorter extends BaseShorter {
|
||||
);
|
||||
}
|
||||
|
||||
fromMessage(
|
||||
async fromMessage(
|
||||
channelId: string,
|
||||
messageId: string,
|
||||
options: RESTPostAPIChannelMessagesThreadsJSONBody & { reason?: string },
|
||||
): Promise<ThreadChannelStructure> {
|
||||
const { reason, ...body } = options;
|
||||
|
||||
return this.client.proxy
|
||||
.channels(channelId)
|
||||
.messages(messageId)
|
||||
.threads.post({ body, reason })
|
||||
.then(async thread => {
|
||||
await this.client.cache.channels?.setIfNI(
|
||||
CacheFrom.Rest,
|
||||
'Guilds',
|
||||
thread.id,
|
||||
(thread as APIThreadChannel).guild_id!,
|
||||
thread,
|
||||
);
|
||||
return channelFrom(thread, this.client) as ThreadChannelStructure;
|
||||
});
|
||||
const thread = await this.client.proxy.channels(channelId).messages(messageId).threads.post({ body, reason });
|
||||
await this.client.cache.channels?.setIfNI(
|
||||
CacheFrom.Rest,
|
||||
'Guilds',
|
||||
thread.id,
|
||||
(thread as APIThreadChannel).guild_id!,
|
||||
thread,
|
||||
);
|
||||
return await (channelFrom(thread, this.client) as ThreadChannelStructure);
|
||||
}
|
||||
|
||||
join(threadId: string) {
|
||||
@ -75,8 +71,9 @@ export class ThreadShorter extends BaseShorter {
|
||||
return this.client.proxy.channels(threadId)['thread-members']('@me').delete();
|
||||
}
|
||||
|
||||
lock(threadId: string, locked = true, reason?: string): Promise<ThreadChannelStructure> {
|
||||
return this.edit(threadId, { locked }, reason).then(x => channelFrom(x, this.client) as ThreadChannelStructure);
|
||||
async lock(threadId: string, locked = true, reason?: string): Promise<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> {
|
||||
@ -110,7 +107,7 @@ export class ThreadShorter extends BaseShorter {
|
||||
return this.client.proxy.channels(threadId)['thread-members'].get({ query }) as never;
|
||||
}
|
||||
|
||||
async listArchivedThreads(
|
||||
async listArchived(
|
||||
channelId: string,
|
||||
type: 'public' | 'private',
|
||||
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(
|
||||
channelId: string,
|
||||
query?: RESTGetAPIChannelThreadsArchivedQuery,
|
||||
|
@ -14,6 +14,7 @@ export const LangRouter = (userLocale: string, defaultLang: string, langs: Parti
|
||||
function getValue(locale?: string) {
|
||||
if (typeof locale === 'undefined') throw new Error('Undefined locale');
|
||||
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];
|
||||
return value;
|
||||
}
|
||||
@ -51,4 +52,4 @@ export type __InternalParseLocale<T extends Record<string, any>> = {
|
||||
};
|
||||
|
||||
export type ParseLocales<T extends Record<string, any>> = T;
|
||||
/**Idea inspiration from: FreeAoi */
|
||||
/**Idea inspiration from: FreeAoi | Fixed by: Drylozu */
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { GuildMemberStructure, GuildStructure } from '../client';
|
||||
import type { GuildMemberStructure, GuildStructure, ThreadChannelStructure } from '../client';
|
||||
import type { UsingClient } from '../commands';
|
||||
import type { CreateInviteFromChannel } from '../common';
|
||||
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);
|
||||
}
|
||||
|
||||
async listActiveThreads(force = false): Promise<ThreadChannelStructure[]> {
|
||||
return this.client.threads.listGuildActive(this.id, force);
|
||||
}
|
||||
|
||||
templates = GuildTemplate.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 });
|
||||
|
Loading…
x
Reference in New Issue
Block a user