refactor: add inventory view layer
Create inventory.view.ts with UI logic extracted from commands: - getInventoryEmbed() for inventory display - getItemUseResultEmbed() for item use results Updated commands with proper type safety: - inventory.ts: add null check, convert user.id to string - use.ts: add null check, convert user.id to string Improves separation of concerns and type safety.
This commit is contained in:
40
src/modules/inventory/inventory.view.ts
Normal file
40
src/modules/inventory/inventory.view.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { EmbedBuilder } from "discord.js";
|
||||
import type { ItemUsageData } from "@/lib/types";
|
||||
|
||||
/**
|
||||
* Inventory entry with item details
|
||||
*/
|
||||
interface InventoryEntry {
|
||||
quantity: bigint | null;
|
||||
item: {
|
||||
id: number;
|
||||
name: string;
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an embed displaying a user's inventory
|
||||
*/
|
||||
export function getInventoryEmbed(items: InventoryEntry[], username: string): EmbedBuilder {
|
||||
const description = items.map(entry => {
|
||||
return `**${entry.item.name}** x${entry.quantity}`;
|
||||
}).join("\n");
|
||||
|
||||
return new EmbedBuilder()
|
||||
.setTitle(`📦 ${username}'s Inventory`)
|
||||
.setDescription(description)
|
||||
.setColor(0x3498db); // Blue
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an embed showing the results of using an item
|
||||
*/
|
||||
export function getItemUseResultEmbed(results: string[], itemName?: string): EmbedBuilder {
|
||||
const description = results.map(r => `• ${r}`).join("\n");
|
||||
|
||||
return new EmbedBuilder()
|
||||
.setTitle("✅ Item Used!")
|
||||
.setDescription(description)
|
||||
.setColor(0x2ecc71); // Green/Success
|
||||
}
|
||||
Reference in New Issue
Block a user