diff --git a/src/api/routes/stickers/#sticker_id/index.ts b/src/api/routes/stickers/#sticker_id/index.ts index ddfbbe4cf..7188d93fb 100644 --- a/src/api/routes/stickers/#sticker_id/index.ts +++ b/src/api/routes/stickers/#sticker_id/index.ts @@ -33,7 +33,22 @@ router.get( async (req: Request, res: Response) => { const { sticker_id } = req.params as { [key: string]: string }; - res.json(await Sticker.find({ where: { id: sticker_id } })); + res.json(await Sticker.findOne({ where: { id: sticker_id } })); + }, +); +router.get( + "/guild", + route({ + responses: { + 200: { + body: "Sticker", + }, + }, + }), + async (req: Request, res: Response) => { + const { sticker_id } = req.params as { [key: string]: string }; + const sticker = await Sticker.findOne({ where: { id: sticker_id }, relations: { guild: true } }); + res.json(await sticker?.guild?.ToGuildSource()); }, ); diff --git a/src/util/entities/Guild.ts b/src/util/entities/Guild.ts index d5a246328..29d4de584 100644 --- a/src/util/entities/Guild.ts +++ b/src/util/entities/Guild.ts @@ -304,6 +304,45 @@ export class Guild extends BaseClass { @Column() discovery_excluded: boolean = false; + async ToGuildSource() { + if (!this.features.includes("DISCOVERABLE")) { + return null; + } + return { + id: this.id, + name: this.name, + icon: this.icon, + description: this.description, + banner: this.banner, + splash: this.splash, + discovery_splash: this.discovery_splash, + features: this.features, + vanity_url_code: null, + preferred_locale: this.preferred_locale || "en", + premium_subscription_count: this.premium_subscription_count, + approximate_member_count: await Member.countBy({ + guild_id: this.id, + }), + approximate_presence_count: await Member.countBy({ + guild_id: this.id, + user: { + sessions: { + status: "online", + }, + }, + }), + emojis: this.emojis ?? undefined, + emoji_count: this.emojis ? this.emojis.length : undefined, + stickers: this.stickers ?? undefined, + sticker_count: this.stickers ? this.stickers.length : undefined, + auto_removed: false, + primary_category_id: this.primary_category_id, + keywords: [], + is_published: false, + reasons_to_join: [], + }; + } + static async createGuild(body: { name?: string; icon?: string | null;