Compare commits

...

2 commits

Author SHA1 Message Date
664d3d1888 Fix inventory overriding the main array
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
2024-02-02 18:53:07 +00:00
ab2b5d70af Allow viewing other users inventories 2024-02-02 17:54:34 +00:00
5 changed files with 85 additions and 5 deletions

58
package-lock.json generated
View file

@ -10,10 +10,12 @@
"license": "MIT",
"dependencies": {
"@discordjs/rest": "^2.0.0",
"@types/clone-deep": "^4.0.4",
"@types/express": "^4.17.20",
"@types/jest": "^29.0.0",
"@types/uuid": "^9.0.0",
"body-parser": "^1.20.2",
"clone-deep": "^4.0.1",
"discord.js": "^14.3.0",
"dotenv": "^16.0.0",
"express": "^4.18.2",
@ -1785,6 +1787,11 @@
"@types/responselike": "^1.0.0"
}
},
"node_modules/@types/clone-deep": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/@types/clone-deep/-/clone-deep-4.0.4.tgz",
"integrity": "sha512-vXh6JuuaAha6sqEbJueYdh5zNBPPgG1OYumuz2UvLvriN6ABHDSW8ludREGWJb1MLIzbwZn4q4zUbUCerJTJfA=="
},
"node_modules/@types/connect": {
"version": "3.4.38",
"license": "MIT",
@ -3788,6 +3795,19 @@
"node": ">=0.8"
}
},
"node_modules/clone-deep": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-4.0.1.tgz",
"integrity": "sha512-neHB9xuzh/wk0dIHweyAXv2aPGZIVk3pLMe+/RNzINf17fe0OG96QroktYAUm7SM1PBnzTabaLboqqxDyMU+SQ==",
"dependencies": {
"is-plain-object": "^2.0.4",
"kind-of": "^6.0.2",
"shallow-clone": "^3.0.0"
},
"engines": {
"node": ">=6"
}
},
"node_modules/clone-response": {
"version": "1.0.3",
"dev": true,
@ -6425,6 +6445,17 @@
"node": ">=8"
}
},
"node_modules/is-plain-object": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
"integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==",
"dependencies": {
"isobject": "^3.0.1"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/is-promise": {
"version": "2.2.2",
"dev": true,
@ -6500,6 +6531,14 @@
"version": "2.0.0",
"license": "ISC"
},
"node_modules/isobject": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz",
"integrity": "sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/issue-regex": {
"version": "4.1.0",
"dev": true,
@ -7300,6 +7339,14 @@
"json-buffer": "3.0.1"
}
},
"node_modules/kind-of": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz",
"integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/kleur": {
"version": "3.0.3",
"license": "MIT",
@ -10241,6 +10288,17 @@
"sha.js": "bin.js"
}
},
"node_modules/shallow-clone": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz",
"integrity": "sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==",
"dependencies": {
"kind-of": "^6.0.2"
},
"engines": {
"node": ">=8"
}
},
"node_modules/shebang-command": {
"version": "2.0.0",
"license": "MIT",

View file

@ -26,10 +26,12 @@
"funding": "https://ko-fi.com/vylpes",
"dependencies": {
"@discordjs/rest": "^2.0.0",
"@types/clone-deep": "^4.0.4",
"@types/express": "^4.17.20",
"@types/jest": "^29.0.0",
"@types/uuid": "^9.0.0",
"body-parser": "^1.20.2",
"clone-deep": "^4.0.1",
"discord.js": "^14.3.0",
"dotenv": "^16.0.0",
"express": "^4.18.2",

View file

@ -4,17 +4,28 @@ import InventoryHelper from "../helpers/InventoryHelper";
export default class Inventory extends ButtonEvent {
public override async execute(interaction: ButtonInteraction) {
if (!interaction.guild) return;
const userid = interaction.customId.split(" ")[1];
const page = interaction.customId.split(" ")[2];
const member = interaction.guild.members.cache.find(x => x.id == userid) || await interaction.guild.members.fetch(userid);
if (!member) {
await interaction.reply("Unable to find user.");
return;
}
try {
const embed = await InventoryHelper.GenerateInventoryPage(interaction.user.username, userid, Number(page));
const embed = await InventoryHelper.GenerateInventoryPage(member.user.username, member.user.id, Number(page));
await interaction.update({
content: `${member.user.username} - ${member.user.id}`,
embeds: [ embed.embed ],
components: [ embed.row ],
});
} catch {
} catch (e) {
console.error(e);
await interaction.reply("No page for user found.");
}
}

View file

@ -12,11 +12,16 @@ export default class Inventory extends Command {
.addNumberOption(x =>
x
.setName("page")
.setDescription("The page to start with"));
.setDescription("The page to start with"))
.addUserOption(x =>
x
.setName("user")
.setDescription("The user to view (Defaults to yourself)"));
}
public override async execute(interaction: CommandInteraction) {
const page = interaction.options.get("page");
const user = interaction.options.getUser("user") || interaction.user;
try {
let pageNumber = 0;
@ -25,9 +30,10 @@ export default class Inventory extends Command {
pageNumber = Number(page.value) - 1;
}
const embed = await InventoryHelper.GenerateInventoryPage(interaction.user.username, interaction.user.id, pageNumber);
const embed = await InventoryHelper.GenerateInventoryPage(user.username, user.id, pageNumber);
await interaction.reply({
content: `${user.username} - ${user.id}`,
embeds: [ embed.embed ],
components: [ embed.row ],
});

View file

@ -3,6 +3,7 @@ import Inventory from "../database/entities/app/Inventory";
import { CoreClient } from "../client/client";
import EmbedColours from "../constants/EmbedColours";
import { CardRarity, CardRarityToString } from "../constants/CardRarity";
import cloneDeep from "clone-deep";
interface InventoryPage {
id: number,
@ -24,7 +25,9 @@ export default class InventoryHelper {
const inventory = await Inventory.FetchAllByUserId(userid);
const allSeriesClaimed = CoreClient.Cards
const clientCards = cloneDeep(CoreClient.Cards);
const allSeriesClaimed = clientCards
.sort((a, b) => a.id - b.id)
.filter(x => {
x.cards = x.cards