Implement /nag command

This commit is contained in:
2025-07-05 17:30:26 -04:00
parent d4387a8264
commit 88679d2eda

View File

@@ -35,6 +35,26 @@ async function execute(interaction: ChatInputCommandInteraction) {
await interaction.reply("Nag can't have a blank `text`, try again.");
return;
}
// Check if we already have an existing nag. In theory, this should be supported entirely, however
// I want to keep things simple for now.
const existingNags = await Nag.findAll({
where: { userId: interaction.user.id },
order: [["createdAt", "ASC"]],
});
if (existingNags && existingNags.length > 0) {
// TODO: Hmm... For now, I guess we can just update the database.
for (const nag of existingNags) {
nag.text = text;
nag.failText = interaction.options.getString("failText") ?? undefined;
await nag.save();
break;
}
await interaction.reply(
`I'll check every day at 9AM if you've completed '${text}'. If not, I'll nag you! Use /checkin to prevent a shameful callout, and /unnag to cancel.`,
);
return;
}
// Otherwise, we need to create a new nag.
const nag = await Nag.create({
userId: interaction.user.id,
guildId: interaction.guild?.id,