Allow enabling welcome screen and check if welcome screen channels exist within the guild (close #998)
This commit is contained in:
parent
be47c8a231
commit
25099aecb7
@ -17,9 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
import { Guild, GuildUpdateWelcomeScreenSchema, Member } from "@spacebar/util";
|
import {
|
||||||
|
Channel,
|
||||||
|
Guild,
|
||||||
|
GuildUpdateWelcomeScreenSchema,
|
||||||
|
Member,
|
||||||
|
} from "@spacebar/util";
|
||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -66,17 +70,28 @@ router.patch(
|
|||||||
|
|
||||||
const guild = await Guild.findOneOrFail({ where: { id: guild_id } });
|
const guild = await Guild.findOneOrFail({ where: { id: guild_id } });
|
||||||
|
|
||||||
if (!guild.welcome_screen.enabled)
|
if (body.enabled != undefined)
|
||||||
throw new HTTPError("Welcome screen disabled", 400);
|
guild.welcome_screen.enabled = body.enabled;
|
||||||
if (body.welcome_channels)
|
|
||||||
guild.welcome_screen.welcome_channels = body.welcome_channels; // TODO: check if they exist and are valid
|
if (body.description != undefined)
|
||||||
if (body.description)
|
|
||||||
guild.welcome_screen.description = body.description;
|
guild.welcome_screen.description = body.description;
|
||||||
if (body.enabled != null) guild.welcome_screen.enabled = body.enabled;
|
|
||||||
|
if (body.welcome_channels != undefined) {
|
||||||
|
// Ensure channels exist within the guild
|
||||||
|
await Promise.all(
|
||||||
|
body.welcome_channels?.map(({ channel_id }) =>
|
||||||
|
Channel.findOneOrFail({
|
||||||
|
where: { id: channel_id, guild_id },
|
||||||
|
select: { id: true },
|
||||||
|
}),
|
||||||
|
) || [],
|
||||||
|
);
|
||||||
|
guild.welcome_screen.welcome_channels = body.welcome_channels;
|
||||||
|
}
|
||||||
|
|
||||||
await guild.save();
|
await guild.save();
|
||||||
|
|
||||||
res.sendStatus(204);
|
res.status(200).json(guild.welcome_screen);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user