From c20e727bfdca2b3aaba77c65a9a8903a29527e41 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 24 Apr 2021 12:11:06 -0400 Subject: [PATCH] Add didyoumean to time and analogclock --- commands/edit-image/analog-clock.js | 9 ++++++++- commands/events/time.js | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/commands/edit-image/analog-clock.js b/commands/edit-image/analog-clock.js index 55578c81..647810b9 100644 --- a/commands/edit-image/analog-clock.js +++ b/commands/edit-image/analog-clock.js @@ -1,6 +1,8 @@ const Command = require('../../structures/Command'); const { createCanvas } = require('canvas'); const moment = require('moment-timezone'); +const { default: didYouMean, ReturnTypeEnums } = require('didyoumean2'); +const { stripIndents } = require('common-tags'); const { firstUpperCase } = require('../../util/Util'); module.exports = class AnalogClockCommand extends Command { @@ -45,7 +47,12 @@ module.exports = class AnalogClockCommand extends Command { run(msg, { timeZone }) { if (!moment.tz.zone(timeZone)) { - return msg.reply('Invalid time zone. Refer to .'); + const results = didYouMean(timeZone, moment.tz.names(), { returnType: ReturnTypeEnums.ALL_SORTED_MATCHES }); + return msg.reply(stripIndents` + Invalid time zone. Refer to . + + ${results.length ? `Did You Mean: ${results.slice(0, 5).map(c => `\`${c}\``).join(', ')}` : ''} + `); } const time = moment().tz(timeZone); const location = timeZone.split('/'); diff --git a/commands/events/time.js b/commands/events/time.js index bb0e5770..d57860d8 100644 --- a/commands/events/time.js +++ b/commands/events/time.js @@ -1,5 +1,7 @@ const Command = require('../../structures/Command'); const moment = require('moment-timezone'); +const { default: didYouMean, ReturnTypeEnums } = require('didyoumean2'); +const { stripIndents } = require('common-tags'); const { firstUpperCase } = require('../../util/Util'); module.exports = class TimeCommand extends Command { @@ -38,7 +40,12 @@ module.exports = class TimeCommand extends Command { run(msg, { timeZone }) { if (!moment.tz.zone(timeZone)) { - return msg.reply('Invalid time zone. Refer to .'); + const results = didYouMean(timeZone, moment.tz.names(), { returnType: ReturnTypeEnums.ALL_SORTED_MATCHES }); + return msg.reply(stripIndents` + Invalid time zone. Refer to . + + ${results.length ? `Did You Mean: ${results.slice(0, 5).map(c => `\`${c}\``).join(', ')}` : ''} + `); } const time = moment().tz(timeZone).format('h:mm A'); const location = timeZone.split('/');