fix shorthand search pulling up all the empty strings

This commit is contained in:
Ean Milligan 2024-09-14 11:49:33 -04:00
parent 73b958d076
commit 2b6b86c8cc
3 changed files with 6 additions and 3 deletions

View File

@ -1,4 +1,4 @@
# Logogram Discord Bot - A FFXIV Eureka Utility Bot | V1.1.3 - 2025/09/14 # Logogram Discord Bot - A FFXIV Eureka Utility Bot | V1.1.4 - 2025/09/14
A Discord bot for Eureka Logos Actions and their recipes. A Discord bot for Eureka Logos Actions and their recipes.
## Commands ## Commands

View File

@ -1,6 +1,6 @@
export const config = { export const config = {
'name': 'Logogram Bot', // Name of the bot 'name': 'Logogram Bot', // Name of the bot
'version': '1.1.3', // Version of the bot 'version': '1.1.4', // Version of the bot
'token': 'the_bot_token', // Discord API Token for this bot 'token': 'the_bot_token', // Discord API Token for this bot
'localToken': 'local_testing_token', // Discord API Token for a secondary OPTIONAL testing bot, THIS MUST BE DIFFERENT FROM "token" 'localToken': 'local_testing_token', // Discord API Token for a secondary OPTIONAL testing bot, THIS MUST BE DIFFERENT FROM "token"
'prefix': 'l!', // Prefix for all commands 'prefix': 'l!', // Prefix for all commands

5
mod.ts
View File

@ -138,6 +138,7 @@ startBot({
const query = rawQuery.toLowerCase(); const query = rawQuery.toLowerCase();
if (data.ActionNames.includes(query)) { if (data.ActionNames.includes(query)) {
log(LT.LOG, `in name matched '${query}'`);
const singleAction: Array<number> = [data.ActionNames.indexOf(query)]; const singleAction: Array<number> = [data.ActionNames.indexOf(query)];
message.send({ message.send({
content: 'Showing single action:', content: 'Showing single action:',
@ -145,7 +146,8 @@ startBot({
}).catch((e) => { }).catch((e) => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`); log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
}); });
} else if (data.ActionShortNames.includes(query)) { } else if (query && data.ActionShortNames.includes(query)) {
log(LT.LOG, `in shorthand matched '${query}'`);
const searchResults: Array<number> = data.Actions.filter((action) => action.shorthand === query).map((action) => data.ActionNames.indexOf(action.name.toLowerCase())); const searchResults: Array<number> = data.Actions.filter((action) => action.shorthand === query).map((action) => data.ActionNames.indexOf(action.name.toLowerCase()));
message.send({ message.send({
content: searchResults.length > 1 ? `Showing ${searchResults.length} actions:` : 'Showing single action:', content: searchResults.length > 1 ? `Showing ${searchResults.length} actions:` : 'Showing single action:',
@ -154,6 +156,7 @@ startBot({
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`); log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
}); });
} else { } else {
log(LT.LOG, `in general search '${query}'`);
const initialSearchResults: Array<number> = data.ActionNames.filter((action) => action.includes(query)).map((action) => data.ActionNames.indexOf(action)); const initialSearchResults: Array<number> = data.ActionNames.filter((action) => action.includes(query)).map((action) => data.ActionNames.indexOf(action));
const searchResults: Array<number> = initialSearchResults.filter((actionIdx) => const searchResults: Array<number> = initialSearchResults.filter((actionIdx) =>
params.class ? (data.Actions[actionIdx].jobs.includes('all-nin') && !params.isNin) || data.Actions[actionIdx].jobs.includes('all') || data.Actions[actionIdx].jobs.includes(params.class) : true params.class ? (data.Actions[actionIdx].jobs.includes('all-nin') && !params.isNin) || data.Actions[actionIdx].jobs.includes('all') || data.Actions[actionIdx].jobs.includes(params.class) : true