(filename: string)
| 82 | // 从缓存获取,如果缓存为空则从文件读取 |
| 83 | if (!configCache[filename] && fs.existsSync(localPath)) { |
| 84 | configCache[filename] = readJsonArray(localPath); |
| 85 | } |
| 86 | |
| 87 | return configCache[filename] || []; |
| 88 | } |
| 89 | |
| 90 | async 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; |
no test coverage detected