Month names in zodiac-sign, Number.parseInt/isNaN

This commit is contained in:
Daniel Odendahl Jr
2018-02-21 23:58:35 +00:00
parent 30b81c143e
commit 3c90676e30
14 changed files with 62 additions and 30 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ module.exports = class MyAnimeListMangaCommand extends Command {
.addField(' Type',
`${data.type[0]} - ${data.status[0]}`, true)
.addField(' Volumes / Chapters',
`${parseInt(data.volumes[0], 10) || '???'} / ${parseInt(data.chapters[0], 10) || '???'}`, true)
`${Number.parseInt(data.volumes[0], 10) || '???'} / ${Number.parseInt(data.chapters[0], 10) || '???'}`, true)
.addField(' Start Date',
data.start_date[0] !== '0000-00-00' ? data.start_date[0] : '???', true)
.addField(' End Date',
+4 -4
View File
@@ -23,15 +23,15 @@ module.exports = class PeriodicTableCommand extends Command {
prompt: 'What element do you want to find? You can enter the name, symbol, or atomic number.',
type: 'string',
validate: element => {
const num = parseInt(element, 10);
if (!isNaN(num) && num >= 0 && num <= elements.length - 1) return true;
const num = Number.parseInt(element, 10);
if (!Number.isNaN(num) && num >= 0 && num <= elements.length - 1) return true;
const search = element.toString().toLowerCase();
if (elements.find(e => e.name.toLowerCase() === search || e.symbol.toLowerCase() === search)) return true;
return 'Invalid element, please enter a valid element symbol, name, or atomic number.';
},
parse: element => {
const num = parseInt(element, 10);
if (!isNaN(num)) return elements[num];
const num = Number.parseInt(element, 10);
if (!Number.isNaN(num)) return elements[num];
const search = element.toLowerCase();
return elements.find(e => e.name.toLowerCase() === search || e.symbol.toLowerCase() === search);
}
+9 -2
View File
@@ -1,6 +1,7 @@
const { Command } = require('discord.js-commando');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const types = ['random', 'today'];
module.exports = class XKCDCommand extends Command {
constructor(client) {
@@ -17,6 +18,12 @@ module.exports = class XKCDCommand extends Command {
prompt: 'Please enter either a specific comic number, today, or random.',
type: 'string',
default: 'today',
validate: query => {
if (types.includes(query.toLowerCase())) return true;
const num = Number.parseInt(query, 10);
if (!Number.isNaN(num) && num > 1) return true;
return `Invalid query, please enter either today, random, or a specific comic number.`;
},
parse: query => query.toLowerCase()
}
]
@@ -46,8 +53,8 @@ module.exports = class XKCDCommand extends Command {
.setFooter(body.alt);
return msg.embed(embed);
}
const choice = parseInt(query, 10);
if (isNaN(choice) || current.body.num < choice || choice < 1) return msg.say('Could not find any results.');
const choice = Number.parseInt(query, 10);
if (current.body.num < choice) return msg.say('Could not find any results.');
const { body } = await snekfetch.get(`https://xkcd.com/${choice}/info.0.json`);
const embed = new MessageEmbed()
.setTitle(`${body.num} - ${body.title}`)
+13 -3
View File
@@ -1,4 +1,5 @@
const { Command } = require('discord.js-commando');
const months = require('../../assets/json/months');
module.exports = class ZodiacSignCommand extends Command {
constructor(client) {
@@ -11,9 +12,18 @@ module.exports = class ZodiacSignCommand extends Command {
{
key: 'month',
prompt: 'What month would you like to get the Zodiac Sign for?',
type: 'integer',
min: 1,
max: 12
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;
}
},
{
key: 'day',