jillo-bot/src/commands/inventory.ts

33 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-11-16 11:33:11 +01:00
import { GuildMember, CommandInteraction, SlashCommandBuilder } from 'discord.js';
2023-11-15 01:50:29 +01:00
import { ItemInventory, db } from '../lib/db';
2023-11-15 11:57:20 +01:00
import { formatItems, getItem } from '../lib/rpg/items';
2023-11-21 20:17:15 +01:00
import { initHealth } from '../lib/rpg/pvp';
2023-11-16 11:33:11 +01:00
import { Command } from '../types/index';
2023-11-15 01:50:29 +01:00
2023-11-16 11:33:11 +01:00
export default {
2023-11-15 01:50:29 +01:00
data: new SlashCommandBuilder()
.setName('inventory')
.setDescription('Check your inventory')
.setDMPermission(false),
2023-11-16 11:33:11 +01:00
execute: async (interaction: CommandInteraction) => {
2023-11-15 01:50:29 +01:00
if (!interaction.isChatInputCommand()) return;
2023-11-16 11:33:11 +01:00
const member = interaction.member! as GuildMember;
2023-11-21 20:17:15 +01:00
await initHealth(member.id);
2023-11-15 01:50:29 +01:00
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
2023-11-19 18:01:00 +01:00
const items = (await Promise.all(itemsList.map(async i => ({item: await getItem(i.item), quantity: i.quantity})))).filter(i => i.item && i.quantity !== 0);
2023-11-15 01:50:29 +01:00
await interaction.followUp(
2023-11-15 22:01:55 +01:00
`Your inventory:\n${items.length === 0 ? '_Your inventory is empty!_' : items.map(i => `- ${formatItems(i.item!, i.quantity)}\n_${i.item!.description}_`).join('\n')}`
2023-11-15 01:50:29 +01:00
);
}
2023-11-16 11:33:11 +01:00
} satisfies Command;