Add shorthand months

This commit is contained in:
Dragon Fire
2021-02-09 17:25:39 -05:00
parent 49c4a46a95
commit 0e1754ae89
4 changed files with 37 additions and 18 deletions
+30 -14
View File
@@ -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"
]
}
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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) {
+5 -2
View File
@@ -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;
}
};