@zaofan/dsh-qqbot 1.10.32 → 1.10.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/settings-host.js +28 -2
package/package.json
CHANGED
package/settings-host.js
CHANGED
|
@@ -312,16 +312,42 @@ function resolveProfileName() {
|
|
|
312
312
|
* (真实存档在 qqbot-settings/desktop/xxx.json)⇒ 凭据读不到 ⇒ nsBot() null。
|
|
313
313
|
* 改成每次调用时现算(开销是几次字符串/目录读,API 请求级,可忽略)。
|
|
314
314
|
*/
|
|
315
|
-
function nsProfileDir() {
|
|
315
|
+
function nsProfileDir(ns) {
|
|
316
316
|
const n = String(resolveProfileName()).trim().replace(/[^A-Za-z0-9_-]/g, '_');
|
|
317
317
|
if (n) return n;
|
|
318
|
+
|
|
319
|
+
// ── 目录级兜底(只在上面几层全空时走到这儿)──
|
|
320
|
+
// 2026-10-25 修 issue #20 + 主人追问「同时装了 desktop 和 web 怎么办」:
|
|
321
|
+
// 一台机器上 qqbot-settings/ 可能同时有 web/ 和 desktop/,
|
|
322
|
+
// 这时**不能猜**(猜错 = 读到别人的凭据),要用事实来判断。
|
|
323
|
+
try {
|
|
324
|
+
const subs = readdirSync(OWN_SETTINGS_DIR, { withFileTypes: true })
|
|
325
|
+
.filter((d) => d.isDirectory() && d.name !== '_default')
|
|
326
|
+
.map((d) => d.name);
|
|
327
|
+
|
|
328
|
+
// ① 只有一个 profile 目录 → 就是它
|
|
329
|
+
if (subs.length === 1) return subs[0];
|
|
330
|
+
|
|
331
|
+
// ② 多个目录 → 看哪个目录里**真的存着这个 ns 的配置**
|
|
332
|
+
// (凭据就在 <profile>/<ns>.json,谁有谁就是当前 profile)
|
|
333
|
+
if (ns) {
|
|
334
|
+
const f = safeNsOf(ns) + '.json';
|
|
335
|
+
const hits = subs.filter((name) => {
|
|
336
|
+
try { return existsSync(join(OWN_SETTINGS_DIR, name, f)); } catch { return false; }
|
|
337
|
+
});
|
|
338
|
+
if (hits.length === 1) return hits[0];
|
|
339
|
+
// 两个 profile 都配过同一个 ns → 不猜,走 _default。
|
|
340
|
+
// 这种「共用一个 settingsNs」的情况本来就会被 writer.json 的 NS_CONFLICT 拦住。
|
|
341
|
+
}
|
|
342
|
+
} catch { /* 目录还不存在(首次启动) */ }
|
|
343
|
+
|
|
318
344
|
return '_default';
|
|
319
345
|
}
|
|
320
346
|
function safeNsOf(ns) {
|
|
321
347
|
return String(ns || NS).replace(/[^A-Za-z0-9_-]/g, '_') || 'im-qqbot';
|
|
322
348
|
}
|
|
323
349
|
function ownSettingsDir(ns) {
|
|
324
|
-
return join(OWN_SETTINGS_DIR, nsProfileDir());
|
|
350
|
+
return join(OWN_SETTINGS_DIR, nsProfileDir(ns));
|
|
325
351
|
}
|
|
326
352
|
function ownSettingsPath(ns) {
|
|
327
353
|
return join(ownSettingsDir(ns), safeNsOf(ns) + '.json');
|