diff options
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/utilities/remind.ts | 59 | ||||
-rw-r--r-- | src/commands/utilities/reminders.ts | 33 |
2 files changed, 92 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')}).`); + } +} diff --git a/src/commands/utilities/reminders.ts b/src/commands/utilities/reminders.ts new file mode 100644 index 0000000..7180aa9 --- /dev/null +++ b/src/commands/utilities/reminders.ts @@ -0,0 +1,33 @@ +import { BushCommand, ButtonPaginator, Reminder, type BushMessage, type BushSlashMessage } from '#lib'; +import { MessageEmbedOptions } from 'discord.js'; +import { Op } from 'sequelize'; + +export default class RemindersCommand extends BushCommand { + public constructor() { + super('reminders', { + aliases: ['reminders', 'view-reminders', 'list-reminders'], + category: 'utilities', + description: 'List all your current reminders.', + usage: ['reminder'], + examples: ['reminders'], + slash: true, + clientPermissions: (m) => util.clientSendAndPermCheck(m, 'EMBED_LINKS'), + userPermissions: [] + }); + } + + public override async exec(message: BushMessage | BushSlashMessage) { + const reminders = await Reminder.findAll({ where: { user: message.author.id, expires: { [Op.gt]: new Date() } } }); + if (!reminders.length) return message.util.send(`${util.emojis.error} You don't have any reminders set.`); + + const formattedReminders = reminders.map((reminder) => `${util.timestamp(reminder.expires, 't')} - ${reminder.content}`); + + const chunked = util.chunk(formattedReminders, 15); + const embeds: MessageEmbedOptions[] = chunked.map((chunk) => ({ + title: `Reminders`, + description: chunk.join('\n'), + color: util.colors.default + })); + return await ButtonPaginator.send(message, embeds); + } +} |