mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-22 10:19:11 +02:00
Fix
This commit is contained in:
@@ -47,14 +47,16 @@ module.exports = class PeriodicTableCommand extends Command {
|
|||||||
{
|
{
|
||||||
key: 'element',
|
key: 'element',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
validate: element => {
|
validate: async element => {
|
||||||
|
if (!this.table) await this.fetchTable();
|
||||||
const num = Number.parseInt(element, 10);
|
const num = Number.parseInt(element, 10);
|
||||||
if (!Number.isNaN(num) && num >= 0 && num <= this.table.length - 1) return true;
|
if (!Number.isNaN(num) && num >= 0 && num <= this.table.length - 1) return true;
|
||||||
const search = element.toString().toLowerCase();
|
const search = element.toString().toLowerCase();
|
||||||
if (this.table.find(e => e.name.toLowerCase() === search || e.symbol.toLowerCase() === search)) return true;
|
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.';
|
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);
|
const num = Number.parseInt(element, 10);
|
||||||
if (!Number.isNaN(num)) return this.table[num];
|
if (!Number.isNaN(num)) return this.table[num];
|
||||||
const search = element.toLowerCase();
|
const search = element.toLowerCase();
|
||||||
|
|||||||
Reference in New Issue
Block a user