mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-04 05:56:09 +00:00
feat: allowedMentions client option
This commit is contained in:
parent
5ad5132fa5
commit
6110337704
@ -172,7 +172,13 @@ export async function resolveFiles(resources: (AttachmentBuilder | RawFile | Att
|
|||||||
* @param type - The type of the attachment data.
|
* @param type - The type of the attachment data.
|
||||||
* @returns The resolved attachment data.
|
* @returns The resolved attachment data.
|
||||||
*/
|
*/
|
||||||
export async function resolveAttachmentData(data: AttachmentResolvable, type: AttachmentDataType) {
|
export async function resolveAttachmentData(
|
||||||
|
data: AttachmentResolvable,
|
||||||
|
type: AttachmentDataType,
|
||||||
|
): Promise<{
|
||||||
|
data: AttachmentResolvable;
|
||||||
|
contentType?: string | null;
|
||||||
|
}> {
|
||||||
if (data instanceof AttachmentBuilder) {
|
if (data instanceof AttachmentBuilder) {
|
||||||
if (!data.data.resolvable)
|
if (!data.data.resolvable)
|
||||||
return throwError('The attachment type has been expressed as attachment but cannot be resolved as one.');
|
return throwError('The attachment type has been expressed as attachment but cannot be resolved as one.');
|
||||||
|
@ -26,7 +26,7 @@ import {
|
|||||||
type MakeRequired,
|
type MakeRequired,
|
||||||
} from '../common';
|
} from '../common';
|
||||||
|
|
||||||
import type { LocaleString } from 'discord-api-types/rest/v10';
|
import type { LocaleString, RESTPostAPIChannelMessageJSONBody } from 'discord-api-types/rest/v10';
|
||||||
import type { DeepPartial, IntentStrings, OmitInsert, PermissionStrings, When } from '../common/types/util';
|
import type { DeepPartial, IntentStrings, OmitInsert, PermissionStrings, When } from '../common/types/util';
|
||||||
import { ComponentHandler } from '../components/handler';
|
import { ComponentHandler } from '../components/handler';
|
||||||
import { LangsHandler } from '../langs/handler';
|
import { LangsHandler } from '../langs/handler';
|
||||||
@ -340,6 +340,9 @@ export interface BaseClientOptions {
|
|||||||
onAfterRun?: Command['onAfterRun'];
|
onAfterRun?: Command['onAfterRun'];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
allowedMentions?: Omit<NonNullable<RESTPostAPIChannelMessageJSONBody['allowed_mentions']>, 'parse'> & {
|
||||||
|
parse?: ('everyone' | 'roles' | 'users')[]; //nice types, d-api
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StartOptions {
|
export interface StartOptions {
|
||||||
|
@ -11,10 +11,13 @@ export class InteractionShorter extends BaseShorter {
|
|||||||
return this.client.proxy
|
return this.client.proxy
|
||||||
.interactions(id)(token)
|
.interactions(id)(token)
|
||||||
.callback.post({
|
.callback.post({
|
||||||
body: BaseInteraction.transformBodyRequest({
|
body: BaseInteraction.transformBodyRequest(
|
||||||
type: body.type,
|
{
|
||||||
data,
|
type: body.type,
|
||||||
}),
|
data,
|
||||||
|
},
|
||||||
|
this.client,
|
||||||
|
),
|
||||||
files: files ? await resolveFiles(files) : undefined,
|
files: files ? await resolveFiles(files) : undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -33,7 +36,7 @@ export class InteractionShorter extends BaseShorter {
|
|||||||
.webhooks(this.client.applicationId)(token)
|
.webhooks(this.client.applicationId)(token)
|
||||||
.messages(messageId)
|
.messages(messageId)
|
||||||
.patch({
|
.patch({
|
||||||
body: BaseInteraction.transformBody(data),
|
body: BaseInteraction.transformBody(data, this.client),
|
||||||
files: files ? await resolveFiles(files) : undefined,
|
files: files ? await resolveFiles(files) : undefined,
|
||||||
});
|
});
|
||||||
return new WebhookMessage(this.client, apiMessage, this.client.applicationId, token);
|
return new WebhookMessage(this.client, apiMessage, this.client.applicationId, token);
|
||||||
@ -60,7 +63,7 @@ export class InteractionShorter extends BaseShorter {
|
|||||||
const apiMessage = await this.client.proxy
|
const apiMessage = await this.client.proxy
|
||||||
.webhooks(this.client.applicationId)(token)
|
.webhooks(this.client.applicationId)(token)
|
||||||
.post({
|
.post({
|
||||||
body: BaseInteraction.transformBody(body),
|
body: BaseInteraction.transformBody(body, this.client),
|
||||||
files: files as RawFile[] | undefined,
|
files: files as RawFile[] | undefined,
|
||||||
});
|
});
|
||||||
return new WebhookMessage(this.client, apiMessage, this.client.applicationId, token);
|
return new WebhookMessage(this.client, apiMessage, this.client.applicationId, token);
|
||||||
|
@ -14,7 +14,7 @@ export class MessageShorter extends BaseShorter {
|
|||||||
async write(channelId: string, { files, ...body }: MessageCreateBodyRequest) {
|
async write(channelId: string, { files, ...body }: MessageCreateBodyRequest) {
|
||||||
const parsedFiles = files ? await resolveFiles(files) : [];
|
const parsedFiles = files ? await resolveFiles(files) : [];
|
||||||
|
|
||||||
const transformedBody = MessagesMethods.transformMessageBody<RESTPostAPIChannelMessageJSONBody>(body);
|
const transformedBody = MessagesMethods.transformMessageBody<RESTPostAPIChannelMessageJSONBody>(body, this.client);
|
||||||
return this.client.proxy
|
return this.client.proxy
|
||||||
.channels(channelId)
|
.channels(channelId)
|
||||||
.messages.post({
|
.messages.post({
|
||||||
@ -33,7 +33,7 @@ export class MessageShorter extends BaseShorter {
|
|||||||
.channels(channelId)
|
.channels(channelId)
|
||||||
.messages(messageId)
|
.messages(messageId)
|
||||||
.patch({
|
.patch({
|
||||||
body: MessagesMethods.transformMessageBody<RESTPatchAPIChannelMessageJSONBody>(body),
|
body: MessagesMethods.transformMessageBody<RESTPatchAPIChannelMessageJSONBody>(body, this.client),
|
||||||
files: parsedFiles,
|
files: parsedFiles,
|
||||||
})
|
})
|
||||||
.then(async message => {
|
.then(async message => {
|
||||||
|
@ -83,7 +83,10 @@ export class WebhookShorter extends BaseShorter {
|
|||||||
*/
|
*/
|
||||||
async writeMessage(webhookId: string, token: string, { body: data, ...payload }: MessageWebhookMethodWriteParams) {
|
async writeMessage(webhookId: string, token: string, { body: data, ...payload }: MessageWebhookMethodWriteParams) {
|
||||||
const { files, ...body } = data;
|
const { files, ...body } = data;
|
||||||
const transformedBody = MessagesMethods.transformMessageBody<RESTPostAPIWebhookWithTokenJSONBody>(body);
|
const transformedBody = MessagesMethods.transformMessageBody<RESTPostAPIWebhookWithTokenJSONBody>(
|
||||||
|
body,
|
||||||
|
this.client,
|
||||||
|
);
|
||||||
const parsedFiles = files ? await resolveFiles(files) : [];
|
const parsedFiles = files ? await resolveFiles(files) : [];
|
||||||
return this.client.proxy
|
return this.client.proxy
|
||||||
.webhooks(webhookId)(token)
|
.webhooks(webhookId)(token)
|
||||||
@ -105,7 +108,10 @@ export class WebhookShorter extends BaseShorter {
|
|||||||
{ messageId, body: data, ...json }: MessageWebhookMethodEditParams,
|
{ messageId, body: data, ...json }: MessageWebhookMethodEditParams,
|
||||||
) {
|
) {
|
||||||
const { files, ...body } = data;
|
const { files, ...body } = data;
|
||||||
const transformedBody = MessagesMethods.transformMessageBody<RESTPostAPIWebhookWithTokenJSONBody>(body);
|
const transformedBody = MessagesMethods.transformMessageBody<RESTPostAPIWebhookWithTokenJSONBody>(
|
||||||
|
body,
|
||||||
|
this.client,
|
||||||
|
);
|
||||||
const parsedFiles = files ? await resolveFiles(files) : [];
|
const parsedFiles = files ? await resolveFiles(files) : [];
|
||||||
return this.client.proxy
|
return this.client.proxy
|
||||||
.webhooks(webhookId)(token)
|
.webhooks(webhookId)(token)
|
||||||
|
@ -57,6 +57,7 @@ import { User } from './User';
|
|||||||
import channelFrom from './channels';
|
import channelFrom from './channels';
|
||||||
import { DiscordBase } from './extra/DiscordBase';
|
import { DiscordBase } from './extra/DiscordBase';
|
||||||
import { PermissionsBitField } from './extra/Permissions';
|
import { PermissionsBitField } from './extra/Permissions';
|
||||||
|
import type { BaseClient } from '../client/base';
|
||||||
|
|
||||||
export type ReplyInteractionBody =
|
export type ReplyInteractionBody =
|
||||||
| { type: InteractionResponseType.Modal; data: ModalCreateBodyRequest }
|
| { type: InteractionResponseType.Modal; data: ModalCreateBodyRequest }
|
||||||
@ -114,7 +115,7 @@ export class BaseInteraction<
|
|||||||
this.user = this.member?.user ?? new User(client, interaction.user!);
|
this.user = this.member?.user ?? new User(client, interaction.user!);
|
||||||
}
|
}
|
||||||
|
|
||||||
static transformBodyRequest(body: ReplyInteractionBody): APIInteractionResponse {
|
static transformBodyRequest(body: ReplyInteractionBody, self: BaseClient): APIInteractionResponse {
|
||||||
switch (body.type) {
|
switch (body.type) {
|
||||||
case InteractionResponseType.ApplicationCommandAutocompleteResult:
|
case InteractionResponseType.ApplicationCommandAutocompleteResult:
|
||||||
case InteractionResponseType.DeferredMessageUpdate:
|
case InteractionResponseType.DeferredMessageUpdate:
|
||||||
@ -127,6 +128,8 @@ export class BaseInteraction<
|
|||||||
type: body.type,
|
type: body.type,
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
data: {
|
data: {
|
||||||
|
//@ts-ignore
|
||||||
|
allowed_mentions: self.options?.allowedMentions,
|
||||||
...(body.data ?? {}),
|
...(body.data ?? {}),
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
components: body.data?.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)) ?? undefined,
|
components: body.data?.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)) ?? undefined,
|
||||||
@ -164,9 +167,11 @@ export class BaseInteraction<
|
|||||||
| MessageUpdateBodyRequest
|
| MessageUpdateBodyRequest
|
||||||
| MessageCreateBodyRequest
|
| MessageCreateBodyRequest
|
||||||
| MessageWebhookCreateBodyRequest,
|
| MessageWebhookCreateBodyRequest,
|
||||||
|
self: UsingClient,
|
||||||
) {
|
) {
|
||||||
const poll = (body as MessageWebhookCreateBodyRequest).poll;
|
const poll = (body as MessageWebhookCreateBodyRequest).poll;
|
||||||
return {
|
return {
|
||||||
|
allowed_mentions: self.options?.allowedMentions,
|
||||||
...body,
|
...body,
|
||||||
components: body.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)) ?? undefined,
|
components: body.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)) ?? undefined,
|
||||||
embeds: body?.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)) ?? undefined,
|
embeds: body?.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)) ?? undefined,
|
||||||
@ -181,7 +186,7 @@ export class BaseInteraction<
|
|||||||
//@ts-expect-error
|
//@ts-expect-error
|
||||||
const data = body.data instanceof Modal ? body.data : rest;
|
const data = body.data instanceof Modal ? body.data : rest;
|
||||||
return (this.replied = this.__reply({
|
return (this.replied = this.__reply({
|
||||||
body: BaseInteraction.transformBodyRequest({ data, type: body.type }),
|
body: BaseInteraction.transformBodyRequest({ data, type: body.type }, this.client),
|
||||||
files: files ? await resolveFiles(files) : undefined,
|
files: files ? await resolveFiles(files) : undefined,
|
||||||
}).then(() => (this.replied = true)));
|
}).then(() => (this.replied = true)));
|
||||||
}
|
}
|
||||||
|
@ -250,9 +250,10 @@ export class MessagesMethods extends DiscordBase {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static transformMessageBody<T>(body: MessageCreateBodyRequest | MessageUpdateBodyRequest) {
|
static transformMessageBody<T>(body: MessageCreateBodyRequest | MessageUpdateBodyRequest, self: UsingClient) {
|
||||||
const poll = (body as MessageCreateBodyRequest).poll;
|
const poll = (body as MessageCreateBodyRequest).poll;
|
||||||
return {
|
return {
|
||||||
|
allowed_mentions: self.options?.allowedMentions,
|
||||||
...body,
|
...body,
|
||||||
components: body.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)) ?? undefined,
|
components: body.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)) ?? undefined,
|
||||||
embeds: body.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)) ?? undefined,
|
embeds: body.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)) ?? undefined,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user