Initial code

This commit is contained in:
Aslan 2025-12-23 07:18:10 -05:00
commit 1f20a611da
26 changed files with 1050 additions and 0 deletions

2
src/store/index.ts Normal file
View file

@ -0,0 +1,2 @@
export * from "./store.js";
export * from "./types.js";

25
src/store/store.ts Normal file
View file

@ -0,0 +1,25 @@
import config from "../config.json" with { type: "json" };
import { existsSync, readFileSync, writeFileSync } from "fs";
import type { IState } from "./types.js";
let state: IState = {
users: [],
};
const load = () => {
if (!existsSync(config.storePath)) {
return;
}
const json = readFileSync(config.storePath).toString();
state = JSON.parse(json) as IState;
};
const save = () => {
const json = JSON.stringify(state);
writeFileSync(config.storePath, json);
};
export { state, load, save };

14
src/store/types.ts Normal file
View file

@ -0,0 +1,14 @@
interface IState {
users: IUser[];
}
interface IUser {
id: string;
role: TRole;
experience: number;
lastMessageTimestamp: number;
}
type TRole = "NONE" | "USER" | "MODERATOR" | "ADMIN";
export { type IState, type IUser, type TRole };