+
-

+
-
昵称:{ user.nickname || "未获取" }
-
QQ号:{ user.user_id || "NaN" }
+
昵称:{ user?.nickname || "未获取" }
+
QQ号:{ user?.user_id || "NaN" }
协议信息:
-
{ versionInfo.app_name }
-
{ versionInfo.app_version }
-
{ versionInfo.protocol_version }
+
{ user?.app_name }
+
{ user?.app_version }
+
{ user?.protocol_version }
diff --git a/server/components/home/bot-network.jsx b/server/components/home/bot-network.jsx
index abc3feb..65b7fe9 100644
--- a/server/components/home/bot-network.jsx
+++ b/server/components/home/bot-network.jsx
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from "react";
-import { NETWORK_BASE_URL } from "../../constants/system.js";
+import { NETWORK_BASE_URL } from "../../constants/api.js";
// 测试链接配置
const TESTING_LINKS = [
diff --git a/server/components/home/system.jsx b/server/components/home/system.jsx
index b0be871..0754bbb 100644
--- a/server/components/home/system.jsx
+++ b/server/components/home/system.jsx
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import { CircularProgressbar, buildStyles } from 'react-circular-progressbar';
import 'react-circular-progressbar/dist/styles.css';
-import { SYSTEM_BASE_URL } from "../../constants/system.js";
+import { SYSTEM_BASE_URL } from "../../constants/api.js";
export default function System() {
const [systemInfo, setSystemInfo] = useState(null);
diff --git a/server/constants/system.js b/server/constants/api.js
similarity index 73%
rename from server/constants/system.js
rename to server/constants/api.js
index 648c8b1..c9d2595 100644
--- a/server/constants/system.js
+++ b/server/constants/api.js
@@ -3,3 +3,5 @@ const BASE_URL = "/r/api";
export const SYSTEM_BASE_URL = `${BASE_URL}/system`;
export const NETWORK_BASE_URL = `${BASE_URL}/network?url=`;
+
+export const BOT_INFO_URL = `${ BASE_URL }/bot`;
diff --git a/server/constants/napcat.js b/server/constants/napcat.js
deleted file mode 100644
index 3cd8565..0000000
--- a/server/constants/napcat.js
+++ /dev/null
@@ -1,11 +0,0 @@
-export const NAPCAT_BASE_URL = "/r/api/napcat";
-
-/**
- * 获取登录号信息
- * @type {string}
- */
-export const NAPCAT_GET_LOGIN_INFO = `${NAPCAT_BASE_URL}/get_login_info`;
-
-export const NAPCAT_GET_STATUS = `${ NAPCAT_BASE_URL }/get_status`;
-
-export const NAPCAT_GET_VERSION_INFO = `${ NAPCAT_BASE_URL }/get_version_info`;
diff --git a/server/utils/axiosInstance.js b/server/utils/axiosInstance.js
deleted file mode 100644
index e446da2..0000000
--- a/server/utils/axiosInstance.js
+++ /dev/null
@@ -1,50 +0,0 @@
-import axios from 'axios';
-
-// 创建 Axios 实例
-const axiosInstance = axios.create({
- baseURL: 'http://192.168.31.230:2537', // 基础请求地址
- timeout: 5000, // 设置请求超时时间,可根据需要调整
- headers: {
- 'Content-Type': 'application/json',
- },
-});
-
-// 请求拦截器
-axiosInstance.interceptors.request.use(
- (config) => {
- // 这里可以添加请求前的处理逻辑,例如添加 token
- // const token = localStorage.getItem('token');
- // if (token) {
- // config.headers.Authorization = `Bearer ${token}`;
- // }
- return config;
- },
- (error) => {
- // 请求错误处理
- return Promise.reject(error);
- }
-);
-
-// 响应拦截器
-axiosInstance.interceptors.response.use(
- (response) => {
- // 响应成功处理
- return response.data;
- },
- (error) => {
- // 响应错误处理
- if (error.response) {
- // 服务器返回的错误
- console.error('Error:', error.response.status, error.response.data);
- } else if (error.request) {
- // 请求未收到服务器响应
- console.error('No response received:', error.request);
- } else {
- // 设置请求时发生的错误
- console.error('Request setup error:', error.message);
- }
- return Promise.reject(error);
- }
-);
-
-export default axiosInstance;
diff --git a/server/utils/napact.js b/server/utils/napact.js
deleted file mode 100644
index 7f3735d..0000000
--- a/server/utils/napact.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import { NAPCAT_GET_LOGIN_INFO, NAPCAT_GET_STATUS, NAPCAT_GET_VERSION_INFO } from "../constants/napcat.js";
-
-export async function getUserInfo() {
- const userInfo = await fetch(NAPCAT_GET_LOGIN_INFO).then(resp => resp.json());
- const { user_id, nickname } = userInfo.data;
- return { user_id, nickname }
-}
-
-export async function getStatus() {
- const status = await fetch(NAPCAT_GET_STATUS).then(resp => resp.json());
- return status.data;
-}
-
-export async function getVersionInfo() {
- const versionInfo = await fetch(NAPCAT_GET_VERSION_INFO).then(resp => resp.json());
- return versionInfo.data;
-}
diff --git a/server/utils/redis.js b/server/utils/redis.js
new file mode 100644
index 0000000..3744815
--- /dev/null
+++ b/server/utils/redis.js
@@ -0,0 +1,17 @@
+import fs from "fs";
+import Redis from "ioredis";
+import yaml from "js-yaml";
+import path from "path";
+
+const configPath = path.join(process.cwd(), "../../../", "config", 'config', 'redis.yaml');
+
+const yamlContent = await fs.promises.readFile(configPath, 'utf8');
+const config = yaml.load(yamlContent);
+
+export const redis = new Redis({
+ port: config.port,
+ host: config.host,
+ username: config.username,
+ password: config.password,
+ db: config.db,
+})
diff --git a/start-nextjs.js b/start-nextjs.js
index d2d5543..222c859 100644
--- a/start-nextjs.js
+++ b/start-nextjs.js
@@ -1,8 +1,10 @@
import { spawn } from 'child_process';
+import child_process from "node:child_process";
+import { getBotLoginInfo, getBotStatus, getBotVersionInfo } from "./utils/yunzai-util.js";
logger.info(`[R插件][Next.js监测], 父进程 PID: ${process.pid}`);
-let childProcess = null;
+let nextjsProcess = null;
// 构建应用程序
export const buildNextJs = () => {
@@ -10,7 +12,7 @@ export const buildNextJs = () => {
return new Promise((resolve, reject) => {
const buildProcess = spawn('pnpm', ['run', 'build'], {
cwd: './plugins/rconsole-plugin/server',
- stdio: 'inherit',
+ stdio: 'ignore',
shell: true,
});
@@ -32,24 +34,24 @@ export const startNextJs = (mode = 'start') => {
logger.info(logger.yellow(`[R插件][Next.js监测],启动 Next.js ${mode} 进程...`));
- childProcess = spawn('pnpm', ['run', script], {
+ nextjsProcess = spawn('pnpm', ['run', script], {
cwd: './plugins/rconsole-plugin', // 指定工作目录
- stdio: 'inherit', // 继承父进程的标准输入输出
+ stdio: ['ignore', 'ignore', 'ignore', 'ipc'], // 继承父进程的标准输入输出
shell: true,
});
// 子进程异常退出时捕获信号
- childProcess.on('close', (code) => {
+ nextjsProcess.on('close', (code) => {
logger.error(`[R插件][Next.js监测],Next.js 进程发生异常 ${code}`);
- childProcess = null;
+ nextjsProcess = null;
});
};
// 捕获父进程退出信号
const cleanup = () => {
logger.info(logger.yellow('[R插件][Next.js监测] 父进程退出,终止子进程...'));
- if (childProcess) {
- childProcess.kill(); // 终止子进程
+ if (nextjsProcess) {
+ nextjsProcess.kill(); // 终止子进程
}
process.exit();
};
diff --git a/utils/redis-util.js b/utils/redis-util.js
index cd1ddf4..1d15eea 100644
--- a/utils/redis-util.js
+++ b/utils/redis-util.js
@@ -86,51 +86,3 @@ export async function redisExistAndUpdateObject(key, updateKey, updateObj) {
await redisSetKey(key, objs);
}
}
-
-/**
- * 删除某个key
- * @param key
- * @returns {Promise
}
- * @example
- * const result = await redisDeleteKey('myKey');
- * console.log(result); // 1 if key was deleted, 0 if key did not exist
- */
-export async function redisDeleteKey(key) {
- return redis.del(key);
-}
-
-/**
- * 获取所有的key
- * @returns {Promise>}
- * @example
- * const keys = await redisGetAllKeys();
- * console.log(keys); // ['key1', 'key2', ...]
- */
-export async function redisGetAllKeys() {
- return redis.keys('*');
-}
-
-/**
- * 设置某个key的过期时间
- * @param key
- * @param seconds
- * @returns {Promise}
- * @example
- * const result = await redisExpireKey('myKey', 3600);
- * console.log(result); // true if timeout was set, false if key does not exist
- */
-export async function redisExpireKey(key, seconds) {
- return redis.expire(key, seconds);
-}
-
-/**
- * 获取某个key的剩余生存时间
- * @param key
- * @returns {Promise}
- * @example
- * const ttl = await redisTTLKey('myKey');
- * console.log(ttl); // time to live in seconds, -1 if key does not have timeout, -2 if key does not exist
- */
-export async function redisTTLKey(key) {
- return redis.ttl(key);
-}
\ No newline at end of file
diff --git a/utils/yunzai-util.js b/utils/yunzai-util.js
index f0799ea..fa343c1 100644
--- a/utils/yunzai-util.js
+++ b/utils/yunzai-util.js
@@ -124,4 +124,31 @@ export async function getReplyMsg(e) {
"message_id" : msgId
})
return msg.data
-}
\ No newline at end of file
+}
+
+/**
+ * 获取机器人信息
+ * @param e
+ * @returns {Promise<*>}
+ */
+export async function getBotLoginInfo(e) {
+ return await e.bot.sendApi("get_login_info");
+}
+
+/**
+ * 获取运行状态
+ * @param e
+ * @returns {Promise<*>}
+ */
+export async function getBotStatus(e) {
+ return await e.bot.sendApi("get_status");
+}
+
+/**
+ * 获取版本信息
+ * @param e
+ * @returns {Promise<*>}
+ */
+export async function getBotVersionInfo(e) {
+ return await e.bot.sendApi("get_version_info");
+}