remind.ts

1import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'
2import { Command } from '@/types/bot'
3import { supabase } from '@/configs/supabase'
4import ms from 'ms'
5
6export default {
7	data: new SlashCommandBuilder()
8		.setName('remind')
9		.setDescription('Set a reminder')
10		.addStringOption((option) =>
11			option
12				.setName('time')
13				.setDescription('When to remind you (e.g., 1h, 30m, 1d)')
14				.setRequired(true),
15		)
16		.addStringOption((option) =>
17			option
18				.setName('message')
19				.setDescription('What to remind you about')
20				.setRequired(true),
21		),
22
23	async execute(interaction: ChatInputCommandInteraction) {
24		const timeStr = interaction.options.getString('time', true)
25		const message = interaction.options.getString('message', true)
26
27		// Convert time string to milliseconds
28		const timeMs = ms(timeStr)
29		if (!timeMs) {
30			return interaction.reply({
31				content: 'Invalid time format! Use formats like: 1h, 30m, 1d',
32				ephemeral: true,
33			})
34		}
35
36		const remindAt = new Date(Date.now() + timeMs)
37
38		// Store reminder in database
39		const { error } = await supabase.from('reminders').insert({
40			user_id: interaction.user.id,
41			channel_id: interaction.channelId,
42			message: message,
43			remind_at: remindAt.toISOString(),
44		})
45
46		if (error) {
47			return interaction.reply({
48				content: 'Failed to set reminder!',
49				ephemeral: true,
50			})
51		}
52
53		await interaction.reply({
54			content: `I'll remind you about "${message}" ${timeStr} from now!`,
55			ephemeral: true,
56		})
57	},
58} as Command
59