summary refs log tree commit diff
path: root/src/api/util
diff options
context:
space:
mode:
authorTomatoCake <60300461+DEVTomatoCake@users.noreply.github.com>2024-07-18 12:52:00 +0200
committerTomatoCake <60300461+DEVTomatoCake@users.noreply.github.com>2024-07-18 12:52:00 +0200
commit6be3714593d282b4ac9881005a358355f729aa0d (patch)
treea281f62f4c3a7e2474e5d84a420c79298aa4841e /src/api/util
parentwebhook fixes & username/avatar property for msg (diff)
downloadserver-ts-6be3714593d282b4ac9881005a358355f729aa0d.tar.xz
Fix ESLint & prettier
Diffstat (limited to 'src/api/util')
-rw-r--r--src/api/util/handlers/Message.ts28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts

index 18616506..0a20fbc8 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts
@@ -42,6 +42,7 @@ import { MessageCreateSchema, EmbedCache, handleFile, + Permissions, } from "@spacebar/util"; import { HTTPError } from "lambert-server"; import { In } from "typeorm"; @@ -95,15 +96,16 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { }); } - let permission: any; + let permission: undefined | Permissions; if (opts.webhook_id) { message.webhook = await Webhook.findOneOrFail({ where: { id: opts.webhook_id }, }); - message.author = (await User.findOne({ - where: { id: opts.webhook_id }, - })) || undefined; + message.author = + (await User.findOne({ + where: { id: opts.webhook_id }, + })) || undefined; if (!message.author) { message.author = User.create({ @@ -132,9 +134,15 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { } if (opts.avatar_url) { const avatarData = await fetch(opts.avatar_url); - const base64 = await avatarData.buffer().then((x) => x.toString("base64")); + const base64 = await avatarData + .buffer() + .then((x) => x.toString("base64")); - const dataUri = "data:" + avatarData.headers.get("content-type") + ";base64," + base64; + const dataUri = + "data:" + + avatarData.headers.get("content-type") + + ";base64," + + base64; message.avatar = await handleFile( `/avatars/${opts.webhook_id}`, @@ -219,14 +227,18 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { const role = await Role.findOneOrFail({ where: { id: mention, guild_id: channel.guild_id }, }); - if (role.mentionable || (opts.webhook_id || permission.has("MANAGE_ROLES"))) { + if ( + role.mentionable || + opts.webhook_id || + permission?.has("MANAGE_ROLES") + ) { mention_role_ids.push(mention); } }, ), ); - if (opts.webhook_id || permission.has("MENTION_EVERYONE")) { + if (opts.webhook_id || permission?.has("MENTION_EVERYONE")) { mention_everyone = !!content.match(EVERYONE_MENTION) || !!content.match(HERE_MENTION);