Files
discordeno/src/helpers/webhooks/edit_webhook_message.ts
Skillz4Killz 3d39b3878a change: ids to use bigint instead of string (#892)
* p1 of bigints change

* shtuff fixes and bits

* Commit from GitHub Actions (Lint)

* finish bigint structs

* typings fixes

* Commit from GitHub Actions (Lint)

* more fixes

* Commit from GitHub Actions (Lint)

* more fixes

* Commit from GitHub Actions (Lint)

* blame wolf

* Commit from GitHub Actions (Lint)

* foxed

* Commit from GitHub Actions (Lint)

* fix unit tests

* Commit from GitHub Actions (Lint)

* change: guildUpdate guild ID can't change

* delete server has been renamed to delete guild

* fixes

Co-authored-by: Skillz4Killz <Skillz4Killz@users.noreply.github.com>
Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
2021-05-03 18:05:18 +01:00

71 lines
2.0 KiB
TypeScript

import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts";
import { Message } from "../../types/messages/message.ts";
import { Errors } from "../../types/misc/errors.ts";
import { EditWebhookMessage } from "../../types/webhooks/edit_webhook_message.ts";
import { endpoints } from "../../util/constants.ts";
export async function editWebhookMessage(
webhookId: bigint,
webhookToken: string,
messageId: bigint,
options: EditWebhookMessage,
) {
if (options.content && options.content.length > 2000) {
throw Error(Errors.MESSAGE_MAX_LENGTH);
}
if (options.embeds && options.embeds.length > 10) {
options.embeds.splice(10);
}
if (options.allowedMentions) {
if (options.allowedMentions.users?.length) {
if (
options.allowedMentions.parse?.includes(
DiscordAllowedMentionsTypes.UserMentions,
)
) {
options.allowedMentions.parse = options.allowedMentions.parse.filter(
(p) => p !== "users",
);
}
if (options.allowedMentions.users.length > 100) {
options.allowedMentions.users = options.allowedMentions.users.slice(
0,
100,
);
}
}
if (options.allowedMentions.roles?.length) {
if (
options.allowedMentions.parse?.includes(
DiscordAllowedMentionsTypes.RoleMentions,
)
) {
options.allowedMentions.parse = options.allowedMentions.parse.filter(
(p) => p !== "roles",
);
}
if (options.allowedMentions.roles.length > 100) {
options.allowedMentions.roles = options.allowedMentions.roles.slice(
0,
100,
);
}
}
}
const result = await rest.runMethod<Message>(
"patch",
endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId),
{ ...options, allowedMentions: options.allowedMentions },
);
return await structures.createDiscordenoMessage(result);
}