MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / loadUserData

Function loadUserData

t/t.ts:35–63  ·  view source on GitHub ↗

读取 + 同步角色(把代码里的新角色并入到 json,不覆盖已有同名条目)

()

Source from the content-addressed store, hash-verified

33 plugin: "t",
34 fileName: DATA_FILE_NAME,
35 legacyDirs: ["tts-plugin"],
36 legacyFiles: [{ dir: "tts-plugin", fileName: DATA_FILE_NAME }],
37});
38const cacheDir = createDirectoryInAssets("t/cache", ["tts-plugin/cache"]);
39
40/** 读取 + 同步角色(把代码里的新角色并入到 json,不覆盖已有同名条目) */
41async function loadUserData(): Promise<AllUserData> {
42 try {
43 const data = await fs.readFile(dataFilePath, "utf8");
44 const parsed: AllUserData = JSON.parse(data);
45
46 if (!parsed.roles) parsed.roles = {};
47 if (!parsed.covers) parsed.covers = { "薯薯": "https://raw.githubusercontent.com/Yu9191/-/main/image.png" };
48
49 // 合并新增的内置角色
50 const initial = getInitialRoles();
51 let changed = false;
52 for (const [name, id] of Object.entries(initial)) {
53 if (!(name in parsed.roles)) {
54 parsed.roles[name] = id;
55 changed = true;
56 }
57 }
58 if (changed) await saveUserData(parsed);
59 return parsed;
60 } catch {
61 const initial: AllUserData = {
62 users: {},
63 roles: getInitialRoles(),
64 covers: { "薯薯": "https://raw.githubusercontent.com/Yu9191/-/main/image.png" }
65 };
66 await saveUserData(initial);

Callers 3

ttsFunction · 0.85
ttsSetFunction · 0.85
setApiKeyFunction · 0.85

Calls 2

getInitialRolesFunction · 0.85
saveUserDataFunction · 0.85

Tested by

no test coverage detected