修复循环错误

This commit is contained in:
Jerry 2025-05-09 22:42:10 +08:00
parent 72b9b8e4ec
commit 9d96f78921

View File

@ -115,22 +115,27 @@ class BotService {
const userPath = paths.get('userData'); const userPath = paths.get('userData');
const botsPath = path.join(userPath, '/crystelfBots'); const botsPath = path.join(userPath, '/crystelfBots');
const dirData = await fs.readdir(botsPath); const dirData = await fs.readdir(botsPath);
for (const clientId of dirData) { for (const clientId of dirData) {
if (!clientId.endsWith('.json')) continue; if (!clientId.endsWith('.json')) continue;
try { try {
const raw: const raw:
| { uin: number; groups: { group_id: number; group_name: string }[]; nickName: string }[] | { uin: number; groups: { group_id: number; group_name: string }[]; nickName: string }[]
| undefined = await redisService.fetch('crystelfBots', clientId); | undefined = await redisService.fetch('crystelfBots', clientId);
if (!raw) continue; if (!raw) continue;
raw.forEach((bot) => {
for (const bot of raw) {
if (bot.uin && bot.groups) { if (bot.uin && bot.groups) {
if (bot.groups.find((group) => group.group_id == groupId)) return bot.uin; const found = bot.groups.find((group) => group.group_id == groupId);
if (found) return bot.uin;
} }
}); }
} catch (err) { } catch (err) {
logger.error(`读取${clientId}出错..`); logger.error(`读取${clientId}出错..`);
} }
} }
return undefined; return undefined;
} }
} }