Add ability to view another's inventory #155

Merged
Vylpes merged 6 commits from feature/131-inventory-other into develop 2024-02-16 17:21:50 +00:00
2 changed files with 17 additions and 3 deletions
Showing only changes of commit ab2b5d70af - Show all commits

View file

@ -4,11 +4,20 @@ import InventoryHelper from "../helpers/InventoryHelper";
export default class Inventory extends ButtonEvent { export default class Inventory extends ButtonEvent {
public override async execute(interaction: ButtonInteraction) { public override async execute(interaction: ButtonInteraction) {
if (!interaction.guild) return;
const userid = interaction.customId.split(" ")[1]; const userid = interaction.customId.split(" ")[1];
const page = interaction.customId.split(" ")[2]; const page = interaction.customId.split(" ")[2];
const member = interaction.guild.members.cache.find(x => x.id == userid) || interaction.member;
if (!member) {
await interaction.reply("Unable to find user.");
return;
}
try { 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({ await interaction.update({
embeds: [ embed.embed ], embeds: [ embed.embed ],
Vylpes marked this conversation as resolved Outdated

This should be removed

This should be removed

View file

@ -12,11 +12,16 @@ export default class Inventory extends Command {
.addNumberOption(x => .addNumberOption(x =>
x x
.setName("page") .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) { public override async execute(interaction: CommandInteraction) {
const page = interaction.options.get("page"); const page = interaction.options.get("page");
const user = interaction.options.getUser("user") || interaction.user;
try { try {
let pageNumber = 0; let pageNumber = 0;
@ -25,7 +30,7 @@ export default class Inventory extends Command {
pageNumber = Number(page.value) - 1; 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({ await interaction.reply({
embeds: [ embed.embed ], embeds: [ embed.embed ],