This commit is contained in:
Dragon Fire
2024-04-03 18:21:58 -04:00
parent eafb509991
commit 2b70fae94d
+4 -2
View File
@@ -47,14 +47,16 @@ module.exports = class PeriodicTableCommand extends Command {
{
key: 'element',
type: 'string',
validate: element => {
validate: async element => {
if (!this.table) await this.fetchTable();
const num = Number.parseInt(element, 10);
if (!Number.isNaN(num) && num >= 0 && num <= this.table.length - 1) return true;
const search = element.toString().toLowerCase();
if (this.table.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 => {
parse: async element => {
if (!this.table) await this.fetchTable();
const num = Number.parseInt(element, 10);
if (!Number.isNaN(num)) return this.table[num];
const search = element.toLowerCase();