Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes error related to restock alerts #330

Merged
merged 7 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ discordClient.on('interactionCreate', async interaction => {
sendWebhook({
title: `Error running /${interaction.commandName} command on shard ${discordClient.shard.ids[0]}`,
message: error.stack,
footer: `Command invoked by @${interaction.member.user.username} | ${interaction.member.guild ? `Server: ${interaction.member.guild.name}` : 'DM'} | lang: ${lang} | mode ${gameMode}`,
footer: `Command invoked by @${interaction.member?.user?.username ?? 'Unknown User'} | ${interaction.member?.guild ? `Server: ${interaction.member.guild.name}` : 'DM'} | lang: ${lang} | mode ${gameMode}`,
files: [
new AttachmentBuilder(
Buffer.from(JSON.stringify(interaction.options, null, 4), 'utf8'),
Expand Down
2 changes: 1 addition & 1 deletion commands/goons.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const defaultFunction = {
json: {
map: selectedMap.nameId,
timestamp: new Date().getTime(),
accountId: parseInt(interaction.user.id.slice(-10)),
discordId: interaction.user.id,
gameMode: gameMode,
},
}).json();
Expand Down
13 changes: 7 additions & 6 deletions modules/progress.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ const buildDefaultProgress = id => {
restock: {},
},
};
const gameModes = ['regular', 'pve'];
for (const gameMode of gameModes) {
progress[gameMode] = getDefaultGameModeProgress();
progress.alerts[gameMode] = [];
progress.alerts.restock[gameMode] = [];
}
return progress;
};
Expand Down Expand Up @@ -167,9 +166,14 @@ const getUserProgress = async id => {
if (Array.isArray(userProgress[id].alerts.restock)) {
userProgress[id].alerts.restock = {
regular: userProgress[id].alerts.restock,
pve: [],
};
}
for (const gameMode of gameModes) {
if (!userProgress[id].alerts.restock[gameMode]) {
userProgress[id].alerts.restock[gameMode] = [];
}

}
return userProgress[id];
};

Expand Down Expand Up @@ -249,9 +253,6 @@ const addRestockAlert = async (id, traders, locale) => {
if (locale) {
prog.locale = locale;
}
if (!prog.alerts.restock[gameMode]) {
prog.alerts.restock[gameMode] = [];
}
const restockAlerts = prog.alerts.restock[gameMode];
for (const traderId of traders) {
if (!restockAlerts.includes(traderId)) restockAlerts.push(traderId);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "The Tarkov.dev's Escape from Tarkov Discord bot",
"main": "index.mjs",
"engines": {
"node": "20.*"
"node": "22.*"
},
"repository": {
"type": "git",
Expand Down
Loading