|
| 1 | +import type { CommandData, ChatInputCommand, MessageCommand } from 'commandkit'; |
| 2 | +import { ApplicationCommandOptionType } from 'discord.js'; |
| 3 | +import ms from 'ms'; |
| 4 | +import { createTask } from '@commandkit/tasks'; |
| 5 | +import { RemindTaskData } from '../tasks/remind'; |
| 6 | + |
| 7 | +export const command: CommandData = { |
| 8 | + name: 'remind', |
| 9 | + description: 'remind command', |
| 10 | + options: [ |
| 11 | + { |
| 12 | + name: 'time', |
| 13 | + description: 'The time to remind after. Eg: 6h, 10m, 1d', |
| 14 | + type: ApplicationCommandOptionType.String, |
| 15 | + required: true, |
| 16 | + }, |
| 17 | + { |
| 18 | + name: 'message', |
| 19 | + description: 'The message to remind about.', |
| 20 | + type: ApplicationCommandOptionType.String, |
| 21 | + required: true, |
| 22 | + }, |
| 23 | + ], |
| 24 | +}; |
| 25 | + |
| 26 | +export const chatInput: ChatInputCommand = async (ctx) => { |
| 27 | + const time = ctx.options.getString('time', true); |
| 28 | + const message = ctx.options.getString('message', true); |
| 29 | + const timeMs = Date.now() + ms(time as `${number}`); |
| 30 | + |
| 31 | + await createTask({ |
| 32 | + name: 'remind', |
| 33 | + data: { |
| 34 | + userId: ctx.interaction.user.id, |
| 35 | + message, |
| 36 | + channelId: ctx.interaction.channelId, |
| 37 | + setAt: Date.now(), |
| 38 | + } satisfies RemindTaskData, |
| 39 | + schedule: { |
| 40 | + type: 'date', |
| 41 | + value: timeMs, |
| 42 | + }, |
| 43 | + }); |
| 44 | + |
| 45 | + await ctx.interaction.reply( |
| 46 | + `I will remind you <t:${Math.floor(timeMs / 1000)}:R> for \`${message}\``, |
| 47 | + ); |
| 48 | +}; |
| 49 | + |
| 50 | +export const message: MessageCommand = async (ctx) => { |
| 51 | + const [time, ...messageParts] = ctx.args(); |
| 52 | + const message = messageParts.join(' '); |
| 53 | + const timeMs = Date.now() + ms(time as `${number}`); |
| 54 | + |
| 55 | + await createTask({ |
| 56 | + name: 'remind', |
| 57 | + data: { |
| 58 | + userId: ctx.message.author.id, |
| 59 | + message, |
| 60 | + channelId: ctx.message.channelId, |
| 61 | + setAt: Date.now(), |
| 62 | + } satisfies RemindTaskData, |
| 63 | + schedule: { |
| 64 | + type: 'date', |
| 65 | + value: timeMs, |
| 66 | + }, |
| 67 | + }); |
| 68 | + |
| 69 | + await ctx.message.reply( |
| 70 | + `I will remind you <t:${Math.floor(timeMs / 1000)}:R> for \`${message}\``, |
| 71 | + ); |
| 72 | +}; |
0 commit comments