aboutsummaryrefslogtreecommitdiff
path: root/src/commands/utilities/remind.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/utilities/remind.ts')
-rw-r--r--src/commands/utilities/remind.ts59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/commands/utilities/remind.ts b/src/commands/utilities/remind.ts
new file mode 100644
index 0000000..8df24c1
--- /dev/null
+++ b/src/commands/utilities/remind.ts
@@ -0,0 +1,59 @@
+import { ArgType, BushCommand, Reminder, type BushMessage, type BushSlashMessage } from '#lib';
+
+export default class RemindCommand extends BushCommand {
+ public constructor() {
+ super('remind', {
+ aliases: ['remind', 'remindme', 'reminder'],
+ category: 'utilities',
+ description: 'Create reminders that will be DMed to you when the time expires.',
+ usage: ['remind <duration> <reason>'],
+ examples: ['template 1 2'],
+ args: [
+ {
+ id: 'reason_and_duration',
+ type: 'contentWithDuration',
+ match: 'rest',
+ description: 'The reason to be reminded and the duration to remind the user in.',
+ prompt: 'What would you like to be reminded about and when?',
+ retry: '{error} Choose a reason to be reminded about with a duration for when to be notified.',
+ optional: true,
+ slashType: 'STRING'
+ }
+ ],
+ slash: true,
+ clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ userPermissions: []
+ });
+ }
+
+ public override async exec(
+ message: BushMessage | BushSlashMessage,
+ args: { reason_and_duration: ArgType<'contentWithDuration'> | string }
+ ) {
+ const { duration, contentWithoutTime: reason } =
+ typeof args.reason_and_duration === 'string'
+ ? await util.arg.cast('contentWithDuration', message, args.reason_and_duration)
+ : args.reason_and_duration;
+
+ if (!reason?.trim()) return await message.util.reply(`${util.emojis.error} Please enter a reason to be reminded about.`);
+ if (!duration) return await message.util.reply(`${util.emojis.error} Please enter a duration.`);
+
+ if (duration < 30_000)
+ return await message.util.reply(`${util.emojis.error} You cannot pick a duration less than 30 seconds.`);
+
+ const created = new Date();
+ const expires = new Date(Date.now() + duration);
+ const delta = util.format.bold(util.dateDelta(expires));
+
+ const success = await Reminder.create({
+ content: reason.trim(),
+ messageUrl: message.url!,
+ user: message.author.id,
+ created,
+ expires
+ }).catch(() => false);
+
+ if (!success) return await message.util.reply(`${util.emojis.error} Could not create a reminder.`);
+ return await message.util.reply(`${util.emojis.success} I will remind you in ${delta} (${util.timestamp(expires, 'T')}).`);
+ }
+}