diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-15 18:39:28 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-15 18:39:28 +0200 |
commit | a64f79afda319f7e75df1b705fa476131dfb5bbb (patch) | |
tree | 645d8cdf2e46448390ee1116142a0693233842c0 /api/src/routes/guilds | |
parent | :sparkles: automatically run db migrations (diff) | |
download | server-a64f79afda319f7e75df1b705fa476131dfb5bbb.tar.xz |
:sparkles: sticker events
Diffstat (limited to 'api/src/routes/guilds')
-rw-r--r-- | api/src/routes/guilds/#guild_id/stickers.ts | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/api/src/routes/guilds/#guild_id/stickers.ts b/api/src/routes/guilds/#guild_id/stickers.ts index 39095dc2..4ea1dce1 100644 --- a/api/src/routes/guilds/#guild_id/stickers.ts +++ b/api/src/routes/guilds/#guild_id/stickers.ts @@ -1,4 +1,14 @@ -import { handleFile, Member, Snowflake, Sticker, StickerFormatType, StickerType, uploadFile } from "@fosscord/util"; +import { + emitEvent, + GuildStickersUpdateEvent, + handleFile, + Member, + Snowflake, + Sticker, + StickerFormatType, + StickerType, + uploadFile +} from "@fosscord/util"; import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; import multer from "multer"; @@ -44,6 +54,8 @@ router.post( uploadFile(`/stickers/${id}`, req.file) ]); + await sendStickerUpdateEvent(guild_id); + res.json(sticker); } ); @@ -94,14 +106,28 @@ router.patch( const body = req.body as ModifyGuildStickerSchema; const sticker = await new Sticker({ ...body, guild_id, id: sticker_id }).save(); + await sendStickerUpdateEvent(guild_id); + return res.json(sticker); } ); +async function sendStickerUpdateEvent(guild_id: string) { + return emitEvent({ + event: "GUILD_STICKERS_UPDATE", + guild_id: guild_id, + data: { + guild_id: guild_id, + stickers: await Sticker.find({ guild_id: guild_id }) + } + } as GuildStickersUpdateEvent); +} + router.delete("/:sticker_id", route({ permission: "MANAGE_EMOJIS_AND_STICKERS" }), async (req: Request, res: Response) => { const { guild_id, sticker_id } = req.params; await Sticker.delete({ guild_id, id: sticker_id }); + await sendStickerUpdateEvent(guild_id); return res.sendStatus(204); }); |