mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
feat: voiceStateShorter (#286)
This commit is contained in:
parent
86e66c706b
commit
db9e319545
@ -42,6 +42,7 @@ import {
|
||||
import { promises } from 'node:fs';
|
||||
import { HandleCommand } from '../commands/handle';
|
||||
import { BanShorter } from '../common/shorters/bans';
|
||||
import { VoiceStateShorter } from '../common/shorters/voiceStates';
|
||||
import type { Awaitable, DeepPartial, IntentStrings, OmitInsert, PermissionStrings, When } from '../common/types/util';
|
||||
import type { ComponentCommand, ComponentContext, ModalCommand, ModalContext } from '../components';
|
||||
import { ComponentHandler } from '../components/handler';
|
||||
@ -75,6 +76,7 @@ export class BaseClient {
|
||||
threads = new ThreadShorter(this);
|
||||
bans = new BanShorter(this);
|
||||
interactions = new InteractionShorter(this);
|
||||
voiceStates = new VoiceStateShorter(this);
|
||||
|
||||
debugger?: Logger;
|
||||
|
||||
|
@ -136,11 +136,10 @@ export class CommandContext<
|
||||
}
|
||||
|
||||
async fetchResponse(): Promise<
|
||||
If<InferWithPrefix, WebhookMessageStructure | MessageStructure | undefined, WebhookMessageStructure | undefined>
|
||||
If<InferWithPrefix, WebhookMessageStructure | MessageStructure, WebhookMessageStructure>
|
||||
> {
|
||||
if (this.interaction) return this.interaction.fetchResponse();
|
||||
this.messageResponse = await this.messageResponse?.fetch();
|
||||
return this.messageResponse as undefined;
|
||||
return (this.messageResponse = (await this.messageResponse!.fetch()) as never);
|
||||
}
|
||||
|
||||
channel(mode?: 'rest' | 'flow'): Promise<If<InferWithPrefix, AllChannels | undefined, AllChannels>>;
|
||||
|
@ -1,17 +1,11 @@
|
||||
import type { ReturnCache } from '../..';
|
||||
import type {
|
||||
GuildMemberStructure,
|
||||
GuildStructure,
|
||||
MessageStructure,
|
||||
WebhookMessageStructure,
|
||||
} from '../../client/transformers';
|
||||
import type { GuildMemberStructure, GuildStructure } from '../../client/transformers';
|
||||
import type {
|
||||
InteractionCreateBodyRequest,
|
||||
InteractionMessageUpdateBodyRequest,
|
||||
MakeRequired,
|
||||
ModalCreateBodyRequest,
|
||||
UnionToTuple,
|
||||
When,
|
||||
} from '../../common';
|
||||
import type { AllChannels, EntryPointInteraction } from '../../structures';
|
||||
import { MessageFlags } from '../../types';
|
||||
@ -43,22 +37,16 @@ export class EntryPointContext<M extends keyof RegisteredMiddlewares = never> ex
|
||||
return this.command.name;
|
||||
}
|
||||
|
||||
write<WR extends boolean = false>(
|
||||
body: InteractionCreateBodyRequest,
|
||||
withResponse?: WR,
|
||||
): Promise<When<WR, WebhookMessageStructure, void | WebhookMessageStructure>> {
|
||||
return this.interaction.write(body, withResponse);
|
||||
write<WR extends boolean = false>(body: InteractionCreateBodyRequest, withResponse?: WR) {
|
||||
return this.interaction.write<WR>(body, withResponse);
|
||||
}
|
||||
|
||||
modal(body: ModalCreateBodyRequest) {
|
||||
return this.interaction.modal(body);
|
||||
}
|
||||
|
||||
deferReply<WR extends boolean = false>(
|
||||
ephemeral = false,
|
||||
withResponse?: WR,
|
||||
): Promise<When<WR, WebhookMessageStructure, undefined>> {
|
||||
return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined, withResponse);
|
||||
deferReply<WR extends boolean = false>(ephemeral = false, withResponse?: WR) {
|
||||
return this.interaction.deferReply<WR>(ephemeral ? MessageFlags.Ephemeral : undefined, withResponse);
|
||||
}
|
||||
|
||||
editResponse(body: InteractionMessageUpdateBodyRequest) {
|
||||
@ -72,8 +60,8 @@ export class EntryPointContext<M extends keyof RegisteredMiddlewares = never> ex
|
||||
editOrReply<WR extends boolean = false>(
|
||||
body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest,
|
||||
withResponse?: WR,
|
||||
): Promise<When<WR, WebhookMessageStructure | MessageStructure, void | WebhookMessageStructure | MessageStructure>> {
|
||||
return this.interaction.editOrReply(body as InteractionCreateBodyRequest, withResponse);
|
||||
) {
|
||||
return this.interaction.editOrReply<WR>(body as InteractionCreateBodyRequest, withResponse);
|
||||
}
|
||||
|
||||
fetchResponse() {
|
||||
|
@ -5,7 +5,6 @@ import {
|
||||
type MessageStructure,
|
||||
Transformers,
|
||||
type UserStructure,
|
||||
type WebhookMessageStructure,
|
||||
} from '../../client/transformers';
|
||||
import {
|
||||
type InteractionCreateBodyRequest,
|
||||
@ -13,7 +12,6 @@ import {
|
||||
type MakeRequired,
|
||||
type ModalCreateBodyRequest,
|
||||
type UnionToTuple,
|
||||
type When,
|
||||
toSnakeCase,
|
||||
} from '../../common';
|
||||
import type { AllChannels, MessageCommandInteraction, UserCommandInteraction } from '../../structures';
|
||||
@ -68,22 +66,16 @@ export class MenuCommandContext<
|
||||
return this.command.name;
|
||||
}
|
||||
|
||||
write<WR extends boolean = false>(
|
||||
body: InteractionCreateBodyRequest,
|
||||
withResponse?: WR,
|
||||
): Promise<When<WR, WebhookMessageStructure, void | WebhookMessageStructure>> {
|
||||
return this.interaction.write(body, withResponse);
|
||||
write<WR extends boolean = false>(body: InteractionCreateBodyRequest, withResponse?: WR) {
|
||||
return this.interaction.write<WR>(body, withResponse);
|
||||
}
|
||||
|
||||
modal(body: ModalCreateBodyRequest) {
|
||||
return this.interaction.modal(body);
|
||||
}
|
||||
|
||||
deferReply<WR extends boolean = false>(
|
||||
ephemeral = false,
|
||||
withResponse?: WR,
|
||||
): Promise<When<WR, WebhookMessageStructure, undefined>> {
|
||||
return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined, withResponse);
|
||||
deferReply<WR extends boolean = false>(ephemeral = false, withResponse?: WR) {
|
||||
return this.interaction.deferReply<WR>(ephemeral ? MessageFlags.Ephemeral : undefined, withResponse);
|
||||
}
|
||||
|
||||
editResponse(body: InteractionMessageUpdateBodyRequest) {
|
||||
@ -97,8 +89,8 @@ export class MenuCommandContext<
|
||||
editOrReply<WR extends boolean = false>(
|
||||
body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest,
|
||||
withResponse?: WR,
|
||||
): Promise<When<WR, WebhookMessageStructure | MessageStructure, void | WebhookMessageStructure | MessageStructure>> {
|
||||
return this.interaction.editOrReply(body as InteractionCreateBodyRequest, withResponse);
|
||||
) {
|
||||
return this.interaction.editOrReply<WR>(body as InteractionCreateBodyRequest, withResponse);
|
||||
}
|
||||
|
||||
fetchResponse() {
|
||||
|
15
src/common/shorters/voiceStates.ts
Normal file
15
src/common/shorters/voiceStates.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { BaseShorter } from './base';
|
||||
|
||||
export class VoiceStateShorter extends BaseShorter {
|
||||
requestSpeak(guildId: string, date: string) {
|
||||
return this.client.proxy.guilds(guildId)['voice-states']['@me'].patch({
|
||||
body: { request_to_speak_timestamp: date },
|
||||
});
|
||||
}
|
||||
|
||||
setSuppress(guildId: string, suppress: boolean) {
|
||||
return this.client.proxy.guilds(guildId)['voice-states']['@me'].patch({
|
||||
body: { suppress },
|
||||
});
|
||||
}
|
||||
}
|
@ -140,14 +140,14 @@ export class WebhookShorter extends BaseShorter {
|
||||
* @param token The token of the webhook.
|
||||
* @param messageId The ID of the message to fetch.
|
||||
* @param threadId The ID of the thread the message belongs to.
|
||||
* @returns A Promise that resolves to the fetched message, or undefined if not found.
|
||||
* @returns A Promise that resolves to the fetched message
|
||||
*/
|
||||
async fetchMessage(webhookId: string, token: string, messageId: string, threadId?: string) {
|
||||
const message = await this.client.proxy
|
||||
.webhooks(webhookId)(token)
|
||||
.messages(messageId)
|
||||
.get({ auth: false, query: threadId ? { thread_id: threadId } : undefined });
|
||||
return message ? Transformers.WebhookMessage(this.client, message, webhookId, token) : undefined;
|
||||
return Transformers.WebhookMessage(this.client, message, webhookId, token);
|
||||
}
|
||||
|
||||
async listFromGuild(guildId: string) {
|
||||
|
@ -9,12 +9,7 @@ import type {
|
||||
StringSelectMenuInteraction,
|
||||
UserSelectMenuInteraction,
|
||||
} from '..';
|
||||
import type {
|
||||
GuildMemberStructure,
|
||||
GuildStructure,
|
||||
MessageStructure,
|
||||
WebhookMessageStructure,
|
||||
} from '../client/transformers';
|
||||
import type { GuildMemberStructure, GuildStructure } from '../client/transformers';
|
||||
import type { CommandMetadata, ExtendContext, GlobalMetadata, RegisteredMiddlewares, UsingClient } from '../commands';
|
||||
import { BaseContext } from '../commands/basecontext';
|
||||
import type {
|
||||
@ -24,7 +19,6 @@ import type {
|
||||
MakeRequired,
|
||||
ModalCreateBodyRequest,
|
||||
UnionToTuple,
|
||||
When,
|
||||
} from '../common';
|
||||
import { ComponentType, MessageFlags } from '../types';
|
||||
|
||||
@ -77,15 +71,15 @@ export class ComponentContext<
|
||||
* @param fetchReply - Whether to fetch the reply or not.
|
||||
*/
|
||||
write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR) {
|
||||
return this.interaction.write(body, fetchReply);
|
||||
return this.interaction.write<FR>(body, fetchReply);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defers the reply to the interaction.
|
||||
* @param ephemeral - Whether the reply should be ephemeral or not.
|
||||
*/
|
||||
deferReply(ephemeral = false) {
|
||||
return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined);
|
||||
deferReply<FR extends boolean = false>(ephemeral = false, fetchReply?: FR) {
|
||||
return this.interaction.deferReply<FR>(ephemeral ? MessageFlags.Ephemeral : undefined, fetchReply);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,8 +113,15 @@ export class ComponentContext<
|
||||
editOrReply<FR extends boolean = false>(
|
||||
body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest,
|
||||
fetchReply?: FR,
|
||||
): Promise<When<FR, WebhookMessageStructure | MessageStructure, void | WebhookMessageStructure | MessageStructure>> {
|
||||
return this.interaction.editOrReply(body as InteractionCreateBodyRequest, fetchReply);
|
||||
) {
|
||||
return this.interaction.editOrReply<FR>(body as InteractionCreateBodyRequest, fetchReply);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns A Promise that resolves to the fetched message
|
||||
*/
|
||||
fetchResponse() {
|
||||
return this.interaction.fetchResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,10 +1,5 @@
|
||||
import type { AllChannels, ModalCommand, ModalSubmitInteraction, ReturnCache } from '..';
|
||||
import type {
|
||||
GuildMemberStructure,
|
||||
GuildStructure,
|
||||
MessageStructure,
|
||||
WebhookMessageStructure,
|
||||
} from '../client/transformers';
|
||||
import type { GuildMemberStructure, GuildStructure } from '../client/transformers';
|
||||
import type { CommandMetadata, ExtendContext, GlobalMetadata, RegisteredMiddlewares, UsingClient } from '../commands';
|
||||
import { BaseContext } from '../commands/basecontext';
|
||||
import type {
|
||||
@ -13,7 +8,6 @@ import type {
|
||||
MakeRequired,
|
||||
ModalCreateBodyRequest,
|
||||
UnionToTuple,
|
||||
When,
|
||||
} from '../common';
|
||||
import { MessageFlags } from '../types';
|
||||
|
||||
@ -61,15 +55,15 @@ export class ModalContext<M extends keyof RegisteredMiddlewares = never> extends
|
||||
* @param fetchReply - Whether to fetch the reply or not.
|
||||
*/
|
||||
write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR) {
|
||||
return this.interaction.write(body, fetchReply);
|
||||
return this.interaction.write<FR>(body, fetchReply);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defers the reply to the interaction.
|
||||
* @param ephemeral - Whether the reply should be ephemeral or not.
|
||||
*/
|
||||
deferReply(ephemeral = false) {
|
||||
return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined);
|
||||
deferReply<FR extends boolean = false>(ephemeral = false, fetchReply?: FR) {
|
||||
return this.interaction.deferReply<FR>(ephemeral ? MessageFlags.Ephemeral : undefined, fetchReply);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,8 +82,15 @@ export class ModalContext<M extends keyof RegisteredMiddlewares = never> extends
|
||||
editOrReply<FR extends boolean = false>(
|
||||
body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest,
|
||||
fetchReply?: FR,
|
||||
): Promise<When<FR, WebhookMessageStructure | MessageStructure, void | WebhookMessageStructure | MessageStructure>> {
|
||||
return this.interaction.editOrReply(body as InteractionCreateBodyRequest, fetchReply);
|
||||
) {
|
||||
return this.interaction.editOrReply<FR>(body as InteractionCreateBodyRequest, fetchReply);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns A Promise that resolves to the fetched message
|
||||
*/
|
||||
fetchResponse() {
|
||||
return this.interaction.fetchResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -173,8 +173,12 @@ export class WebhookMessage extends BaseMessage {
|
||||
super(client, data);
|
||||
}
|
||||
|
||||
fetchWebhook() {
|
||||
return this.client.webhooks.fetch(this.webhookId, this.webhookToken);
|
||||
}
|
||||
|
||||
fetch() {
|
||||
return this.api.webhooks(this.webhookId)(this.webhookToken).get();
|
||||
return this.client.webhooks.fetchMessage(this.webhookId, this.webhookToken, this.id, this.thread?.id);
|
||||
}
|
||||
|
||||
edit(body: EditMessageWebhook) {
|
||||
|
@ -48,9 +48,7 @@ export class VoiceState extends Base {
|
||||
}
|
||||
|
||||
async setSuppress(suppress = !this.suppress) {
|
||||
await this.client.proxy.guilds(this.guildId)['voice-states']['@me'].patch({
|
||||
body: { suppress },
|
||||
});
|
||||
await this.client.voiceStates.setSuppress(this.guildId, suppress);
|
||||
this.suppress = suppress;
|
||||
}
|
||||
|
||||
@ -58,10 +56,7 @@ export class VoiceState extends Base {
|
||||
if (typeof date === 'string') date = new Date(date);
|
||||
if (Number.isNaN(date)) return Promise.reject('Invalid date');
|
||||
date = date.toISOString();
|
||||
|
||||
await this.client.proxy.guilds(this.guildId)['voice-states']['@me'].patch({
|
||||
body: { request_to_speak_timestamp: date },
|
||||
});
|
||||
await this.client.voiceStates.requestSpeak(this.guildId, date);
|
||||
this.requestToSpeakTimestamp = date;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user