/inventory

This commit is contained in:
Jill 2023-11-15 03:50:29 +03:00
parent 2a2cdb8dff
commit 4351e6dfad
Signed by: oat
GPG Key ID: 33489AA58A955108
1 changed files with 27 additions and 0 deletions

27
src/commands/inventory.ts Normal file
View File

@ -0,0 +1,27 @@
import { GuildMember, Interaction, SlashCommandBuilder } from 'discord.js';
import { ItemInventory, db } from '../lib/db';
import { formatItems, getItem } from '../lib/items';
module.exports = {
data: new SlashCommandBuilder()
.setName('inventory')
.setDescription('Check your inventory')
.setDMPermission(false),
execute: async (interaction: Interaction, member: GuildMember) => {
if (!interaction.isChatInputCommand()) return;
await interaction.deferReply({ephemeral: true});
const itemsList = await db<ItemInventory>('itemInventories')
.select('item', 'quantity')
.where('user', member.user.id);
// kind of stupid kind of awful
const items = (await Promise.all(itemsList.map(async i => ({item: await getItem(i.item), quantity: i.quantity})))).filter(i => i.item);
await interaction.followUp(
`Your inventory:\n${items.length === 0 ? '_Your inventory is empty!_' : items.map(i => `- ${formatItems(i.item!, i.quantity)}`).join('\n')}`
);
}
};