import { type ChatInputCommandInteraction, SlashCommandBuilder, } from "discord.js"; import { Nag, CheckIn, type Settings } from "./service"; import { Chrono } from "chrono-node"; const data = new SlashCommandBuilder() .setName("nag") .setDescription("Let Blitzcrank nag you every day about something") .addStringOption((option) => option .setRequired(true) .setName("text") .setDescription("What you have to do every day"), ) .addStringOption((option) => option .setName("failText") .setDescription("Custom message to be broadcast on failure"), ) .addBooleanOption((option) => option .setName("mentionHere") .setDescription("Whether to DM you or @ a channel") .setRequired(false), ); async function initialize(settings: Settings) {} async function execute(interaction: ChatInputCommandInteraction) { const text = interaction.options.getString("text"); if (text === null || text === undefined) { await interaction.reply("Nag can't have a blank `text`, try again."); return; } const nag = await Nag.create({ userId: interaction.user.id, guildId: interaction.guild?.id, channelId: interaction.channel?.id, messageId: interaction.id, text: text, failText: interaction.options.getString("failText"), mentionHere: interaction.options.getBoolean("mentionHere") ?? false, }); await nag.save(); const chrono = new Chrono(); const checkIn = chrono.parseDate("today at 9AM"); if (!checkIn) { await interaction.reply( "Internal error while saving your nag. Tell Drew the bot is broken!!!", ); return; } await CheckIn.create({ nagId: nag.id, checkIn: checkIn, }); 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.`, ); } export default function (settings: Settings) { return { data, execute, initialize: async () => await initialize(settings), }; }