mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-09 20:22:47 +01:00
Fix ESLint & prettier
This commit is contained in:
parent
e7a98b6c46
commit
6be3714593
@ -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;
|
||||
|
@ -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 },
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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<void> {
|
||||
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<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`");
|
||||
}
|
||||
}
|
||||
|
@ -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<void> {
|
||||
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<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`");
|
||||
}
|
||||
}
|
||||
|
@ -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<void> {
|
||||
|
Loading…
Reference in New Issue
Block a user