ToGuildSource -> ToDiscoverableGuild

This commit is contained in:
Rory&
2026-08-08 05:11:25 +02:00
parent b4d322c62e
commit 580d438c3a
3 changed files with 35 additions and 22 deletions
+7 -6
View File
@@ -49,7 +49,7 @@ router.get(
where: {
id: Not(In(hiddenGuildIds)),
discovery_excluded: false,
...(categories == undefined ? {} : { primary_category_id: categories.toString() }), // TODO: isnt this an array?
...(categories == undefined ? {} : { primary_category_id: Number(categories as string) }), // TODO: isnt this an array?
...(showAllGuilds ? {} : { features: ArrayContains(["DISCOVERABLE"]) }),
},
order: {
@@ -64,11 +64,12 @@ router.get(
res.send({
total: total,
guilds: guilds.map((g) => ({
...g,
discovery_weight: undefined,
discovery_splash: undefined,
})),
// guilds: guilds.map((g) => ({
// ...g,
// discovery_weight: undefined,
// discovery_splash: undefined,
// })),
guilds: guilds.map((g) => g.toDiscoverableGuild()),
offset: Number(offset || Config.get().guild.discovery.offset),
limit: Number(limit || configLimit),
});
+1 -1
View File
@@ -49,7 +49,7 @@ router.get(
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());
res.json(await sticker?.guild?.toDiscoverableGuild());
},
);
+27 -15
View File
@@ -31,7 +31,8 @@ import { Template } from "./Template";
import { User } from "./User";
import { VoiceState } from "./VoiceState";
import { Webhook } from "./Webhook";
import { IntegrationGuild } from "@spacebar/schemas";
import { DiscoverableGuild, IntegrationGuild } from "@spacebar/schemas";
import { Categories } from "@spacebar/database";
// TODO: application_command_count, application_command_counts: {1: 0, 2: 0, 3: 0}
// TODO: guild_scheduled_events
// TODO: stage_instances
@@ -305,42 +306,53 @@ export class Guild extends BaseClass {
@Column({ default: false })
discovery_excluded: boolean = false;
async ToGuildSource() {
async toDiscoverableGuild(): Promise<DiscoverableGuild | null> {
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,
icon: this.icon ?? null,
description: this.description ?? null,
banner: this.banner ?? null,
splash: this.splash ?? null,
discovery_splash: this.discovery_splash ?? null,
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({
premium_subscription_count: this.premium_subscription_count ?? 0,
approximate_member_count: this.member_count ?? 1,
/*await Member.countBy({
guild_id: this.id,
}),
approximate_presence_count: await Member.countBy({
}),*/
approximate_presence_count: this.presence_count ?? 0,
/* await Member.countBy({
guild_id: this.id,
user: {
sessions: {
status: "online",
},
},
}),
emojis: this.emojis ?? undefined,
}),*/
emojis: this.emojis.map((e) => e.toJSON()) ?? undefined,
emoji_count: this.emojis ? this.emojis.length : undefined,
stickers: this.stickers ?? undefined,
stickers: this.stickers.map((s) => s.toJSON()) ?? undefined,
sticker_count: this.stickers ? this.stickers.length : undefined,
auto_removed: false,
primary_category_id: this.primary_category_id,
primary_category_id: this.primary_category_id!,
keywords: [],
is_published: false,
reasons_to_join: [],
created_at: new Date(Snowflake.deconstruct(this.id).timestamp).toISOString(), // TODO: make column
primary_category: (
await Categories.findOneOrFail({
where: {
id: this.primary_category_id!,
},
})
).toJSON(),
};
}