Fix ESLint & prettier

This commit is contained in:
TomatoCake 2024-07-18 12:52:00 +02:00
parent e7a98b6c46
commit 6be3714593
7 changed files with 50 additions and 19 deletions

View File

@ -95,7 +95,7 @@ router.post(
}, },
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const { wait, thread_id } = req.query; const { wait } = req.query;
if (!wait) return res.status(204).send(); if (!wait) return res.status(204).send();
const { webhook_id, token } = req.params; const { webhook_id, token } = req.params;

View File

@ -15,6 +15,7 @@ router.get(
}, },
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
// TODO: Permission check
const { webhook_id } = req.params; const { webhook_id } = req.params;
const webhook = await Webhook.findOneOrFail({ const webhook = await Webhook.findOneOrFail({
where: { id: webhook_id }, where: { id: webhook_id },

View File

@ -42,6 +42,7 @@ import {
MessageCreateSchema, MessageCreateSchema,
EmbedCache, EmbedCache,
handleFile, handleFile,
Permissions,
} from "@spacebar/util"; } from "@spacebar/util";
import { HTTPError } from "lambert-server"; import { HTTPError } from "lambert-server";
import { In } from "typeorm"; 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) { if (opts.webhook_id) {
message.webhook = await Webhook.findOneOrFail({ message.webhook = await Webhook.findOneOrFail({
where: { id: opts.webhook_id }, where: { id: opts.webhook_id },
}); });
message.author = (await User.findOne({ message.author =
where: { id: opts.webhook_id }, (await User.findOne({
})) || undefined; where: { id: opts.webhook_id },
})) || undefined;
if (!message.author) { if (!message.author) {
message.author = User.create({ message.author = User.create({
@ -132,9 +134,15 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
} }
if (opts.avatar_url) { if (opts.avatar_url) {
const avatarData = await fetch(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( message.avatar = await handleFile(
`/avatars/${opts.webhook_id}`, `/avatars/${opts.webhook_id}`,
@ -219,14 +227,18 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
const role = await Role.findOneOrFail({ const role = await Role.findOneOrFail({
where: { id: mention, guild_id: channel.guild_id }, 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); mention_role_ids.push(mention);
} }
}, },
), ),
); );
if (opts.webhook_id || permission.has("MENTION_EVERYONE")) { if (opts.webhook_id || permission?.has("MENTION_EVERYONE")) {
mention_everyone = mention_everyone =
!!content.match(EVERYONE_MENTION) || !!content.match(EVERYONE_MENTION) ||
!!content.match(HERE_MENTION); !!content.match(HERE_MENTION);

View File

@ -241,7 +241,7 @@ export class Message extends BaseClass {
sticker_items: this.sticker_items ?? undefined, sticker_items: this.sticker_items ?? undefined,
message_reference: this.message_reference ?? undefined, message_reference: this.message_reference ?? undefined,
author: { author: {
...this.author?.toPublicUser() ?? undefined, ...(this.author?.toPublicUser() ?? undefined),
// Webhooks // Webhooks
username: this.username ?? this.author?.username, username: this.username ?? this.author?.username,
avatar: this.avatar ?? this.author?.avatar, avatar: this.avatar ?? this.author?.avatar,

View File

@ -1,15 +1,23 @@
import { MigrationInterface, QueryRunner } from "typeorm"; import { MigrationInterface, QueryRunner } from "typeorm";
export class WebhookMessageProperties1721298824927 implements MigrationInterface { export class WebhookMessageProperties1721298824927
implements MigrationInterface
{
name = "WebhookMessageProperties1721298824927"; name = "WebhookMessageProperties1721298824927";
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query("ALTER TABLE `messages` ADD `username` text NULL"); await queryRunner.query(
await queryRunner.query("ALTER TABLE `messages` ADD `avatar` text NULL"); "ALTER TABLE `messages` ADD `username` text NULL",
);
await queryRunner.query(
"ALTER TABLE `messages` ADD `avatar` text NULL",
);
} }
public async down(queryRunner: QueryRunner): Promise<void> { public async down(queryRunner: QueryRunner): Promise<void> {
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`"); await queryRunner.query("ALTER TABLE `messages` DROP COLUMN `avatar`");
} }
} }

View File

@ -1,15 +1,23 @@
import { MigrationInterface, QueryRunner } from "typeorm"; import { MigrationInterface, QueryRunner } from "typeorm";
export class WebhookMessageProperties1721298824927 implements MigrationInterface { export class WebhookMessageProperties1721298824927
implements MigrationInterface
{
name = "WebhookMessageProperties1721298824927"; name = "WebhookMessageProperties1721298824927";
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query("ALTER TABLE `messages` ADD `username` text NULL"); await queryRunner.query(
await queryRunner.query("ALTER TABLE `messages` ADD `avatar` text NULL"); "ALTER TABLE `messages` ADD `username` text NULL",
);
await queryRunner.query(
"ALTER TABLE `messages` ADD `avatar` text NULL",
);
} }
public async down(queryRunner: QueryRunner): Promise<void> { public async down(queryRunner: QueryRunner): Promise<void> {
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`"); await queryRunner.query("ALTER TABLE `messages` DROP COLUMN `avatar`");
} }
} }

View File

@ -1,6 +1,8 @@
import { MigrationInterface, QueryRunner } from "typeorm"; import { MigrationInterface, QueryRunner } from "typeorm";
export class WebhookMessageProperties1721298824927 implements MigrationInterface { export class WebhookMessageProperties1721298824927
implements MigrationInterface
{
name = "WebhookMessageProperties1721298824927"; name = "WebhookMessageProperties1721298824927";
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {