mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-15 00:12:38 +02:00
Month type
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
const { ArgumentType } = require('discord.js-commando');
|
||||
const months = require('../assets/json/month');
|
||||
|
||||
class MonthArgumentType extends ArgumentType {
|
||||
constructor(client) {
|
||||
super(client, 'month');
|
||||
}
|
||||
|
||||
validate(value) {
|
||||
const num = Number.parseInt(value, 10);
|
||||
if (num > 0 && num < 13) return true;
|
||||
if (months.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;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MonthArgumentType;
|
||||
Reference in New Issue
Block a user