Add fetching guild profiles
This commit is contained in:
parent
4f20beeff7
commit
2620a55518
Binary file not shown.
65
src/api/routes/guilds/#guild_id/profile.ts
Normal file
65
src/api/routes/guilds/#guild_id/profile.ts
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
|
||||
Copyright (C) 2023 Spacebar and Spacebar Contributors
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { route } from "@spacebar/api";
|
||||
import { Guild, GuildProfileResponse, GuildVisibilityLevel } from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
"/",
|
||||
route({
|
||||
responses: {
|
||||
"200": {
|
||||
body: "GuildProfileResponse",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (req: Request, res: Response) => {
|
||||
const { guild_id } = req.params;
|
||||
const guild = await Guild.findOneOrFail({ where: { id: guild_id } });
|
||||
const profileResponse: GuildProfileResponse = {
|
||||
id: guild_id,
|
||||
name: guild.name,
|
||||
icon_hash: guild.icon ?? null,
|
||||
member_count: guild.member_count!,
|
||||
online_count: guild.member_count!,
|
||||
description: guild.description ?? "A Spacebar guild",
|
||||
brand_color_primary: "#FF00FF",
|
||||
banner_hash: null,
|
||||
game_application_ids: [], // We don't track this
|
||||
game_activity: {}, // We don't track this
|
||||
tag: guild.name.substring(0, 4).toUpperCase(), // TODO: allow custom tags
|
||||
badge: 0,
|
||||
badge_color_primary: "#FF00FF",
|
||||
badge_color_secondary: "#00FFFF",
|
||||
badge_hash: "",
|
||||
traits: [],
|
||||
features: guild.features ?? [],
|
||||
visibility: GuildVisibilityLevel.PUBLIC,
|
||||
custom_banner_hash: guild.banner ?? null,
|
||||
premium_subscription_count: guild.premium_subscription_count ?? 0,
|
||||
premium_tier: guild.premium_tier ?? 0
|
||||
};
|
||||
|
||||
res.send(profileResponse);
|
||||
},
|
||||
);
|
||||
|
||||
export default router;
|
||||
@ -23,6 +23,9 @@ import { Guild } from "./Guild";
|
||||
import { Member } from "./Member";
|
||||
import { User } from "./User";
|
||||
import { dbEngine } from "../util/Database";
|
||||
import { emitEvent } from "../util";
|
||||
import { GuildCreateEvent } from "../interfaces";
|
||||
import { ReadyGuildDTO } from "../dtos";
|
||||
|
||||
export const PublicInviteRelation = ["inviter", "guild", "channel"];
|
||||
|
||||
|
||||
96
src/util/schemas/responses/GuildProfileResponse.ts
Normal file
96
src/util/schemas/responses/GuildProfileResponse.ts
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
|
||||
Copyright (C) 2025 Spacebar and Spacebar Contributors
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
export interface GuildProfileResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
icon_hash: string | null;
|
||||
member_count: number;
|
||||
online_count: number;
|
||||
description: string;
|
||||
brand_color_primary: string;
|
||||
banner_hash: string | null;
|
||||
game_application_ids: string[];
|
||||
game_activity: {[id: string]: GameActivity};
|
||||
tag: string | null;
|
||||
badge: GuildBadgeType;
|
||||
badge_color_primary: string;
|
||||
badge_color_secondary: string;
|
||||
badge_hash: string;
|
||||
traits: GuildTrait[];
|
||||
features: string[];
|
||||
visibility: GuildVisibilityLevel;
|
||||
custom_banner_hash: string | null;
|
||||
premium_subscription_count: number;
|
||||
premium_tier: number;
|
||||
}
|
||||
|
||||
export interface GameActivity {
|
||||
activity_level: number;
|
||||
activity_score: number;
|
||||
}
|
||||
|
||||
export interface GuildTrait {
|
||||
emoji_id: string | null;
|
||||
emoji_name: string | null;
|
||||
emoji_animated: boolean;
|
||||
label: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
// TODO: move
|
||||
export enum GuildVisibilityLevel {
|
||||
PUBLIC = 1,
|
||||
RESTRICTED = 2,
|
||||
PUBLIC_WITH_RECRUITMENT = 3
|
||||
}
|
||||
|
||||
export enum GuildBadgeType {
|
||||
SWORD = 0,
|
||||
WATER_DROP = 1,
|
||||
SKULL = 2,
|
||||
TOADSTOOL = 3,
|
||||
MOON = 4,
|
||||
LIGHTNING = 5,
|
||||
LEAF = 6,
|
||||
HEART = 7,
|
||||
FIRE = 8,
|
||||
COMPASS = 9,
|
||||
CROSSHAIRS = 10,
|
||||
FLOWER = 11,
|
||||
FORCE = 12,
|
||||
GEM = 13,
|
||||
LAVA = 14,
|
||||
PSYCHIC = 15,
|
||||
SMOKE = 16,
|
||||
SNOW = 17,
|
||||
SOUND = 18,
|
||||
SUN = 19,
|
||||
WIND = 20,
|
||||
BUNNY = 21,
|
||||
DOG = 22,
|
||||
FROG = 23,
|
||||
GOAT = 24,
|
||||
CAT = 25,
|
||||
DIAMOND = 26,
|
||||
CROWN = 27,
|
||||
TROPHY = 28,
|
||||
MONEY_BAG = 29,
|
||||
DOLLAR_SIGN = 30,
|
||||
}
|
||||
|
||||
@ -36,6 +36,7 @@ export * from "./GuildBansResponse";
|
||||
export * from "./GuildCreateResponse";
|
||||
export * from "./GuildDiscoveryRequirements";
|
||||
export * from "./GuildMessagesSearchResponse";
|
||||
export * from "./GuildProfileResponse";
|
||||
export * from "./GuildPruneResponse";
|
||||
export * from "./GuildRecommendationsResponse";
|
||||
export * from "./GuildVanityUrl";
|
||||
|
||||
Reference in New Issue
Block a user