Merge pull request #1381 from MathMan05/fixGuildJoin

This commit is contained in:
Madeline 2025-11-18 08:50:43 +11:00 committed by GitHub
commit db2befeab6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 30 deletions

Binary file not shown.

Binary file not shown.

View File

@ -17,19 +17,7 @@
*/ */
import { route } from "@spacebar/api"; import { route } from "@spacebar/api";
import { import { DiscordApiErrors, emitEvent, Emoji, getPermission, getRights, Guild, GuildMemberUpdateEvent, handleFile, Member, Role, Sticker } from "@spacebar/util";
DiscordApiErrors,
emitEvent,
Emoji,
getPermission,
getRights,
Guild,
GuildMemberUpdateEvent,
handleFile,
Member,
Role,
Sticker,
} from "@spacebar/util";
import { Request, Response, Router } from "express"; import { Request, Response, Router } from "express";
import { MemberChangeSchema, PublicMemberProjection, PublicUserProjection } from "@spacebar/schemas"; import { MemberChangeSchema, PublicMemberProjection, PublicUserProjection } from "@spacebar/schemas";
@ -60,13 +48,9 @@ router.get(
select: { select: {
index: true, index: true,
// only grab public member props // only grab public member props
...Object.fromEntries( ...Object.fromEntries(PublicMemberProjection.map((x) => [x, true])),
PublicMemberProjection.map((x) => [x, true]),
),
// and public user props // and public user props
user: Object.fromEntries( user: Object.fromEntries(PublicUserProjection.map((x) => [x, true])),
PublicUserProjection.map((x) => [x, true]),
),
roles: { roles: {
id: true, id: true,
}, },
@ -102,8 +86,7 @@ router.patch(
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const { guild_id } = req.params; const { guild_id } = req.params;
const member_id = const member_id = req.params.member_id === "@me" ? req.user_id : req.params.member_id;
req.params.member_id === "@me" ? req.user_id : req.params.member_id;
const body = req.body as MemberChangeSchema; const body = req.body as MemberChangeSchema;
const member = await Member.findOneOrFail({ const member = await Member.findOneOrFail({
@ -123,19 +106,12 @@ router.patch(
} }
} }
if ( if (("bio" in body || "avatar" in body) && req.params.member_id != "@me") {
("bio" in body || "avatar" in body) &&
req.params.member_id != "@me"
) {
const rights = await getRights(req.user_id); const rights = await getRights(req.user_id);
rights.hasThrow("MANAGE_USERS"); rights.hasThrow("MANAGE_USERS");
} }
if (body.avatar) if (body.avatar) body.avatar = await handleFile(`/guilds/${guild_id}/users/${member_id}/avatars`, body.avatar as string);
body.avatar = await handleFile(
`/guilds/${guild_id}/users/${member_id}/avatars`,
body.avatar as string,
);
member.assign(body); member.assign(body);
@ -202,6 +178,10 @@ router.put(
where: { id: guild_id }, where: { id: guild_id },
}); });
if (!guild.features.includes("DISCOVERABLE")) {
throw DiscordApiErrors.UNKNOWN_GUILD;
}
const emoji = await Emoji.find({ const emoji = await Emoji.find({
where: { guild_id: guild_id }, where: { guild_id: guild_id },
}); });