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,24 +13,31 @@ 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);
|
||||||
const uins: string[] = [];
|
const uins: { uin: string; nickName: string }[] = [];
|
||||||
|
|
||||||
for (const fileName of dirData) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
} catch (e) {
|
||||||
const fileContent: string | undefined = await redisService.fetch('crystelfBots', fileName);
|
logger.warn(`解析 ${fileName} 出错: ${e}`);
|
||||||
if (fileContent) {
|
continue;
|
||||||
uins.push(fileContent);
|
}
|
||||||
|
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) {
|
} catch (err) {
|
||||||
logger.error(`读取或解析 ${fileName} 出错: ${err}`);
|
logger.error(`读取或解析 ${fileName} 出错: ${err}`);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import WebSocket from 'ws';
|
import WebSocket from 'ws';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import logger from '../utils/core/logger';
|
||||||
|
|
||||||
const WS_URL = 'ws://server.crystelf.top:4001';
|
const WS_URL = 'ws://127.0.0.1:4001';
|
||||||
const WS_SECRET = '520520';
|
const WS_SECRET = '114514';
|
||||||
const CLIENT_ID = 'test';
|
const CLIENT_ID = 'test';
|
||||||
|
|
||||||
function createWebSocketClient() {
|
function createWebSocketClient() {
|
||||||
@ -48,10 +49,10 @@ async function testGetAPI() {
|
|||||||
|
|
||||||
async function testPostAPI() {
|
async function testPostAPI() {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post('https://core.crystelf.top/api/system/restart', {
|
const response = await axios.post('http://127.0.0.1:4000/api/bot/getBotId', {
|
||||||
token: 114113,
|
token: 54188,
|
||||||
});
|
});
|
||||||
console.log('[HTTP][POST] Response:', response.data);
|
logger.info('[HTTP][POST] Response:', response.data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[HTTP][POST] Error:', err);
|
console.error('[HTTP][POST] Error:', err);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user