细节优化

This commit is contained in:
🌌 2023-06-29 10:41:02 +08:00
parent ea01dbbe7c
commit a38dd325e0
3 changed files with 74 additions and 39 deletions

33
.puppeteerrc.cjs Normal file
View File

@ -0,0 +1,33 @@
const os = require("os");
const { existsSync } = require("fs");
const arch = os.arch();
let skipDownload = false;
let executablePath;
//win32 存在 Edge 优先选择
if (process.platform == "win32") {
if (
existsSync("C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe")
) {
skipDownload = true;
executablePath =
"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe";
}
} else if (process.platform == "linux") {
//如果arm64架构跳过下载
if (arch == "arm64" || arch == "aarch64") {
skipDownload = true;
}
//不管什么架构,如果存在配置则跳过下载,且配置路径
if (existsSync("/usr/bin/chromium")) {
skipDownload = true;
executablePath = "/usr/bin/chromium";
}
}
/**
* @type {import("puppeteer").Configuration}
*/
module.exports = {
skipDownload,
executablePath,
};

View File

@ -20,7 +20,7 @@ export default class Yunzai extends EventEmitter {
await PluginsLoader.load() await PluginsLoader.load()
await ListenerLoader.load() await ListenerLoader.load()
this.serverLoad() this.serverLoad()
this.emit("online") this.emit("online", this)
} }
serverRequest(req) { serverRequest(req) {
@ -148,6 +148,7 @@ export default class Yunzai extends EventEmitter {
} catch (err) { } catch (err) {
logger.error(`${logger.blue(`[${bot_id}]`)} 发送好友消息失败:[$${user_id}] ${err}`) logger.error(`${logger.blue(`[${bot_id}]`)} 发送好友消息失败:[$${user_id}] ${err}`)
} }
return false
} }
sendGroupMsg(bot_id, group_id, msg) { sendGroupMsg(bot_id, group_id, msg) {
@ -164,12 +165,13 @@ export default class Yunzai extends EventEmitter {
} catch (err) { } catch (err) {
logger.error(`${logger.blue(`[${bot_id}]`)} 发送群消息失败:[$${group_id}] ${err}`) logger.error(`${logger.blue(`[${bot_id}]`)} 发送群消息失败:[$${group_id}] ${err}`)
} }
return false
} }
sendMasterMsg(msg) { sendMasterMsg(msg) {
for (const id in cfg.master) for (const bot_id in cfg.master)
for (const i of cfg.master[id]) for (const user_id of cfg.master[bot_id])
this.sendFriendMsg(id, i, msg) this.sendFriendMsg(bot_id, user_id, msg)
} }
async getMasterMsg() { async getMasterMsg() {

View File

@ -1,36 +1,36 @@
import { exec, execSync } from 'child_process' import { exec, execSync } from "child_process"
import plugin from '../../lib/plugins/plugin.js' import plugin from "../../lib/plugins/plugin.js"
import fs from 'node:fs' import fs from "node:fs"
import { Restart } from './restart.js' import { Restart } from "./restart.js"
let insing = false let insing = false
const list = { const list = {
'Atlas' :'https://gitee.com/Nwflower/atlas', "Atlas" :"https://gitee.com/Nwflower/atlas",
'TRSS-Plugin' :'https://Yunzai.TRSS.me', "TRSS-Plugin" :"https://Yunzai.TRSS.me",
'yenai-plugin' :'https://gitee.com/yeyang52/yenai-plugin', "yenai-plugin" :"https://gitee.com/yeyang52/yenai-plugin",
'expand-plugin' :'https://gitee.com/SmallK111407/expand-plugin', "expand-plugin" :"https://gitee.com/SmallK111407/expand-plugin",
'flower-plugin' :'https://gitee.com/Nwflower/flower-plugin', "flower-plugin" :"https://gitee.com/Nwflower/flower-plugin",
'earth-k-plugin' :'https://gitee.com/SmallK111407/earth-k-plugin', "earth-k-plugin" :"https://gitee.com/SmallK111407/earth-k-plugin",
'xiaofei-plugin' :'https://gitee.com/xfdown/xiaofei-plugin', "xiaofei-plugin" :"https://gitee.com/xfdown/xiaofei-plugin",
'xiaoyao-cvs-plugin':'https://gitee.com/Ctrlcvs/xiaoyao-cvs-plugin', "xiaoyao-cvs-plugin":"https://gitee.com/Ctrlcvs/xiaoyao-cvs-plugin",
'Telegram-Plugin' :'https://gitee.com/TimeRainStarSky/Yunzai-Telegram-Plugin', "Telegram-Plugin" :"https://gitee.com/TimeRainStarSky/Yunzai-Telegram-Plugin",
'Discord-Plugin' :'https://gitee.com/TimeRainStarSky/Yunzai-Discord-Plugin', "Discord-Plugin" :"https://gitee.com/TimeRainStarSky/Yunzai-Discord-Plugin",
'QQGuild-Plugin' :'https://gitee.com/TimeRainStarSky/Yunzai-QQGuild-Plugin', "QQGuild-Plugin" :"https://gitee.com/TimeRainStarSky/Yunzai-QQGuild-Plugin",
'ICQQ-Plugin' :'https://gitee.com/TimeRainStarSky/Yunzai-ICQQ-Plugin', "ICQQ-Plugin" :"https://gitee.com/TimeRainStarSky/Yunzai-ICQQ-Plugin",
'KOOK-Plugin' :'https://gitee.com/TimeRainStarSky/Yunzai-KOOK-Plugin', "KOOK-Plugin" :"https://gitee.com/TimeRainStarSky/Yunzai-KOOK-Plugin",
} }
export class install extends plugin { export class install extends plugin {
constructor () { constructor () {
super({ super({
name: '安装插件', name: "安装插件",
dsc: '#安装插件 #安装TRSS-Plugin', dsc: "#安装插件 #安装TRSS-Plugin",
event: 'message', event: "message",
rule: [ rule: [
{ {
reg: `^#安装(插件|${Object.keys(list).join('|')})$`, reg: `^#安装(插件|${Object.keys(list).join("|")})$`,
fnc: 'install', fnc: "install",
permission: 'master' permission: "master"
} }
] ]
}) })
@ -38,19 +38,19 @@ export class install extends plugin {
async install () { async install () {
if (insing) { if (insing) {
await this.reply('已有命令安装中..请勿重复操作') await this.reply("已有命令安装中..请勿重复操作")
return false return false
} }
const name = this.e.msg.replace(/^#安装/, '').trim() const name = this.e.msg.replace(/^#安装/, "").trim()
if (name == '插件') { if (name == "插件") {
let msg = '\n' let msg = "\n"
for (const name in list) for (const name in list)
if (!fs.existsSync(`plugins/${name}`)) if (!fs.existsSync(`plugins/${name}`))
msg += `${name}\n` msg += `${name}\n`
if (msg == '\n') if (msg == "\n")
msg = '暂无可安装插件' msg = "暂无可安装插件"
else else
msg = `可安装插件列表:${msg}发送 #安装+插件名 进行安装` msg = `可安装插件列表:${msg}发送 #安装+插件名 进行安装`
@ -78,7 +78,7 @@ export class install extends plugin {
async runInstall (name, url, path) { async runInstall (name, url, path) {
this.isNowUp = false this.isNowUp = false
let cm = `git clone --depth 1 --single-branch '${url}' '${path}'` let cm = `git clone --depth 1 --single-branch "${url}" "${path}"`
logger.mark(`${this.e.logFnc} 开始安装:${name} 插件`) logger.mark(`${this.e.logFnc} 开始安装:${name} 插件`)
@ -86,7 +86,7 @@ export class install extends plugin {
insing = true insing = true
let ret = await this.execSync(cm) let ret = await this.execSync(cm)
if (fs.existsSync(`${path}/package.json`)) if (fs.existsSync(`${path}/package.json`))
await this.execSync('pnpm install') await this.execSync("pnpm install")
insing = false insing = false
if (ret.error) { if (ret.error) {
@ -99,18 +99,18 @@ export class install extends plugin {
} }
async gitErr (err, stdout) { async gitErr (err, stdout) {
let msg = '安装失败!' let msg = "安装失败!"
let errMsg = err.toString() let errMsg = err.toString()
stdout = stdout.toString() stdout = stdout.toString()
if (errMsg.includes('Timed out')) { if (errMsg.includes("Timed out")) {
let remote = errMsg.match(/'(.+?)'/g)[0].replace(/'/g, '') let remote = errMsg.match(/'(.+?)'/g)[0].replace(/'/g, "")
await this.reply(msg + `\n连接超时:${remote}`) await this.reply(msg + `\n连接超时:${remote}`)
return return
} }
if (/Failed to connect|unable to access/g.test(errMsg)) { if (/Failed to connect|unable to access/g.test(errMsg)) {
let remote = errMsg.match(/'(.+?)'/g)[0].replace(/'/g, '') let remote = errMsg.match(/'(.+?)'/g)[0].replace(/'/g, "")
await this.reply(msg + `\n连接失败:${remote}`) await this.reply(msg + `\n连接失败:${remote}`)
return return
} }