Month type

This commit is contained in:
Daniel Odendahl Jr
2018-02-22 00:25:05 +00:00
parent 3c90676e30
commit 5485ad138f
6 changed files with 38 additions and 28 deletions
+11 -10
View File
@@ -4,26 +4,27 @@ module.exports = class DaysUntilCommand extends Command {
constructor(client) {
super(client, {
name: 'days-until',
aliases: ['days-until-christmas'],
group: 'events',
memberName: 'days-until',
description: 'Responds with how many days there are until a certain date.',
args: [
{
key: 'date',
prompt: 'What date do you want to get the days until? Month/Day format.',
type: 'string',
default: ['12', '25'],
parse: date => date.split('/')
key: 'month',
prompt: 'What month would you like to get the days until?',
type: 'month'
},
{
key: 'day',
prompt: 'What day would you like to get the days until?',
type: 'integer',
min: 1,
max: 12
}
]
});
}
run(msg, { date }) {
const month = Number.parseInt(date[0], 10);
const day = Number.parseInt(date[1], 10);
if (!month || !day) return msg.reply('Invalid date.');
run(msg, { month, day }) {
const now = new Date();
let year = now.getMonth() + 1 <= month ? now.getFullYear() : now.getFullYear() + 1;
if (month === now.getMonth() + 1 && now.getDate() >= day) ++year;
+2 -4
View File
@@ -13,10 +13,8 @@ module.exports = class GoogleDoodleCommand extends Command {
{
key: 'month',
prompt: 'What month would you like to get doodles for?',
type: 'integer',
default: 'latest',
min: 1,
max: 12
type: 'month',
default: 'latest'
},
{
key: 'year',
+1 -13
View File
@@ -1,5 +1,4 @@
const { Command } = require('discord.js-commando');
const months = require('../../assets/json/months');
module.exports = class ZodiacSignCommand extends Command {
constructor(client) {
@@ -12,18 +11,7 @@ module.exports = class ZodiacSignCommand extends Command {
{
key: 'month',
prompt: 'What month would you like to get the Zodiac Sign for?',
type: 'string',
validate: month => {
const num = Number.parseInt(month, 10);
if (num > 0 && num < 13) return true;
if (months.includes(month.toLowerCase())) return true;
return 'Please enter a valid month name or number.';
},
parse: month => {
const num = Number.parseInt(month, 10);
if (!Number.isNaN(num)) return num;
return months.indexOf(month.toLowerCase()) + 1;
}
type: 'month'
},
{
key: 'day',
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "65.4.1",
"version": "66.0.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
+23
View File
@@ -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;