Merge pull request #1360 from CyberL1/fix/application-command-code-fucks

fix: add BulkApplicationCommandCreateSchema
This commit is contained in:
Cyber 2025-10-22 18:03:19 +02:00 committed by GitHub
commit e54972694b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 17 additions and 12 deletions

Binary file not shown.

Binary file not shown.

View File

@ -95,7 +95,7 @@ router.patch(
version: Snowflake.generate(), version: Snowflake.generate(),
}; };
await ApplicationCommand.update({ name: body.name }, commandForDb); await ApplicationCommand.update({ name: body.name.trim() }, commandForDb);
res.send(commandForDb); res.send(commandForDb);
}, },
); );

View File

@ -83,10 +83,10 @@ router.post(
version: Snowflake.generate(), version: Snowflake.generate(),
}; };
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id, name: body.name } }); const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id, name: body.name.trim() } });
if (commandExists) { if (commandExists) {
await ApplicationCommand.update({ application_id: req.params.application_id, name: body.name }, commandForDb); await ApplicationCommand.update({ application_id: req.params.application_id, name: body.name.trim() }, commandForDb);
} else { } else {
commandForDb.id = Snowflake.generate(); // Have to be done that way so the id doesn't change commandForDb.id = Snowflake.generate(); // Have to be done that way so the id doesn't change
await ApplicationCommand.save(commandForDb); await ApplicationCommand.save(commandForDb);
@ -99,7 +99,7 @@ router.post(
router.put( router.put(
"/", "/",
route({ route({
// requestBody: "ApplicationCommandCreateSchema", // How to make this array? requestBody: "BulkApplicationCommandCreateSchema",
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } }); const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
@ -154,10 +154,10 @@ router.put(
version: Snowflake.generate(), version: Snowflake.generate(),
}; };
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id, name: command.name } }); const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id, name: command.name.trim() } });
if (commandExists) { if (commandExists) {
await ApplicationCommand.update({ application_id: req.params.application_id, name: command.name }, commandForDb); await ApplicationCommand.update({ application_id: req.params.application_id, name: command.name.trim() }, commandForDb);
} else { } else {
commandForDb.id = Snowflake.generate(); // Have to be done that way so the id doesn't change commandForDb.id = Snowflake.generate(); // Have to be done that way so the id doesn't change
await ApplicationCommand.save(commandForDb); await ApplicationCommand.save(commandForDb);

View File

@ -113,7 +113,7 @@ router.patch(
}; };
const commandExists = await ApplicationCommand.exists({ const commandExists = await ApplicationCommand.exists({
where: { application_id: req.params.application_id, guild_id: req.params.guild_id, id: req.params.command_id, name: body.name }, where: { application_id: req.params.application_id, guild_id: req.params.guild_id, id: req.params.command_id, name: body.name.trim() },
}); });
if (!commandExists) { if (!commandExists) {
@ -121,7 +121,10 @@ router.patch(
return; return;
} }
await ApplicationCommand.update({ application_id: req.params.application_id, guild_id: req.params.guild_id, id: req.params.command_id, name: body.name }, commandForDb); await ApplicationCommand.update(
{ application_id: req.params.application_id, guild_id: req.params.guild_id, id: req.params.command_id, name: body.name.trim() },
commandForDb,
);
res.send(commandForDb); res.send(commandForDb);
}, },
); );

View File

@ -107,10 +107,10 @@ router.post(
version: Snowflake.generate(), version: Snowflake.generate(),
}; };
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id, guild_id: req.params.guild_id, name: body.name } }); const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id, guild_id: req.params.guild_id, name: body.name.trim() } });
if (commandExists) { if (commandExists) {
await ApplicationCommand.update({ application_id: req.params.application_id, guild_id: req.params.guild_id, name: body.name }, commandForDb); await ApplicationCommand.update({ application_id: req.params.application_id, guild_id: req.params.guild_id, name: body.name.trim() }, commandForDb);
} else { } else {
commandForDb.id = Snowflake.generate(); // Have to be done that way so the id doesn't change commandForDb.id = Snowflake.generate(); // Have to be done that way so the id doesn't change
await ApplicationCommand.save(commandForDb); await ApplicationCommand.save(commandForDb);
@ -123,7 +123,7 @@ router.post(
router.put( router.put(
"/", "/",
route({ route({
// requestBody: "ApplicationCommandCreateSchema", // How to make this array? requestBody: "BulkApplicationCommandCreateSchema",
}), }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } }); const applicationExists = await Application.exists({ where: { id: req.params.application_id } });

View File

@ -91,7 +91,7 @@ router.post("/", route({}), async (req: Request, res: Response) => {
} }
if (body.type === InteractionType.MessageComponent || body.data.type === InteractionType.ModalSubmit) { if (body.type === InteractionType.MessageComponent || body.data.type === InteractionType.ModalSubmit) {
interactionData.message = await Message.findOneOrFail({ where: { id: body.message_id } }); interactionData.message = await Message.findOneOrFail({ where: { id: body.message_id }, relations: ["author"] });
} }
emitEvent({ emitEvent({

View File

@ -17,3 +17,5 @@ export interface ApplicationCommandCreateSchema {
contexts?: InteractionContextType[]; contexts?: InteractionContextType[];
handler?: ApplicationCommandHandlerType; handler?: ApplicationCommandHandlerType;
} }
export type BulkApplicationCommandCreateSchema = ApplicationCommandCreateSchema[];