mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-04 05:56:09 +00:00
fix: types
This commit is contained in:
parent
a9d14c4c01
commit
0c1ef3777f
@ -9,6 +9,20 @@ import type { RestArguments } from '../api';
|
|||||||
export interface InteractionRoutes {
|
export interface InteractionRoutes {
|
||||||
interactions: (id: string) => (token: string) => {
|
interactions: (id: string) => (token: string) => {
|
||||||
callback: {
|
callback: {
|
||||||
|
post(
|
||||||
|
args: RestArguments<
|
||||||
|
ProxyRequestMethod.Post,
|
||||||
|
RESTPostAPIInteractionCallbackJSONBody,
|
||||||
|
Omit<RESTPostAPIInteractionCallbackQuery, 'with_response'> & { with_response: true }
|
||||||
|
>,
|
||||||
|
): Promise<RESTPostAPIInteractionCallbackResult>;
|
||||||
|
post(
|
||||||
|
args: RestArguments<
|
||||||
|
ProxyRequestMethod.Post,
|
||||||
|
RESTPostAPIInteractionCallbackJSONBody,
|
||||||
|
Omit<RESTPostAPIInteractionCallbackQuery, 'with_response'> & { with_response: false }
|
||||||
|
>,
|
||||||
|
): Promise<undefined>;
|
||||||
post(
|
post(
|
||||||
args: RestArguments<
|
args: RestArguments<
|
||||||
ProxyRequestMethod.Post,
|
ProxyRequestMethod.Post,
|
||||||
|
@ -6,6 +6,7 @@ import type {
|
|||||||
Command,
|
Command,
|
||||||
CommandContext,
|
CommandContext,
|
||||||
ContextMenuCommand,
|
ContextMenuCommand,
|
||||||
|
EntryPointCommand,
|
||||||
ExtraProps,
|
ExtraProps,
|
||||||
MenuCommandContext,
|
MenuCommandContext,
|
||||||
RegisteredMiddlewares,
|
RegisteredMiddlewares,
|
||||||
@ -319,10 +320,12 @@ export class BaseClient {
|
|||||||
BaseClient.assertString(applicationId, 'applicationId is not a string');
|
BaseClient.assertString(applicationId, 'applicationId is not a string');
|
||||||
|
|
||||||
const commands = this.commands!.values;
|
const commands = this.commands!.values;
|
||||||
const filter = filterSplit(commands, command => !command.guildId);
|
const filter = filterSplit<
|
||||||
|
Omit<Command | ContextMenuCommand, 'guildId'> | EntryPointCommand,
|
||||||
|
MakeRequired<Command | ContextMenuCommand, 'guildId'>
|
||||||
|
>(commands, command => ('guildId' in command ? !command.guildId : true));
|
||||||
|
|
||||||
if (this.commands?.entryPoint) {
|
if (this.commands?.entryPoint) {
|
||||||
// @ts-expect-error
|
|
||||||
filter.expect.push(this.commands.entryPoint);
|
filter.expect.push(this.commands.entryPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,7 +339,7 @@ export class BaseClient {
|
|||||||
const guilds = new Set<string>();
|
const guilds = new Set<string>();
|
||||||
|
|
||||||
for (const command of filter.never) {
|
for (const command of filter.never) {
|
||||||
for (const guild_id of command.guildId!) {
|
for (const guild_id of command.guildId) {
|
||||||
guilds.add(guild_id);
|
guilds.add(guild_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -349,7 +352,7 @@ export class BaseClient {
|
|||||||
.commands.put({
|
.commands.put({
|
||||||
body: filter.never
|
body: filter.never
|
||||||
.filter(
|
.filter(
|
||||||
cmd => cmd.guildId?.includes(guildId) && (!('ignore' in cmd) || cmd.ignore !== IgnoreCommand.Slash),
|
cmd => cmd.guildId.includes(guildId) && (!('ignore' in cmd) || cmd.ignore !== IgnoreCommand.Slash),
|
||||||
)
|
)
|
||||||
.map(x => x.toJSON()),
|
.map(x => x.toJSON()),
|
||||||
});
|
});
|
||||||
|
@ -79,7 +79,7 @@ export class EntryPointContext<M extends keyof RegisteredMiddlewares = never> ex
|
|||||||
channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
|
channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
|
||||||
channel(mode?: 'cache'): ReturnCache<AllChannels>;
|
channel(mode?: 'cache'): ReturnCache<AllChannels>;
|
||||||
channel(mode: 'cache' | 'rest' | 'flow' = 'cache') {
|
channel(mode: 'cache' | 'rest' | 'flow' = 'cache') {
|
||||||
if (this.interaction?.channel && mode === 'cache')
|
if (this.interaction.channel && mode === 'cache')
|
||||||
return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
|
return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
|
||||||
return this.client.channels.fetch(this.channelId, mode === 'rest');
|
return this.client.channels.fetch(this.channelId, mode === 'rest');
|
||||||
}
|
}
|
||||||
|
@ -96,14 +96,17 @@ export function MergeOptions<T>(defaults: any, ...options: any[]): T {
|
|||||||
* @param func The predicate function used to test elements of the array.
|
* @param func The predicate function used to test elements of the array.
|
||||||
* @returns An object containing two arrays: one with elements that passed the test and one with elements that did not.
|
* @returns An object containing two arrays: one with elements that passed the test and one with elements that did not.
|
||||||
*/
|
*/
|
||||||
export function filterSplit<Element, Predicate extends (value: Element) => boolean>(arr: Element[], func: Predicate) {
|
export function filterSplit<Element, Never = Element>(
|
||||||
|
arr: (Element | Never)[],
|
||||||
|
func: (value: Element | Never) => boolean,
|
||||||
|
) {
|
||||||
const expect: Element[] = [];
|
const expect: Element[] = [];
|
||||||
const never: Element[] = [];
|
const never: Never[] = [];
|
||||||
|
|
||||||
for (const element of arr) {
|
for (const element of arr) {
|
||||||
const test = func(element);
|
const test = func(element);
|
||||||
if (test) expect.push(element);
|
if (test) expect.push(element as Element);
|
||||||
else never.push(element);
|
else never.push(element as Never);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { expect, never };
|
return { expect, never };
|
||||||
|
@ -39,7 +39,6 @@ import {
|
|||||||
type APIEntryPointCommandInteraction,
|
type APIEntryPointCommandInteraction,
|
||||||
type InteractionCallbackData,
|
type InteractionCallbackData,
|
||||||
type InteractionCallbackResourceActivity,
|
type InteractionCallbackResourceActivity,
|
||||||
type RESTPostAPIInteractionCallbackResult,
|
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
import type { RawFile } from '../api';
|
import type { RawFile } from '../api';
|
||||||
@ -509,12 +508,12 @@ export class EntryPointInteraction<FromGuild extends boolean = boolean> extends
|
|||||||
files = files ? await resolveFiles(files) : undefined;
|
files = files ? await resolveFiles(files) : undefined;
|
||||||
body = BaseInteraction.transformBody(rest, files, this.client);
|
body = BaseInteraction.transformBody(rest, files, this.client);
|
||||||
}
|
}
|
||||||
const response = (await this.client.proxy
|
const response = await this.client.proxy
|
||||||
.interactions(this.id)(this.token)
|
.interactions(this.id)(this.token)
|
||||||
.callback.post({
|
.callback.post({
|
||||||
body,
|
body,
|
||||||
query: { with_response: true },
|
query: { with_response: true },
|
||||||
})) as RESTPostAPIInteractionCallbackResult;
|
});
|
||||||
|
|
||||||
const result: Partial<EntryPointWithResponseResult> = {
|
const result: Partial<EntryPointWithResponseResult> = {
|
||||||
interaction: toCamelCase(response.interaction),
|
interaction: toCamelCase(response.interaction),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user