Merge pull request #1354 from CyberL1/fix/bulk-command-registration

Remove commands not present in array for bulk registration
This commit is contained in:
Cyber 2025-10-20 18:28:13 +02:00 committed by GitHub
commit 09b1e08632
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import { ApplicationCommandCreateSchema, ApplicationCommandSchema } from "@space
import { route } from "@spacebar/api";
import { Request, Response, Router } from "express";
import { Application, ApplicationCommand, FieldErrors, Snowflake } from "@spacebar/util";
import { IsNull } from "typeorm";
const router = Router({ mergeParams: true });
@ -110,6 +111,16 @@ router.put(
const body = req.body as ApplicationCommandCreateSchema[];
// Remove commands not present in array
const applicationCommands = await ApplicationCommand.find({ where: { application_id: req.params.application_id, guild_id: IsNull() } });
const commandNamesInArray = body.map((c) => c.name);
const commandsNotInArray = applicationCommands.filter((c) => !commandNamesInArray.includes(c.name));
for (const command of commandsNotInArray) {
await ApplicationCommand.delete({ application_id: req.params.application_id, guild_id: IsNull(), id: command.id });
}
for (const command of body) {
if (!command.type) {
command.type = 1;

View File

@ -147,6 +147,16 @@ router.put(
const body = req.body as ApplicationCommandCreateSchema[];
// Remove commands not present in array
const applicationCommands = await ApplicationCommand.find({ where: { application_id: req.params.application_id, guild_id: req.params.guild_id } });
const commandNamesInArray = body.map((c) => c.name);
const commandsNotInArray = applicationCommands.filter((c) => !commandNamesInArray.includes(c.name));
for (const command of commandsNotInArray) {
await ApplicationCommand.delete({ application_id: req.params.application_id, guild_id: req.params.guild_id, id: command.id });
}
for (const command of body) {
if (!command.type) {
command.type = 1;