优化算法

This commit is contained in:
Jerry 2025-05-07 15:12:23 +08:00
parent 86f8a04112
commit d4035acd43
2 changed files with 8 additions and 17 deletions

View File

@ -45,8 +45,8 @@ class BotController {
* @example req示例 * @example req示例
* ```json * ```json
* { * {
* token: 114514, * token: 114514,
* groupId: 114514 * groupId: 114514
* } * }
* ``` * ```
* @param req * @param req

View File

@ -34,11 +34,11 @@ class BotService {
logger.warn(`解析 ${fileName} 出错: ${e}`); logger.warn(`解析 ${fileName} 出错: ${e}`);
continue; continue;
} }
for (const bot of botList) { botList.forEach((bot) => {
if (bot.uin && bot.nickName) { if (bot.uin && bot.nickName) {
uins.push({ uin: bot.uin, nickName: bot.nickName }); uins.push({ uin: bot.uin, nickName: bot.nickName });
} }
} });
} catch (err) { } catch (err) {
logger.error(`读取或解析 ${fileName} 出错: ${err}`); logger.error(`读取或解析 ${fileName} 出错: ${err}`);
} }
@ -97,12 +97,7 @@ class BotService {
| { uin: string; groups: { group_id: string; group_name: string }[]; nickName: string }[] | { uin: string; groups: { group_id: string; group_name: string }[]; nickName: string }[]
| undefined = await redisService.fetch('crystelfBots', clientId); | undefined = await redisService.fetch('crystelfBots', clientId);
if (!raw) continue; if (!raw) continue;
if (raw.find((bot) => bot.uin === botId)) return clientId;
for (const bot of raw) {
if (bot.uin === botId) {
return clientId;
}
}
} catch (err) { } catch (err) {
logger.error(`读取${clientId}出错..`); logger.error(`读取${clientId}出错..`);
} }
@ -126,15 +121,11 @@ class BotService {
| { uin: string; groups: { group_id: string; group_name: string }[]; nickName: string }[] | { uin: string; groups: { group_id: string; group_name: string }[]; nickName: string }[]
| undefined = await redisService.fetch('crystelfBots', clientId); | undefined = await redisService.fetch('crystelfBots', clientId);
if (!raw) continue; if (!raw) continue;
for (const bot of raw) { raw.forEach((bot) => {
if (bot.uin && bot.groups) { if (bot.uin && bot.groups) {
for (const group of bot.groups) { if (bot.groups.find((group) => group.group_id === groupId)) return bot.uin;
if (group.group_id === groupId) {
return bot.uin;
}
}
} }
} });
} catch (err) { } catch (err) {
logger.error(`读取${clientId}出错..`); logger.error(`读取${clientId}出错..`);
} }