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
+14
View File
@@ -0,0 +1,14 @@
[
"january",
"february",
"march",
"april",
"may",
"june",
"july",
"august",
"september",
"october",
"november",
"december"
]
+2 -2
View File
@@ -21,8 +21,8 @@ module.exports = class DaysUntilCommand extends Command {
}
run(msg, { date }) {
const month = parseInt(date[0], 10);
const day = parseInt(date[1], 10);
const month = Number.parseInt(date[0], 10);
const day = Number.parseInt(date[1], 10);
if (!month || !day) return msg.reply('Invalid date.');
const now = new Date();
let year = now.getMonth() + 1 <= month ? now.getFullYear() : now.getFullYear() + 1;
+3 -3
View File
@@ -75,7 +75,7 @@ module.exports = class AkinatorCommand extends Command {
id: data.identification.session,
signature: data.identification.signature,
step: 0,
progress: parseInt(data.step_information.progression, 10)
progress: Number.parseInt(data.step_information.progression, 10)
});
return data.step_information;
}
@@ -95,8 +95,8 @@ module.exports = class AkinatorCommand extends Command {
this.sessions.set(channel.id, {
id: session.id,
signature: session.signature,
step: parseInt(data.step, 10),
progress: parseInt(data.progression, 10)
step: Number.parseInt(data.step, 10),
progress: Number.parseInt(data.progression, 10)
});
return data;
}
+3 -3
View File
@@ -73,7 +73,7 @@ module.exports = class ApplesToApplesCommand extends Command {
`);
let chosen = null;
const filter = res => {
const existing = hand[parseInt(res.content, 10) - 1];
const existing = hand[Number.parseInt(res.content, 10) - 1];
if (!existing) return false;
chosen = existing;
return true;
@@ -111,7 +111,7 @@ module.exports = class ApplesToApplesCommand extends Command {
`);
const filter = res => {
if (res.author.id !== czar.user.id) return false;
if (!cards[parseInt(res.content, 10) - 1]) return false;
if (!cards[Number.parseInt(res.content, 10) - 1]) return false;
return true;
};
const chosen = await msg.channel.awaitMessages(filter, {
@@ -122,7 +122,7 @@ module.exports = class ApplesToApplesCommand extends Command {
await msg.say('Hmm... No one wins.');
continue;
}
const player = players.get(cards[parseInt(chosen.first().content, 10) - 1].id);
const player = players.get(cards[Number.parseInt(chosen.first().content, 10) - 1].id);
++player.points;
if (player.points >= maxPts) winner = player.user;
else await msg.say(`Nice one, ${player.user}! You now have **${player.points}** points!`);
+3 -3
View File
@@ -74,7 +74,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command {
`);
const chosen = [];
const filter = res => {
const existing = hand[parseInt(res.content, 10) - 1];
const existing = hand[Number.parseInt(res.content, 10) - 1];
if (!existing) return false;
if (chosen.includes(existing)) return false;
chosen.push(existing);
@@ -112,7 +112,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command {
`);
const filter = res => {
if (res.author.id !== czar.user.id) return false;
if (!cards[parseInt(res.content, 10) - 1]) return false;
if (!cards[Number.parseInt(res.content, 10) - 1]) return false;
return true;
};
const chosen = await msg.channel.awaitMessages(filter, {
@@ -123,7 +123,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command {
await msg.say('Hmm... No one wins.');
continue;
}
const player = players.get(cards[parseInt(chosen.first().content, 10) - 1].id);
const player = players.get(cards[Number.parseInt(chosen.first().content, 10) - 1].id);
++player.points;
if (player.points >= maxPts) winner = player.user;
else await msg.say(`Nice one, ${player.user}! You now have **${player.points}** points!`);
+2 -2
View File
@@ -22,7 +22,7 @@ module.exports = class RouletteCommand extends Command {
prompt: 'What space do you want to bet on?',
type: 'string',
validate: space => {
if (numbers.includes(parseInt(space, 10))) return true;
if (numbers.includes(Number.parseInt(space, 10))) return true;
if (dozens.includes(space)) return true;
if (halves.includes(space)) return true;
if (columns.includes(space.toLowerCase())) return true;
@@ -57,7 +57,7 @@ module.exports = class RouletteCommand extends Command {
}
if (parity.includes(choice)) return parity[result % 2] === choice;
if (columns.includes(choice)) return columns[(result - 1) % 3] === choice;
const number = parseInt(choice, 10);
const number = Number.parseInt(choice, 10);
if (numbers.includes(number)) return result === number;
if (!result) return false;
return false;
+1 -1
View File
@@ -67,7 +67,7 @@ module.exports = class TicTacToeCommand extends Command {
} else if (!sides.includes(choice)) {
await msg.say('I don\'t think that is a valid spot...');
} else {
sides[parseInt(choice, 10)] = sign;
sides[Number.parseInt(choice, 10)] = sign;
taken.push(choice);
if ((sides[0] === sides[1] && sides[0] === sides[2])
|| (sides[0] === sides[3] && sides[0] === sides[6])
+5 -4
View File
@@ -42,7 +42,8 @@ module.exports = class WizardConventionCommand extends Command {
${questions[player.role]} Please type the number.
${valid.map((p, i) => `**${i + 1}.** ${p.user.tag}`).join('\n')}
`);
const decision = await player.user.dmChannel.awaitMessages(res => valid[parseInt(res.content, 10) - 1], {
const filter = res => valid[Number.parseInt(res.content, 10) - 1];
const decision = await player.user.dmChannel.awaitMessages(filter, {
max: 1,
time: 120000
});
@@ -50,7 +51,7 @@ module.exports = class WizardConventionCommand extends Command {
await player.user.send('Sorry, time is up!');
continue;
}
const choice = parseInt(decision.first().content, 10);
const choice = Number.parseInt(decision.first().content, 10);
if (player.role === 'dragon') {
const chosen = players.get(choice);
eaten = chosen.id;
@@ -99,7 +100,7 @@ module.exports = class WizardConventionCommand extends Command {
const filter = res => {
if (!players.exists(p => p.user.id === res.author.id)) return false;
if (voted.includes(res.author.id)) return false;
if (!playersArr[parseInt(res.content, 10) - 1]) return false;
if (!playersArr[Number.parseInt(res.content, 10) - 1]) return false;
voted.push(res.author.id);
return true;
};
@@ -146,7 +147,7 @@ module.exports = class WizardConventionCommand extends Command {
getExpelled(votes, players, playersArr) {
const counts = new Collection();
for (const vote of votes.values()) {
const player = players.get(playersArr[parseInt(vote.content, 10) - 1].id);
const player = players.get(playersArr[Number.parseInt(vote.content, 10) - 1].id);
if (counts.has(player.id)) {
++counts.get(player.id).votes;
} else {
+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',
+1 -1
View File
@@ -47,6 +47,6 @@ module.exports = class BinaryCommand extends Command {
}
unbinary(text) {
return text.split(' ').map(str => String.fromCharCode(parseInt(str, 2))).join('');
return text.split(' ').map(str => String.fromCharCode(Number.parseInt(str, 2))).join('');
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "65.4.0",
"version": "65.4.1",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {