View others' sacks

This commit is contained in:
Hri7566 2024-02-23 17:14:39 -05:00
parent fe2c3a77da
commit 4056843f1a
1 changed files with 53 additions and 13 deletions

View File

@ -1,5 +1,7 @@
import Command from "@server/commands/Command";
import { getInventory } from "@server/data/inventory";
import prisma from "@server/data/prisma";
import type { User } from "@prisma/client";
export const sack = new Command(
"sack",
@ -8,9 +10,46 @@ export const sack = new Command(
"sack",
"command.inventory.sack",
async ({ id, command, args, prefix, part, user }) => {
if (args[0]) {
let decidedUser: User = user;
decidedUser = (await prisma.user.findFirst({
where: {
name: {
contains: args[0]
}
}
})) as User;
if (!decidedUser)
decidedUser = (await prisma.user.findFirst({
where: {
id: {
contains: args[0]
}
}
})) as User;
if (!decidedUser) return `User "${args[0]}" not found.`;
const inv = await getInventory(decidedUser.inventoryId);
if (!inv)
return `This message should be impossible to see because friend ${decidedUser.name}'s fish sack (and, by extension, their entire inventory) does not exist.`;
const fishSack = inv.fishSack as TFishSack;
return `Contents of ${decidedUser.name}'s fish sack: ${
fishSack
.map(
(fish: IFish) =>
`${fish.emoji || "🐟"}${fish.name}${
fish.count ? ` (x${fish.count})` : ""
}`
)
.join(", ") || "(none)"
}`;
} else {
const inv = await getInventory(user.inventoryId);
if (!inv) return;
const fishSack = inv.fishSack as TFishSack;
return `Contents of ${part.name}'s fish sack: ${
@ -24,4 +63,5 @@ export const sack = new Command(
.join(", ") || "(none)"
}`;
}
}
);