Fix , all in /as and /is (#9657)

* Fix , all in /as and /is

* Update datasearch.ts
This commit is contained in:
dot-Comfey 2023-07-26 23:38:23 -07:00 committed by GitHub
parent 4045bd9658
commit 684e9ee2a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2115,14 +2115,11 @@ function runItemsearch(target: string, cmd: string, canAll: boolean, message: st
let gen = 0;
let randomOutput = 0;
target = target.trim();
const targetSplit = target.split(',');
const lastCommaIndex = target.lastIndexOf(',');
const lastArgumentSubstr = target.substr(lastCommaIndex + 1).trim();
if (lastArgumentSubstr === 'all') {
if (targetSplit[targetSplit.length - 1].trim() === 'all') {
if (!canAll) return {error: "A search ending in ', all' cannot be broadcast."};
showAll = true;
target = target.substr(0, lastCommaIndex);
targetSplit.pop();
}
const sanitizedTargets = [];
@ -2399,28 +2396,25 @@ function runAbilitysearch(target: string, cmd: string, canAll: boolean, message:
let gen = 0;
let randomOutput = 0;
target = target.trim();
const target_split = target.split(',');
const lastCommaIndex = target.lastIndexOf(',');
const lastArgumentSubstr = target.substr(lastCommaIndex + 1).trim();
if (lastArgumentSubstr === 'all') {
const targetSplit = target.split(',');
if (targetSplit[targetSplit.length - 1].trim() === 'all') {
if (!canAll) return {error: "A search ending in ', all' cannot be broadcast."};
showAll = true;
target = target.substr(0, lastCommaIndex);
targetSplit.pop();
}
const sanitized_targets = [];
for (const index of target_split.keys()) {
const local_target = target_split[index].trim();
const sanitizedTargets = [];
for (const index of targetSplit.keys()) {
const localTarget = targetSplit[index].trim();
// Check if the target contains "random<digit>".
if (local_target.startsWith('random') && cmd === 'randability') {
if (localTarget.startsWith('random') && cmd === 'randability') {
// Validation for this is in the /randpoke command
randomOutput = parseInt(local_target.substr(6));
randomOutput = parseInt(localTarget.substr(6));
} else {
sanitized_targets.push(local_target);
sanitizedTargets.push(localTarget);
}
}
target = sanitized_targets.join(',');
target = sanitizedTargets.join(',');
target = target.toLowerCase().replace('-', ' ').replace(/[^a-z0-9.\s/]/g, '');
const rawSearch = target.replace(/(max ?)?gen \d/g, match => toID(match)).split(' ');