refactor: monorepo structure

NOTE: discord bot moved to apps only
This commit is contained in:
Pihkaal
2025-12-03 14:42:35 +01:00
parent 414509dd6e
commit fd2e2ebd4b
24 changed files with 997 additions and 300 deletions

View File

@@ -0,0 +1,34 @@
import { readFile, writeFile, access } from "node:fs/promises";
import { constants } from "node:fs";
const ACCOUNTS_FILE = "./.cache/accounts.json";
export const initAccounts = async (): Promise<void> => {
try {
await access(ACCOUNTS_FILE, constants.F_OK);
} catch {
await writeFile(ACCOUNTS_FILE, "{}");
}
};
export const getAccountBalance = async (playerId: string): Promise<number> => {
const content = await readFile(ACCOUNTS_FILE, "utf-8");
const accounts: Record<string, number> = JSON.parse(content);
if (accounts[playerId]) return accounts[playerId];
accounts[playerId] = 0;
await writeFile(ACCOUNTS_FILE, JSON.stringify(accounts));
return 0;
};
export const setAccountBalance = async (
playerId: string,
balance: number,
): Promise<void> => {
const content = await readFile(ACCOUNTS_FILE, "utf-8");
const accounts: Record<string, number> = JSON.parse(content);
accounts[playerId] = balance;
await writeFile(ACCOUNTS_FILE, JSON.stringify(accounts));
};