diff --git a/commands/calendar/nag/nag.ts b/commands/calendar/nag/nag.ts index 3e7afc8..6efd722 100644 --- a/commands/calendar/nag/nag.ts +++ b/commands/calendar/nag/nag.ts @@ -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,