Implement community "create one for me"

This commit is contained in:
Madeline
2023-08-10 20:37:07 +10:00
parent 25099aecb7
commit 326bf08df0
2 changed files with 86 additions and 12 deletions
+72
View File
@@ -18,11 +18,13 @@
import { route } from "@spacebar/api";
import {
Channel,
DiscordApiErrors,
Guild,
GuildUpdateEvent,
GuildUpdateSchema,
Member,
Permissions,
SpacebarApiErrors,
emitEvent,
getPermission,
@@ -155,6 +157,76 @@ router.patch(
guild.features = body.features;
}
if (body.public_updates_channel_id == "1") {
// move all channels up 1
await Channel.createQueryBuilder("channels")
.where({ guild: { id: guild_id } })
.update({ position: () => "position + 1" })
.execute();
// create an updates channel for them
await Channel.createChannel(
{
name: "moderator-only",
guild_id: guild.id,
position: 0,
type: 0,
permission_overwrites: [
// remove SEND_MESSAGES from @everyone
{
id: guild.id,
allow: "0",
deny: Permissions.FLAGS.VIEW_CHANNEL.toString(),
type: 0,
},
],
},
undefined,
{ skipPermissionCheck: true },
);
} else if (body.public_updates_channel_id != undefined) {
// ensure channel exists in this guild
await Channel.findOneOrFail({
where: { guild_id, id: body.public_updates_channel_id },
select: { id: true },
});
}
if (body.rules_channel_id == "1") {
// move all channels up 1
await Channel.createQueryBuilder("channels")
.where({ guild: { id: guild_id } })
.update({ position: () => "position + 1" })
.execute();
// create a rules for them
await Channel.createChannel(
{
name: "rules",
guild_id: guild.id,
position: 0,
type: 0,
permission_overwrites: [
// remove SEND_MESSAGES from @everyone
{
id: guild.id,
allow: "0",
deny: Permissions.FLAGS.SEND_MESSAGES.toString(),
type: 0,
},
],
},
undefined,
{ skipPermissionCheck: true },
);
} else if (body.rules_channel_id != undefined) {
// ensure channel exists in this guild
await Channel.findOneOrFail({
where: { guild_id, id: body.rules_channel_id },
select: { id: true },
});
}
// TODO: check if body ids are valid
guild.assign(body);