Added more resiliency to the give command for modders who dont want to add localization for their mods (!325)

Fixed cases for modded items causing problems with Commando.

Co-authored-by: clodan <clodan@clodan.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/325
Co-authored-by: Alex <clodan@noreply.dev.sp-tarkov.com>
Co-committed-by: Alex <clodan@noreply.dev.sp-tarkov.com>
This commit is contained in:
Alex 2024-05-06 07:17:40 +00:00 committed by chomp
parent c552c7ad67
commit c33773a318

View File

@ -146,16 +146,17 @@ export class GiveSptCommand implements ISptCommand
commandHandler,
`An error occurred while trying to use localized text. Locale will be defaulted to 'en'.`,
);
this.logger.error(e);
this.logger.warning(e);
locale = "en";
}
const localizedGlobal = this.databaseServer.getTables().locales.global[locale];
const localizedGlobal = this.databaseServer.getTables().locales.global[locale] ??
this.databaseServer.getTables().locales.global.en;
const closestItemsMatchedByName = this.itemHelper.getItems()
.filter((i) => this.isItemAllowed(i))
.map((i) => localizedGlobal[`${i?._id} Name`]?.toLowerCase())
.filter((i) => i !== undefined)
.map((i) => localizedGlobal[`${i?._id} Name`]?.toLowerCase() ?? i._props.Name)
.filter((i) => i !== undefined && i !== "")
.map(i => ({match: stringSimilarity(item.toLocaleLowerCase(), i.toLocaleLowerCase()), itemName: i}))
.sort((a1, a2) => a2.match - a1.match);
@ -186,7 +187,7 @@ export class GiveSptCommand implements ISptCommand
const tplId = isItemName
? this.itemHelper.getItems()
.filter((i) => this.isItemAllowed(i))
.find((i) => this.databaseServer.getTables().locales.global[locale][`${i?._id} Name`]?.toLowerCase() === item)._id
.find((i) => (this.databaseServer.getTables().locales.global[locale][`${i?._id} Name`]?.toLowerCase() ?? i._props.Name) === item)._id
: item;
const checkedItem = this.itemHelper.getItem(tplId);