mirror of
https://github.com/crystelf/crystelf-core.git
synced 2025-07-04 14:49:19 +00:00
优化getBotId路由
This commit is contained in:
parent
4c9e06deeb
commit
952f9711eb
@ -13,26 +13,33 @@ class BotService {
|
||||
const userPath = paths.get('userData');
|
||||
const botsPath = path.join(userPath, '/crystelfBots');
|
||||
const dirData = await fs.readdir(botsPath);
|
||||
const uins: string[] = [];
|
||||
const uins: { uin: string; nickName: string }[] = [];
|
||||
|
||||
for (const fileName of dirData) {
|
||||
if (!fileName.endsWith('.json')) {
|
||||
if (!fileName.endsWith('.json')) continue;
|
||||
|
||||
try {
|
||||
const raw: [] | undefined = await redisService.fetch('crystelfBots', fileName);
|
||||
if (!raw) continue;
|
||||
|
||||
let botList: any[];
|
||||
try {
|
||||
botList = raw;
|
||||
if (!Array.isArray(botList)) {
|
||||
logger.warn(`${fileName}不是数组,已跳过`);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const fileContent: string | undefined = await redisService.fetch('crystelfBots', fileName);
|
||||
if (fileContent) {
|
||||
uins.push(fileContent);
|
||||
} catch (e) {
|
||||
logger.warn(`解析 ${fileName} 出错: ${e}`);
|
||||
continue;
|
||||
}
|
||||
for (const bot of botList) {
|
||||
if (bot.uin && bot.nickName) {
|
||||
uins.push({ uin: bot.uin, nickName: bot.nickName });
|
||||
}
|
||||
}
|
||||
/*
|
||||
const filePath = path.join(botsPath, fileName);
|
||||
const fileContent = await fs.readFile(filePath, 'utf-8');
|
||||
const jsonData = JSON.parse(fileContent);
|
||||
if (jsonData.uin) {
|
||||
uins.push(jsonData.uin);
|
||||
}*/
|
||||
} catch (err) {
|
||||
logger.error(`读取或解析${fileName}出错: ${err}`);
|
||||
logger.error(`读取或解析 ${fileName} 出错: ${err}`);
|
||||
}
|
||||
}
|
||||
logger.debug(uins);
|
||||
|
@ -1,8 +1,9 @@
|
||||
import WebSocket from 'ws';
|
||||
import axios from 'axios';
|
||||
import logger from '../utils/core/logger';
|
||||
|
||||
const WS_URL = 'ws://server.crystelf.top:4001';
|
||||
const WS_SECRET = '520520';
|
||||
const WS_URL = 'ws://127.0.0.1:4001';
|
||||
const WS_SECRET = '114514';
|
||||
const CLIENT_ID = 'test';
|
||||
|
||||
function createWebSocketClient() {
|
||||
@ -48,10 +49,10 @@ async function testGetAPI() {
|
||||
|
||||
async function testPostAPI() {
|
||||
try {
|
||||
const response = await axios.post('https://core.crystelf.top/api/system/restart', {
|
||||
token: 114113,
|
||||
const response = await axios.post('http://127.0.0.1:4000/api/bot/getBotId', {
|
||||
token: 54188,
|
||||
});
|
||||
console.log('[HTTP][POST] Response:', response.data);
|
||||
logger.info('[HTTP][POST] Response:', response.data);
|
||||
} catch (err) {
|
||||
console.error('[HTTP][POST] Error:', err);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user