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
8 changed files with 17 additions and 12 deletions
Binary file not shown.
Binary file not shown.
@@ -95,7 +95,7 @@ router.patch(
version: Snowflake.generate(),
};
await ApplicationCommand.update({ name: body.name }, commandForDb);
await ApplicationCommand.update({ name: body.name.trim() }, commandForDb);
res.send(commandForDb);
},
);
@@ -83,10 +83,10 @@ router.post(
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) {
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 {
commandForDb.id = Snowflake.generate(); // Have to be done that way so the id doesn't change
await ApplicationCommand.save(commandForDb);
@@ -99,7 +99,7 @@ router.post(
router.put(
"/",
route({
// requestBody: "ApplicationCommandCreateSchema", // How to make this array?
requestBody: "BulkApplicationCommandCreateSchema",
}),
async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
@@ -154,10 +154,10 @@ router.put(
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) {
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 {
commandForDb.id = Snowflake.generate(); // Have to be done that way so the id doesn't change
await ApplicationCommand.save(commandForDb);
@@ -113,7 +113,7 @@ router.patch(
};
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) {
@@ -121,7 +121,10 @@ router.patch(
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);
},
);
@@ -107,10 +107,10 @@ router.post(
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) {
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 {
commandForDb.id = Snowflake.generate(); // Have to be done that way so the id doesn't change
await ApplicationCommand.save(commandForDb);
@@ -123,7 +123,7 @@ router.post(
router.put(
"/",
route({
// requestBody: "ApplicationCommandCreateSchema", // How to make this array?
requestBody: "BulkApplicationCommandCreateSchema",
}),
async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
+1 -1
View File
@@ -91,7 +91,7 @@ router.post("/", route({}), async (req: Request, res: Response) => {
}
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({
@@ -17,3 +17,5 @@ export interface ApplicationCommandCreateSchema {
contexts?: InteractionContextType[];
handler?: ApplicationCommandHandlerType;
}
export type BulkApplicationCommandCreateSchema = ApplicationCommandCreateSchema[];