mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 02:15:10 +02:00
Month names in zodiac-sign, Number.parseInt/isNaN
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
[
|
||||||
|
"january",
|
||||||
|
"february",
|
||||||
|
"march",
|
||||||
|
"april",
|
||||||
|
"may",
|
||||||
|
"june",
|
||||||
|
"july",
|
||||||
|
"august",
|
||||||
|
"september",
|
||||||
|
"october",
|
||||||
|
"november",
|
||||||
|
"december"
|
||||||
|
]
|
||||||
@@ -21,8 +21,8 @@ module.exports = class DaysUntilCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
run(msg, { date }) {
|
run(msg, { date }) {
|
||||||
const month = parseInt(date[0], 10);
|
const month = Number.parseInt(date[0], 10);
|
||||||
const day = parseInt(date[1], 10);
|
const day = Number.parseInt(date[1], 10);
|
||||||
if (!month || !day) return msg.reply('Invalid date.');
|
if (!month || !day) return msg.reply('Invalid date.');
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
let year = now.getMonth() + 1 <= month ? now.getFullYear() : now.getFullYear() + 1;
|
let year = now.getMonth() + 1 <= month ? now.getFullYear() : now.getFullYear() + 1;
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ module.exports = class AkinatorCommand extends Command {
|
|||||||
id: data.identification.session,
|
id: data.identification.session,
|
||||||
signature: data.identification.signature,
|
signature: data.identification.signature,
|
||||||
step: 0,
|
step: 0,
|
||||||
progress: parseInt(data.step_information.progression, 10)
|
progress: Number.parseInt(data.step_information.progression, 10)
|
||||||
});
|
});
|
||||||
return data.step_information;
|
return data.step_information;
|
||||||
}
|
}
|
||||||
@@ -95,8 +95,8 @@ module.exports = class AkinatorCommand extends Command {
|
|||||||
this.sessions.set(channel.id, {
|
this.sessions.set(channel.id, {
|
||||||
id: session.id,
|
id: session.id,
|
||||||
signature: session.signature,
|
signature: session.signature,
|
||||||
step: parseInt(data.step, 10),
|
step: Number.parseInt(data.step, 10),
|
||||||
progress: parseInt(data.progression, 10)
|
progress: Number.parseInt(data.progression, 10)
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ module.exports = class ApplesToApplesCommand extends Command {
|
|||||||
`);
|
`);
|
||||||
let chosen = null;
|
let chosen = null;
|
||||||
const filter = res => {
|
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 (!existing) return false;
|
||||||
chosen = existing;
|
chosen = existing;
|
||||||
return true;
|
return true;
|
||||||
@@ -111,7 +111,7 @@ module.exports = class ApplesToApplesCommand extends Command {
|
|||||||
`);
|
`);
|
||||||
const filter = res => {
|
const filter = res => {
|
||||||
if (res.author.id !== czar.user.id) return false;
|
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;
|
return true;
|
||||||
};
|
};
|
||||||
const chosen = await msg.channel.awaitMessages(filter, {
|
const chosen = await msg.channel.awaitMessages(filter, {
|
||||||
@@ -122,7 +122,7 @@ module.exports = class ApplesToApplesCommand extends Command {
|
|||||||
await msg.say('Hmm... No one wins.');
|
await msg.say('Hmm... No one wins.');
|
||||||
continue;
|
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;
|
++player.points;
|
||||||
if (player.points >= maxPts) winner = player.user;
|
if (player.points >= maxPts) winner = player.user;
|
||||||
else await msg.say(`Nice one, ${player.user}! You now have **${player.points}** points!`);
|
else await msg.say(`Nice one, ${player.user}! You now have **${player.points}** points!`);
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command {
|
|||||||
`);
|
`);
|
||||||
const chosen = [];
|
const chosen = [];
|
||||||
const filter = res => {
|
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 (!existing) return false;
|
||||||
if (chosen.includes(existing)) return false;
|
if (chosen.includes(existing)) return false;
|
||||||
chosen.push(existing);
|
chosen.push(existing);
|
||||||
@@ -112,7 +112,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command {
|
|||||||
`);
|
`);
|
||||||
const filter = res => {
|
const filter = res => {
|
||||||
if (res.author.id !== czar.user.id) return false;
|
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;
|
return true;
|
||||||
};
|
};
|
||||||
const chosen = await msg.channel.awaitMessages(filter, {
|
const chosen = await msg.channel.awaitMessages(filter, {
|
||||||
@@ -123,7 +123,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command {
|
|||||||
await msg.say('Hmm... No one wins.');
|
await msg.say('Hmm... No one wins.');
|
||||||
continue;
|
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;
|
++player.points;
|
||||||
if (player.points >= maxPts) winner = player.user;
|
if (player.points >= maxPts) winner = player.user;
|
||||||
else await msg.say(`Nice one, ${player.user}! You now have **${player.points}** points!`);
|
else await msg.say(`Nice one, ${player.user}! You now have **${player.points}** points!`);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ module.exports = class RouletteCommand extends Command {
|
|||||||
prompt: 'What space do you want to bet on?',
|
prompt: 'What space do you want to bet on?',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
validate: space => {
|
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 (dozens.includes(space)) return true;
|
||||||
if (halves.includes(space)) return true;
|
if (halves.includes(space)) return true;
|
||||||
if (columns.includes(space.toLowerCase())) 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 (parity.includes(choice)) return parity[result % 2] === choice;
|
||||||
if (columns.includes(choice)) return columns[(result - 1) % 3] === 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 (numbers.includes(number)) return result === number;
|
||||||
if (!result) return false;
|
if (!result) return false;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ module.exports = class TicTacToeCommand extends Command {
|
|||||||
} else if (!sides.includes(choice)) {
|
} else if (!sides.includes(choice)) {
|
||||||
await msg.say('I don\'t think that is a valid spot...');
|
await msg.say('I don\'t think that is a valid spot...');
|
||||||
} else {
|
} else {
|
||||||
sides[parseInt(choice, 10)] = sign;
|
sides[Number.parseInt(choice, 10)] = sign;
|
||||||
taken.push(choice);
|
taken.push(choice);
|
||||||
if ((sides[0] === sides[1] && sides[0] === sides[2])
|
if ((sides[0] === sides[1] && sides[0] === sides[2])
|
||||||
|| (sides[0] === sides[3] && sides[0] === sides[6])
|
|| (sides[0] === sides[3] && sides[0] === sides[6])
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ module.exports = class WizardConventionCommand extends Command {
|
|||||||
${questions[player.role]} Please type the number.
|
${questions[player.role]} Please type the number.
|
||||||
${valid.map((p, i) => `**${i + 1}.** ${p.user.tag}`).join('\n')}
|
${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,
|
max: 1,
|
||||||
time: 120000
|
time: 120000
|
||||||
});
|
});
|
||||||
@@ -50,7 +51,7 @@ module.exports = class WizardConventionCommand extends Command {
|
|||||||
await player.user.send('Sorry, time is up!');
|
await player.user.send('Sorry, time is up!');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const choice = parseInt(decision.first().content, 10);
|
const choice = Number.parseInt(decision.first().content, 10);
|
||||||
if (player.role === 'dragon') {
|
if (player.role === 'dragon') {
|
||||||
const chosen = players.get(choice);
|
const chosen = players.get(choice);
|
||||||
eaten = chosen.id;
|
eaten = chosen.id;
|
||||||
@@ -99,7 +100,7 @@ module.exports = class WizardConventionCommand extends Command {
|
|||||||
const filter = res => {
|
const filter = res => {
|
||||||
if (!players.exists(p => p.user.id === res.author.id)) return false;
|
if (!players.exists(p => p.user.id === res.author.id)) return false;
|
||||||
if (voted.includes(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);
|
voted.push(res.author.id);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@@ -146,7 +147,7 @@ module.exports = class WizardConventionCommand extends Command {
|
|||||||
getExpelled(votes, players, playersArr) {
|
getExpelled(votes, players, playersArr) {
|
||||||
const counts = new Collection();
|
const counts = new Collection();
|
||||||
for (const vote of votes.values()) {
|
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)) {
|
if (counts.has(player.id)) {
|
||||||
++counts.get(player.id).votes;
|
++counts.get(player.id).votes;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ module.exports = class MyAnimeListMangaCommand extends Command {
|
|||||||
.addField('❯ Type',
|
.addField('❯ Type',
|
||||||
`${data.type[0]} - ${data.status[0]}`, true)
|
`${data.type[0]} - ${data.status[0]}`, true)
|
||||||
.addField('❯ Volumes / Chapters',
|
.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',
|
.addField('❯ Start Date',
|
||||||
data.start_date[0] !== '0000-00-00' ? data.start_date[0] : '???', true)
|
data.start_date[0] !== '0000-00-00' ? data.start_date[0] : '???', true)
|
||||||
.addField('❯ End Date',
|
.addField('❯ End Date',
|
||||||
|
|||||||
@@ -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.',
|
prompt: 'What element do you want to find? You can enter the name, symbol, or atomic number.',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
validate: element => {
|
validate: element => {
|
||||||
const num = parseInt(element, 10);
|
const num = Number.parseInt(element, 10);
|
||||||
if (!isNaN(num) && num >= 0 && num <= elements.length - 1) return true;
|
if (!Number.isNaN(num) && num >= 0 && num <= elements.length - 1) return true;
|
||||||
const search = element.toString().toLowerCase();
|
const search = element.toString().toLowerCase();
|
||||||
if (elements.find(e => e.name.toLowerCase() === search || e.symbol.toLowerCase() === search)) return true;
|
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.';
|
return 'Invalid element, please enter a valid element symbol, name, or atomic number.';
|
||||||
},
|
},
|
||||||
parse: element => {
|
parse: element => {
|
||||||
const num = parseInt(element, 10);
|
const num = Number.parseInt(element, 10);
|
||||||
if (!isNaN(num)) return elements[num];
|
if (!Number.isNaN(num)) return elements[num];
|
||||||
const search = element.toLowerCase();
|
const search = element.toLowerCase();
|
||||||
return elements.find(e => e.name.toLowerCase() === search || e.symbol.toLowerCase() === search);
|
return elements.find(e => e.name.toLowerCase() === search || e.symbol.toLowerCase() === search);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const { Command } = require('discord.js-commando');
|
const { Command } = require('discord.js-commando');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
const snekfetch = require('snekfetch');
|
const snekfetch = require('snekfetch');
|
||||||
|
const types = ['random', 'today'];
|
||||||
|
|
||||||
module.exports = class XKCDCommand extends Command {
|
module.exports = class XKCDCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -17,6 +18,12 @@ module.exports = class XKCDCommand extends Command {
|
|||||||
prompt: 'Please enter either a specific comic number, today, or random.',
|
prompt: 'Please enter either a specific comic number, today, or random.',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: 'today',
|
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()
|
parse: query => query.toLowerCase()
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -46,8 +53,8 @@ module.exports = class XKCDCommand extends Command {
|
|||||||
.setFooter(body.alt);
|
.setFooter(body.alt);
|
||||||
return msg.embed(embed);
|
return msg.embed(embed);
|
||||||
}
|
}
|
||||||
const choice = parseInt(query, 10);
|
const choice = Number.parseInt(query, 10);
|
||||||
if (isNaN(choice) || current.body.num < choice || choice < 1) return msg.say('Could not find any results.');
|
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 { body } = await snekfetch.get(`https://xkcd.com/${choice}/info.0.json`);
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setTitle(`${body.num} - ${body.title}`)
|
.setTitle(`${body.num} - ${body.title}`)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const { Command } = require('discord.js-commando');
|
const { Command } = require('discord.js-commando');
|
||||||
|
const months = require('../../assets/json/months');
|
||||||
|
|
||||||
module.exports = class ZodiacSignCommand extends Command {
|
module.exports = class ZodiacSignCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -11,9 +12,18 @@ module.exports = class ZodiacSignCommand extends Command {
|
|||||||
{
|
{
|
||||||
key: 'month',
|
key: 'month',
|
||||||
prompt: 'What month would you like to get the Zodiac Sign for?',
|
prompt: 'What month would you like to get the Zodiac Sign for?',
|
||||||
type: 'integer',
|
type: 'string',
|
||||||
min: 1,
|
validate: month => {
|
||||||
max: 12
|
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',
|
key: 'day',
|
||||||
|
|||||||
@@ -47,6 +47,6 @@ module.exports = class BinaryCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unbinary(text) {
|
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
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "65.4.0",
|
"version": "65.4.1",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user