Skip to content

Commit

Permalink
fix hideout stations reg command crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Razzmatazzz committed Dec 29, 2023
1 parent e81c88f commit e9d8ae7
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 39 deletions.
16 changes: 8 additions & 8 deletions commands/barter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const defaultFunction = {
.setDescription('Find barters with a specific item')
.setNameLocalizations(getCommandLocalizations('barter'))
.setDescriptionLocalizations(getCommandLocalizations('barter_desc'))
.addStringOption(option => {
return option.setName('name')
.setDescription('Item name to search for')
.setNameLocalizations(getCommandLocalizations('name'))
.setDescriptionLocalizations(getCommandLocalizations('name_search_desc'))
.setAutocomplete(true)
.setRequired(true);
}),
.addStringOption(option => option
.setName('name')
.setDescription('Item name to search for')
.setNameLocalizations(getCommandLocalizations('name'))
.setDescriptionLocalizations(getCommandLocalizations('name_search_desc'))
.setAutocomplete(true)
.setRequired(true)
),
async execute(interaction) {
await interaction.deferReply();
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
Expand Down
16 changes: 8 additions & 8 deletions commands/craft.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const defaultFunction = {
.setDescription('Find crafts with a specific item')
.setNameLocalizations(getCommandLocalizations('craft'))
.setDescriptionLocalizations(getCommandLocalizations('craft_desc'))
.addStringOption(option => {
return option.setName('name')
.setDescription('Item name to search for')
.setNameLocalizations(getCommandLocalizations('name'))
.setDescriptionLocalizations(getCommandLocalizations('name_search_desc'))
.setAutocomplete(true)
.setRequired(true);
}),
.addStringOption(option => option
.setName('name')
.setDescription('Item name to search for')
.setNameLocalizations(getCommandLocalizations('name'))
.setDescriptionLocalizations(getCommandLocalizations('name_search_desc'))
.setAutocomplete(true)
.setRequired(true)
),

async execute(interaction) {
await interaction.deferReply();
Expand Down
16 changes: 8 additions & 8 deletions commands/price.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const defaultFunction = {
.setDescription('Get an item\'s flea and trader value')
.setNameLocalizations(getCommandLocalizations('price'))
.setDescriptionLocalizations(getCommandLocalizations('price_desc'))
.addStringOption(option => {
return option.setName('name')
.setDescription('Item name to search for')
.setNameLocalizations(getCommandLocalizations('name'))
.setDescriptionLocalizations(getCommandLocalizations('name_search_desc'))
.setAutocomplete(true)
.setRequired(true);
}),
.addStringOption(option => option
.setName('name')
.setDescription('Item name to search for')
.setNameLocalizations(getCommandLocalizations('name'))
.setDescriptionLocalizations(getCommandLocalizations('name_search_desc'))
.setAutocomplete(true)
.setRequired(true)
),

async execute(interaction) {
await interaction.deferReply();
Expand Down
22 changes: 19 additions & 3 deletions commands/progress.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,31 @@ const subCommands = {
hideout: async interaction => {
await interaction.deferReply({ephemeral: true});
const t = getFixedT(interaction.locale);
const stationId = interaction.options.getString('station');
const stations = await gameData.hideout.getAll(interaction.locale);
let stationId;
const stationName = interaction.options.getString('station').toLowerCase();
for (const station of stations) {
if (stationName === 'all') {
stationId = stationName;
break;
}
if (station.name.toLowerCase() === stationName) {
stationId = station.id;
break;
}
}
if (!stationId) {
return interaction.editReply({
content: `❌ ${t('No matching hideout station found.')}`
});
}
const level = interaction.options.getInteger('level');
const prog = await progress.getProgress(interaction.user.id);
let ttWarn = '';
if (prog && prog.tarkovTracker.token) {
ttWarn = '\n'+t('Note: Progress synced via [TarkovTracker](https://tarkovtracker.io/settings/) will overwrite your hideout settings. \nUse `/progress unlink` to stop syncing from TarkovTracker.');
}
if (stationId === 'all') {
const stations = await gameData.hideout.getAll();
for (const station of stations) {
let lvl = level;
let maxValue = station.levels[station.levels.length-1].level;
Expand Down Expand Up @@ -258,7 +274,7 @@ const defaultFunction = {
.setNameLocalizations(getCommandLocalizations('station'))
.setDescriptionLocalizations(getCommandLocalizations('progress_hideout_station_select_desc'))
.setRequired(true)
.setChoices(...gameData.hideout.choices({all: true}))
.setAutocomplete(true)
)
.addIntegerOption(option => option
.setName('level')
Expand Down
22 changes: 19 additions & 3 deletions modules/autocomplete.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import gameData from "./game-data.mjs";
import progress from '../modules/progress-shard.mjs';
import { getCommandLocalizations } from "./translations.mjs";

const caches = {
default: async lang => {
Expand All @@ -26,22 +27,37 @@ const caches = {
},
stim: async lang => {
return gameData.items.getStims(lang).then(items => items.map(item => item.name).sort());
},
hideout: async lang => {
const stations = await gameData.hideout.getAll(lang).then(stations => stations.reduce((all, current) => {
all.push(current.name);
return all;
}, []).sort());
const allOption = allLocalizations[lang] || allLocalizations['en-US'];
stations.push(allOption);
return stations;
}
};

const allLocalizations = getCommandLocalizations('all_desc');

async function autocomplete(interaction) {
let searchString;
try {
searchString = interaction.options.getString('name');
} catch (getError) {
console.error(getError);
}

const cacheFunction = caches[interaction.commandName] || caches.default;
let cacheKey = interaction.commandName;
if (cacheKey === 'progress' && interaction.options.getSubcommand() === 'hideout') {
cacheKey = interaction.options.getSubcommand();
searchString = interaction.options.getString('station');
}
const cacheFunction = caches[cacheKey] || caches.default;
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const nameCache = await cacheFunction(locale);

if (interaction.commandName === 'ammo') {
if (cacheKey === 'ammo') {
return nameCache.filter(name => name.toLowerCase().replace(/\./g, '').includes(searchString.toLowerCase().replace(/\./g, '')));
}

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
},
"type": "module",
"dependencies": {
"@discordjs/rest": "^2.0.1",
"@discordjs/rest": "^2.2.0",
"@sentry/node": "^7.81.1",
"@sentry/tracing": "^7.81.1",
"ascii-table": "^0.0.9",
"cheerio": "^1.0.0-rc.12",
"cron": "^2.4.0",
"cross-env": "^7.0.3",
"discord-api-types": "^0.37.64",
"discord.js": "^14.13.0",
"discord-api-types": "^0.37.67",
"discord.js": "^14.14.1",
"dotenv": "^16.3.1",
"got": "^13.0.0",
"i18next": "^23.7.6",
Expand Down

0 comments on commit e9d8ae7

Please sign in to comment.