From 0e1754ae89cbce25f7237136d32dd7572172366b Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Tue, 9 Feb 2021 17:25:39 -0500 Subject: [PATCH] Add shorthand months --- assets/json/month.json | 44 +++++++++++++++++++++++----------- commands/analyze/birthstone.js | 2 +- commands/events/calendar.js | 2 +- types/month.js | 7 ++++-- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/assets/json/month.json b/assets/json/month.json index 77912012..08d87b15 100644 --- a/assets/json/month.json +++ b/assets/json/month.json @@ -1,14 +1,30 @@ -[ - "january", - "february", - "march", - "april", - "may", - "june", - "july", - "august", - "september", - "october", - "november", - "december" -] +{ + "months": [ + "january", + "february", + "march", + "april", + "may", + "june", + "july", + "august", + "september", + "october", + "november", + "december" + ], + "shorthand": [ + "jan", + "feb", + "mar", + "apr", + "may", + "jun", + "jul", + "aug", + "sep", + "oct", + "nov", + "dec" + ] +} diff --git a/commands/analyze/birthstone.js b/commands/analyze/birthstone.js index bdda2e14..fc0b964a 100644 --- a/commands/analyze/birthstone.js +++ b/commands/analyze/birthstone.js @@ -1,6 +1,6 @@ const Command = require('../../structures/Command'); const { list, firstUpperCase } = require('../../util/Util'); -const months = require('../../assets/json/month'); +const { months } = require('../../assets/json/month'); const stones = require('../../assets/json/birthstone'); module.exports = class BirthstoneCommand extends Command { diff --git a/commands/events/calendar.js b/commands/events/calendar.js index a5a1ffca..1d1dd453 100644 --- a/commands/events/calendar.js +++ b/commands/events/calendar.js @@ -2,7 +2,7 @@ const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); const { firstUpperCase, isLeap } = require('../../util/Util'); const monthsWith30 = [4, 6, 9, 11]; -const months = require('../../assets/json/month'); +const { months } = require('../../assets/json/month'); module.exports = class CalendarCommand extends Command { constructor(client) { diff --git a/types/month.js b/types/month.js index 41069077..1f2943c7 100644 --- a/types/month.js +++ b/types/month.js @@ -1,5 +1,5 @@ const { ArgumentType } = require('discord.js-commando'); -const months = require('../assets/json/month'); +const { months, shorthand } = require('../assets/json/month'); module.exports = class MonthArgumentType extends ArgumentType { constructor(client) { @@ -10,12 +10,15 @@ module.exports = class MonthArgumentType extends ArgumentType { const num = Number.parseInt(value, 10); if (num > 0 && num < 13) return true; if (months.includes(value.toLowerCase())) return true; + if (shorthand.includes(value.toLowerCase())) return true; return false; } parse(value) { const num = Number.parseInt(value, 10); if (!Number.isNaN(num)) return num; - return months.indexOf(value.toLowerCase()) + 1; + if (months.includes(value.toLowerCase())) return months.indexOf(value.toLowerCase()) + 1; + if (shorthand.includes(value.toLowerCase())) return shorthand.indexOf(value.toLowerCase()) + 1; + return null; } };