Prettified Code!

This commit is contained in:
itohatweb
2021-05-21 15:55:49 +00:00
committed by GitHub Action
parent 71a20fb0f4
commit 179add27c9
271 changed files with 889 additions and 3067 deletions
+10 -32
View File
@@ -7,11 +7,7 @@ import type { ExecuteWebhook } from "../../types/webhooks/execute_webhook.ts";
import { endpoints } from "../../util/constants.ts";
/** Send a webhook with webhook Id and webhook token */
export async function sendWebhook(
webhookId: bigint,
webhookToken: string,
options: ExecuteWebhook
) {
export async function sendWebhook(webhookId: bigint, webhookToken: string, options: ExecuteWebhook) {
if (!options.content && !options.file && !options.embeds) {
throw new Error(Errors.INVALID_WEBHOOK_OPTIONS);
}
@@ -26,49 +22,31 @@ export async function sendWebhook(
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.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
);
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.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
);
options.allowedMentions.roles = options.allowedMentions.roles.slice(0, 100);
}
}
}
const result = await rest.runMethod<Message>(
"post",
`${endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${
options.wait ?? false
}${options.threadId ? `&thread_id=${options.threadId}` : ""}`,
`${endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${options.wait ?? false}${
options.threadId ? `&thread_id=${options.threadId}` : ""
}`,
{
...options,
allowed_mentions: options.allowedMentions,