From c3d6c4c7049768e566eeeec2cbcc9a19495d1ca0 Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Mon, 25 Nov 2024 11:36:52 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20pref=EF=BC=9A=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BA=A4=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/webUI.js | 10 +++++++++- utils/yunzai-util.js | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/apps/webUI.js b/apps/webUI.js index 060bcf6..b54c065 100644 --- a/apps/webUI.js +++ b/apps/webUI.js @@ -1,7 +1,8 @@ import { REDIS_YUNZAI_WEBUI } from "../constants/constant.js"; import config from "../model/config.js"; import { redisSetKey } from "../utils/redis-util.js"; -import { getBotLoginInfo, getBotStatus, getBotVersionInfo } from "../utils/yunzai-util.js"; +import { getBotLoginInfo, getBotStatus, getBotVersionInfo, sendPrivateMsg } from "../utils/yunzai-util.js"; +import os from "os"; export class WebUI extends plugin { constructor() { @@ -51,6 +52,13 @@ export class WebUI extends plugin { await this.initData(e, realIsOpenWebUI); // 这里有点延迟,需要写反 e.reply(`R插件可视化面板:${ realIsOpenWebUI ? "✅已开启" : "❌已关闭" },重启后生效`); + if (realIsOpenWebUI) { + const networkInterfaces = os.networkInterfaces(); + const ipAddress = Object.values(networkInterfaces) + .flat() + .filter(detail => detail.family === 'IPv4' && !detail.internal)[0].address; + await sendPrivateMsg(e, `R插件可视化面板地址:${ ipAddress }:4016`); + } return true; } diff --git a/utils/yunzai-util.js b/utils/yunzai-util.js index fa343c1..0cda1d1 100644 --- a/utils/yunzai-util.js +++ b/utils/yunzai-util.js @@ -1,3 +1,5 @@ +import os from "os"; + /** * 将只有 text 类型的数组转换为原生的 {Bot.makeForwardMsg} * @param e @@ -152,3 +154,16 @@ export async function getBotStatus(e) { export async function getBotVersionInfo(e) { return await e.bot.sendApi("get_version_info"); } + +/** + * 发送私聊消息 + * @param e + * @param message + * @returns {Promise} + */ +export async function sendPrivateMsg(e, message) { + e.bot.sendApi("send_private_msg", { + user_id: e.user_id, + message: message, + }) +}