forked from syntaxbullet/AuroraBot-discord
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { createCommand } from "@/lib/utils";
|
|
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
|
|
import { inventoryService } from "@/modules/inventory/inventory.service";
|
|
import { userService } from "@/modules/user/user.service";
|
|
import { createWarningEmbed } from "@lib/embeds";
|
|
|
|
export const inventory = createCommand({
|
|
data: new SlashCommandBuilder()
|
|
.setName("inventory")
|
|
.setDescription("View your or another user's inventory")
|
|
.addUserOption(option =>
|
|
option.setName("user")
|
|
.setDescription("User to view")
|
|
.setRequired(false)
|
|
),
|
|
execute: async (interaction) => {
|
|
await interaction.deferReply();
|
|
|
|
const targetUser = interaction.options.getUser("user") || interaction.user;
|
|
const user = await userService.getOrCreateUser(targetUser.id, targetUser.username);
|
|
const items = await inventoryService.getInventory(user.id);
|
|
|
|
if (!items || items.length === 0) {
|
|
await interaction.editReply({ embeds: [createWarningEmbed("Inventory is empty.", `${user.username}'s Inventory`)] });
|
|
return;
|
|
}
|
|
|
|
const description = items.map(entry => {
|
|
return `**${entry.item.name}** x${entry.quantity}`;
|
|
}).join("\n");
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setTitle(`${user.username}'s Inventory`)
|
|
.setDescription(description)
|
|
.setColor("Blue")
|
|
.setTimestamp();
|
|
|
|
await interaction.editReply({ embeds: [embed] });
|
|
}
|
|
});
|