diff --git a/src/api/routes/webhooks/#webhook_id/#token/index.ts b/src/api/routes/webhooks/#webhook_id/#token/index.ts index 538ee181..49c47cca 100644 --- a/src/api/routes/webhooks/#webhook_id/#token/index.ts +++ b/src/api/routes/webhooks/#webhook_id/#token/index.ts @@ -95,7 +95,7 @@ router.post( }, }), async (req: Request, res: Response) => { - const { wait, thread_id } = req.query; + const { wait } = req.query; if (!wait) return res.status(204).send(); const { webhook_id, token } = req.params; diff --git a/src/api/routes/webhooks/#webhook_id/index.ts b/src/api/routes/webhooks/#webhook_id/index.ts index cc8c0386..7d528dbf 100644 --- a/src/api/routes/webhooks/#webhook_id/index.ts +++ b/src/api/routes/webhooks/#webhook_id/index.ts @@ -15,6 +15,7 @@ router.get( }, }), async (req: Request, res: Response) => { + // TODO: Permission check const { webhook_id } = req.params; const webhook = await Webhook.findOneOrFail({ where: { id: webhook_id }, 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 { }); } - 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 { } 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 { 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); diff --git a/src/util/entities/Message.ts b/src/util/entities/Message.ts index 86238e53..6f712023 100644 --- a/src/util/entities/Message.ts +++ b/src/util/entities/Message.ts @@ -241,7 +241,7 @@ export class Message extends BaseClass { sticker_items: this.sticker_items ?? undefined, message_reference: this.message_reference ?? undefined, author: { - ...this.author?.toPublicUser() ?? undefined, + ...(this.author?.toPublicUser() ?? undefined), // Webhooks username: this.username ?? this.author?.username, avatar: this.avatar ?? this.author?.avatar, diff --git a/src/util/migration/mariadb/1721298824927-webhookMessageProperties.ts b/src/util/migration/mariadb/1721298824927-webhookMessageProperties.ts index ccbe689a..775847e0 100644 --- a/src/util/migration/mariadb/1721298824927-webhookMessageProperties.ts +++ b/src/util/migration/mariadb/1721298824927-webhookMessageProperties.ts @@ -1,15 +1,23 @@ import { MigrationInterface, QueryRunner } from "typeorm"; -export class WebhookMessageProperties1721298824927 implements MigrationInterface { +export class WebhookMessageProperties1721298824927 + implements MigrationInterface +{ name = "WebhookMessageProperties1721298824927"; public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query("ALTER TABLE `messages` ADD `username` text NULL"); - await queryRunner.query("ALTER TABLE `messages` ADD `avatar` text NULL"); + await queryRunner.query( + "ALTER TABLE `messages` ADD `username` text NULL", + ); + await queryRunner.query( + "ALTER TABLE `messages` ADD `avatar` text NULL", + ); } public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query("ALTER TABLE `messages` DROP COLUMN `username`"); + await queryRunner.query( + "ALTER TABLE `messages` DROP COLUMN `username`", + ); await queryRunner.query("ALTER TABLE `messages` DROP COLUMN `avatar`"); } } diff --git a/src/util/migration/mysql/1721298824927-webhookMessageProperties.ts b/src/util/migration/mysql/1721298824927-webhookMessageProperties.ts index ccbe689a..775847e0 100644 --- a/src/util/migration/mysql/1721298824927-webhookMessageProperties.ts +++ b/src/util/migration/mysql/1721298824927-webhookMessageProperties.ts @@ -1,15 +1,23 @@ import { MigrationInterface, QueryRunner } from "typeorm"; -export class WebhookMessageProperties1721298824927 implements MigrationInterface { +export class WebhookMessageProperties1721298824927 + implements MigrationInterface +{ name = "WebhookMessageProperties1721298824927"; public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query("ALTER TABLE `messages` ADD `username` text NULL"); - await queryRunner.query("ALTER TABLE `messages` ADD `avatar` text NULL"); + await queryRunner.query( + "ALTER TABLE `messages` ADD `username` text NULL", + ); + await queryRunner.query( + "ALTER TABLE `messages` ADD `avatar` text NULL", + ); } public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query("ALTER TABLE `messages` DROP COLUMN `username`"); + await queryRunner.query( + "ALTER TABLE `messages` DROP COLUMN `username`", + ); await queryRunner.query("ALTER TABLE `messages` DROP COLUMN `avatar`"); } } diff --git a/src/util/migration/postgres/1721298824927-webhookMessageProperties.ts b/src/util/migration/postgres/1721298824927-webhookMessageProperties.ts index 46c507d4..bd603f10 100644 --- a/src/util/migration/postgres/1721298824927-webhookMessageProperties.ts +++ b/src/util/migration/postgres/1721298824927-webhookMessageProperties.ts @@ -1,6 +1,8 @@ import { MigrationInterface, QueryRunner } from "typeorm"; -export class WebhookMessageProperties1721298824927 implements MigrationInterface { +export class WebhookMessageProperties1721298824927 + implements MigrationInterface +{ name = "WebhookMessageProperties1721298824927"; public async up(queryRunner: QueryRunner): Promise {