item transfer, item to buy other items, item income, unbuyable items

This commit is contained in:
stjet
2024-09-13 18:17:44 +00:00
parent 3145f52df7
commit c2d1cd2af1
18 changed files with 407 additions and 56 deletions

16
commands/common/common.ts Normal file
View File

@@ -0,0 +1,16 @@
import { get_item } from "../../db";
//if return string, that is error message
export async function items_string_to_items(items_string: string): Promise<[string, number][] | string> {
let items = [];
for (const item of items_string.split("|")) {
const parts = item.split(",");
if (parts.length !== 2) return "Incorrect items format, must be `name,quantity|name,quantity`, etc";
const quantity = Number(parts[1]);
if (isNaN(quantity) || Math.floor(quantity) !== quantity) return "Item quantity was not an integer";
if (!await get_item(parts[0])) return `Item \`${parts[0].replaceAll("`", "\\`")}\` does not exist`;
items.push([parts[0], quantity]);
}
return items;
}