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

Function ensureConfigFile

fadian/fadian.ts:84–100  ·  view source on GitHub ↗
(filename: string)

Source from the content-addressed store, hash-verified

82 // 从缓存获取,如果缓存为空则从文件读取
83 if (!configCache[filename] && fs.existsSync(localPath)) {
84 configCache[filename] = readJsonArray(localPath);
85 }
86
87 return configCache[filename] || [];
88}
89
90async function getPopSentence(
91 filename: string,
92 originals: string[] = [],
93 replacers: string[] = []
94): Promise<string | null> {
95 const list = await ensureConfigFile(filename);
96 if (!list.length) return null;
97 let item = list[Math.floor(Math.random() * list.length)] as string;
98 if (replacers.length === 1) item = item.replace(/<name>/g, replacers[0]);
99 if (replacers.length === 2)
100 item = item
101 .replace(/<name1>/g, replacers[0])
102 .replace(/<name2>/g, replacers[1]);
103 return item;

Callers 1

getPopSentenceFunction · 0.85

Calls 2

downloadConfigFileFunction · 0.85
readJsonArrayFunction · 0.85

Tested by

no test coverage detected