mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
const Command = require('../../structures/Command');
|
|
const moment = require('moment');
|
|
|
|
module.exports = class TimerCommand extends Command {
|
|
constructor(client) {
|
|
super(client, {
|
|
name: 'timer',
|
|
group: 'other',
|
|
memberName: 'timer',
|
|
description: 'Sets a timer for anywhere from 1 second to 10 minutes.',
|
|
args: [
|
|
{
|
|
key: 'time',
|
|
prompt: 'What do you want me to remind you about, and in how long?',
|
|
type: 'sherlock'
|
|
}
|
|
]
|
|
});
|
|
|
|
this.timers = new Map();
|
|
}
|
|
|
|
run(msg, { time }) {
|
|
if (this.timers.has(msg.channel.id)) return msg.reply('Only one timer can be set per channel.');
|
|
const timeMs = time.startDate.getTime() - Date.now();
|
|
if (timeMs > 600000) return msg.reply('Times above 10 minutes are not currently supported. Sorry!');
|
|
const display = moment().add(timeMs, 'ms').fromNow();
|
|
const timeout = setTimeout(async () => {
|
|
await msg.channel.send(`🕰️ ${msg.author}, you wanted me to remind you of: **"${time.eventTitle}"**.`);
|
|
this.timers.delete(msg.channel.id);
|
|
}, timeMs);
|
|
this.timers.set(msg.channel.id, timeout);
|
|
return msg.say(`🕰️ Okay, I will remind you **"${time.eventTitle}"** ${display}.`);
|
|
}
|
|
};
|