27 lines
1017 B
TypeScript
27 lines
1017 B
TypeScript
import { GuildMember, Interaction, SlashCommandBuilder } from 'discord.js';
|
|
import { ItemInventory, db } from '../lib/db';
|
|
import { formatItems, getItem } from '../lib/rpg/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')}`
|
|
);
|
|
}
|
|
}; |