2026.4.0-alpha.0
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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({
|
||||
repliedUeuse: [],
|
||||
permissions: {},
|
||||
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;
|
||||
Reference in New Issue
Block a user