Files
xiao/commands/random/remind.js
T
Daniel Odendahl Jr 76907549df The Power of const
2017-04-03 22:31:19 +00:00

44 lines
1.7 KiB
JavaScript

const commando = require('discord.js-commando');
const moment = require('moment');
const sherlock = require('Sherlock');
module.exports = class RemindCommand extends commando.Command {
constructor(Client) {
super(Client, {
name: 'remind',
aliases: [
'remindme'
],
group: 'random',
memberName: 'remind',
description: 'Reminds you of something at a certain time. (;remind Eat Food tomorrow)',
examples: [';remind Eat Food tomorrow'],
args: [{
key: 'remind',
prompt: 'What should I remind you of?',
type: 'string'
}]
});
}
async run(message, args) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
console.log(`[Command] ${message.content}`);
const remindMe = args.remind;
try {
const remindTime = sherlock.parse(remindMe);
const time = remindTime.startDate.getTime() - Date.now();
const preRemind = await message.say(`I will remind you '${remindTime.eventTitle}' ${moment().add(time, 'ms').fromNow()}.`);
const remindMessage = await new Promise(resolve => {
setTimeout(() => resolve(message.say(`${message.author} you wanted me to remind you of: '${remindTime.eventTitle}'`)), time);
});
return [preRemind, remindMessage];
}
catch (err) {
return message.say(":x: Error! Something went wrong! Perhaps you didn't enter a valid time with your data?");
}
}
};