Add ability to view another's inventory (#155)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
# Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. - Add ability to view another user's inventory - Fix bug where the inventory generation logic was overriding the main array #131, #138 ## Type of change Please delete options that are not relevant. - [x] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) # How Has This Been Tested? Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration. # Checklist - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that provde my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/155 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
4c97d41495
commit
6ee8db6232
58
package-lock.json
generated
58
package-lock.json
generated
|
@ -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",
|
||||
|
@ -10242,6 +10289,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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -4,17 +4,27 @@ 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({
|
||||
embeds: [ embed.embed ],
|
||||
components: [ embed.row ],
|
||||
});
|
||||
} catch {
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
await interaction.reply("No page for user found.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,7 +30,7 @@ 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({
|
||||
embeds: [ embed.embed ],
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue