46 lines
1017 B
TypeScript
46 lines
1017 B
TypeScript
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
import client from "@/lib/client";
|
|
|
|
const path = `${import.meta.dirname}/../../memory.json`;
|
|
|
|
class MemoryClass {
|
|
private cachedMemory: any;
|
|
|
|
constructor() {
|
|
if (!existsSync(path)) {
|
|
writeFileSync(path, JSON.stringify({
|
|
processedInfo: [],
|
|
permissions: {},
|
|
lastReadMention: "",
|
|
lastReadReply: "",
|
|
userid: "",
|
|
}));
|
|
}
|
|
|
|
this.cachedMemory = JSON.parse(readFileSync(path, "utf-8"));
|
|
}
|
|
|
|
get memory() {
|
|
return this.cachedMemory;
|
|
}
|
|
|
|
set memory(data: any) {
|
|
this.cachedMemory = data;
|
|
writeFileSync(path, JSON.stringify(this.cachedMemory), "utf-8");
|
|
}
|
|
}
|
|
|
|
const Memory = new MemoryClass();
|
|
|
|
export const initUserID = async () => {
|
|
const response = await client.request("me/");
|
|
|
|
if (!response.success)
|
|
throw new Error("meの取得に失敗しました");
|
|
|
|
const mem = Memory.memory;
|
|
mem.userid = response.userid;
|
|
Memory.memory = mem;
|
|
}
|
|
|
|
export default Memory; |