View others' sacks
This commit is contained in:
parent
fe2c3a77da
commit
4056843f1a
|
@ -1,5 +1,7 @@
|
||||||
import Command from "@server/commands/Command";
|
import Command from "@server/commands/Command";
|
||||||
import { getInventory } from "@server/data/inventory";
|
import { getInventory } from "@server/data/inventory";
|
||||||
|
import prisma from "@server/data/prisma";
|
||||||
|
import type { User } from "@prisma/client";
|
||||||
|
|
||||||
export const sack = new Command(
|
export const sack = new Command(
|
||||||
"sack",
|
"sack",
|
||||||
|
@ -8,9 +10,46 @@ export const sack = new Command(
|
||||||
"sack",
|
"sack",
|
||||||
"command.inventory.sack",
|
"command.inventory.sack",
|
||||||
async ({ id, command, args, prefix, part, user }) => {
|
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);
|
const inv = await getInventory(user.inventoryId);
|
||||||
if (!inv) return;
|
if (!inv) return;
|
||||||
|
|
||||||
const fishSack = inv.fishSack as TFishSack;
|
const fishSack = inv.fishSack as TFishSack;
|
||||||
|
|
||||||
return `Contents of ${part.name}'s fish sack: ${
|
return `Contents of ${part.name}'s fish sack: ${
|
||||||
|
@ -24,4 +63,5 @@ export const sack = new Command(
|
||||||
.join(", ") || "(none)"
|
.join(", ") || "(none)"
|
||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue