Add didyoumean to time and analogclock

This commit is contained in:
Dragon Fire
2021-04-24 12:11:06 -04:00
parent c9a111415a
commit c20e727bfd
2 changed files with 16 additions and 2 deletions
+8 -1
View File
@@ -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 <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>.');
const results = didYouMean(timeZone, moment.tz.names(), { returnType: ReturnTypeEnums.ALL_SORTED_MATCHES });
return msg.reply(stripIndents`
Invalid time zone. Refer to <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>.
${results.length ? `Did You Mean: ${results.slice(0, 5).map(c => `\`${c}\``).join(', ')}` : ''}
`);
}
const time = moment().tz(timeZone);
const location = timeZone.split('/');
+8 -1
View File
@@ -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 <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>.');
const results = didYouMean(timeZone, moment.tz.names(), { returnType: ReturnTypeEnums.ALL_SORTED_MATCHES });
return msg.reply(stripIndents`
Invalid time zone. Refer to <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>.
${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('/');