1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-09 20:22:47 +01:00

feat: emit MESSAGE_CREATE

This commit is contained in:
Cyber 2024-08-18 13:32:19 +02:00
parent a401f63318
commit 39e3b5ad7a

View File

@ -23,7 +23,9 @@ import {
DiscordApiErrors,
emitEvent,
Message,
MessageCreateEvent,
MessageUpdateEvent,
User,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
@ -61,6 +63,30 @@ router.put(
message.pinned = true;
const author = await User.getPublicUser(req.user_id);
const systemPinMessage = Message.create({
timestamp: new Date(),
type: 6,
guild_id: message.guild_id,
channel_id: message.channel_id,
author,
message_reference: {
message_id: message.id,
channel_id: message.channel_id,
guild_id: message.guild_id,
},
reactions: [],
attachments: [],
embeds: [],
sticker_items: [],
edited_timestamp: undefined,
mentions: [],
mention_channels: [],
mention_roles: [],
mention_everyone: false,
});
await Promise.all([
message.save(),
emitEvent({
@ -77,21 +103,12 @@ router.put(
last_pin_timestamp: undefined,
},
} as ChannelPinsUpdateEvent),
Message.create({
timestamp: new Date(),
type: 6,
embeds: [],
reactions: [],
systemPinMessage.save(),
emitEvent({
event: "MESSAGE_CREATE",
channel_id: message.channel_id,
guild_id: message.guild_id,
author_id: req.user_id,
message_reference: {
message_id: message.id,
channel_id: message.channel_id,
guild_id: message.guild_id,
},
}).save(),
data: systemPinMessage,
} as MessageCreateEvent),
]);
res.sendStatus(204);