细节优化
This commit is contained in:
parent
ea01dbbe7c
commit
a38dd325e0
|
@ -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,
|
||||
};
|
10
lib/bot.js
10
lib/bot.js
|
@ -20,7 +20,7 @@ export default class Yunzai extends EventEmitter {
|
|||
await PluginsLoader.load()
|
||||
await ListenerLoader.load()
|
||||
this.serverLoad()
|
||||
this.emit("online")
|
||||
this.emit("online", this)
|
||||
}
|
||||
|
||||
serverRequest(req) {
|
||||
|
@ -148,6 +148,7 @@ export default class Yunzai extends EventEmitter {
|
|||
} catch (err) {
|
||||
logger.error(`${logger.blue(`[${bot_id}]`)} 发送好友消息失败:[$${user_id}] ${err}`)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
sendGroupMsg(bot_id, group_id, msg) {
|
||||
|
@ -164,12 +165,13 @@ export default class Yunzai extends EventEmitter {
|
|||
} catch (err) {
|
||||
logger.error(`${logger.blue(`[${bot_id}]`)} 发送群消息失败:[$${group_id}] ${err}`)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
sendMasterMsg(msg) {
|
||||
for (const id in cfg.master)
|
||||
for (const i of cfg.master[id])
|
||||
this.sendFriendMsg(id, i, msg)
|
||||
for (const bot_id in cfg.master)
|
||||
for (const user_id of cfg.master[bot_id])
|
||||
this.sendFriendMsg(bot_id, user_id, msg)
|
||||
}
|
||||
|
||||
async getMasterMsg() {
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
import { exec, execSync } from 'child_process'
|
||||
import plugin from '../../lib/plugins/plugin.js'
|
||||
import fs from 'node:fs'
|
||||
import { Restart } from './restart.js'
|
||||
import { exec, execSync } from "child_process"
|
||||
import plugin from "../../lib/plugins/plugin.js"
|
||||
import fs from "node:fs"
|
||||
import { Restart } from "./restart.js"
|
||||
|
||||
let insing = false
|
||||
const list = {
|
||||
'Atlas' :'https://gitee.com/Nwflower/atlas',
|
||||
'TRSS-Plugin' :'https://Yunzai.TRSS.me',
|
||||
'yenai-plugin' :'https://gitee.com/yeyang52/yenai-plugin',
|
||||
'expand-plugin' :'https://gitee.com/SmallK111407/expand-plugin',
|
||||
'flower-plugin' :'https://gitee.com/Nwflower/flower-plugin',
|
||||
'earth-k-plugin' :'https://gitee.com/SmallK111407/earth-k-plugin',
|
||||
'xiaofei-plugin' :'https://gitee.com/xfdown/xiaofei-plugin',
|
||||
'xiaoyao-cvs-plugin':'https://gitee.com/Ctrlcvs/xiaoyao-cvs-plugin',
|
||||
'Telegram-Plugin' :'https://gitee.com/TimeRainStarSky/Yunzai-Telegram-Plugin',
|
||||
'Discord-Plugin' :'https://gitee.com/TimeRainStarSky/Yunzai-Discord-Plugin',
|
||||
'QQGuild-Plugin' :'https://gitee.com/TimeRainStarSky/Yunzai-QQGuild-Plugin',
|
||||
'ICQQ-Plugin' :'https://gitee.com/TimeRainStarSky/Yunzai-ICQQ-Plugin',
|
||||
'KOOK-Plugin' :'https://gitee.com/TimeRainStarSky/Yunzai-KOOK-Plugin',
|
||||
"Atlas" :"https://gitee.com/Nwflower/atlas",
|
||||
"TRSS-Plugin" :"https://Yunzai.TRSS.me",
|
||||
"yenai-plugin" :"https://gitee.com/yeyang52/yenai-plugin",
|
||||
"expand-plugin" :"https://gitee.com/SmallK111407/expand-plugin",
|
||||
"flower-plugin" :"https://gitee.com/Nwflower/flower-plugin",
|
||||
"earth-k-plugin" :"https://gitee.com/SmallK111407/earth-k-plugin",
|
||||
"xiaofei-plugin" :"https://gitee.com/xfdown/xiaofei-plugin",
|
||||
"xiaoyao-cvs-plugin":"https://gitee.com/Ctrlcvs/xiaoyao-cvs-plugin",
|
||||
"Telegram-Plugin" :"https://gitee.com/TimeRainStarSky/Yunzai-Telegram-Plugin",
|
||||
"Discord-Plugin" :"https://gitee.com/TimeRainStarSky/Yunzai-Discord-Plugin",
|
||||
"QQGuild-Plugin" :"https://gitee.com/TimeRainStarSky/Yunzai-QQGuild-Plugin",
|
||||
"ICQQ-Plugin" :"https://gitee.com/TimeRainStarSky/Yunzai-ICQQ-Plugin",
|
||||
"KOOK-Plugin" :"https://gitee.com/TimeRainStarSky/Yunzai-KOOK-Plugin",
|
||||
}
|
||||
|
||||
export class install extends plugin {
|
||||
constructor () {
|
||||
super({
|
||||
name: '安装插件',
|
||||
dsc: '#安装插件 #安装TRSS-Plugin',
|
||||
event: 'message',
|
||||
name: "安装插件",
|
||||
dsc: "#安装插件 #安装TRSS-Plugin",
|
||||
event: "message",
|
||||
rule: [
|
||||
{
|
||||
reg: `^#安装(插件|${Object.keys(list).join('|')})$`,
|
||||
fnc: 'install',
|
||||
permission: 'master'
|
||||
reg: `^#安装(插件|${Object.keys(list).join("|")})$`,
|
||||
fnc: "install",
|
||||
permission: "master"
|
||||
}
|
||||
]
|
||||
})
|
||||
|
@ -38,19 +38,19 @@ export class install extends plugin {
|
|||
|
||||
async install () {
|
||||
if (insing) {
|
||||
await this.reply('已有命令安装中..请勿重复操作')
|
||||
await this.reply("已有命令安装中..请勿重复操作")
|
||||
return false
|
||||
}
|
||||
|
||||
const name = this.e.msg.replace(/^#安装/, '').trim()
|
||||
if (name == '插件') {
|
||||
let msg = '\n'
|
||||
const name = this.e.msg.replace(/^#安装/, "").trim()
|
||||
if (name == "插件") {
|
||||
let msg = "\n"
|
||||
for (const name in list)
|
||||
if (!fs.existsSync(`plugins/${name}`))
|
||||
msg += `${name}\n`
|
||||
|
||||
if (msg == '\n')
|
||||
msg = '暂无可安装插件'
|
||||
if (msg == "\n")
|
||||
msg = "暂无可安装插件"
|
||||
else
|
||||
msg = `可安装插件列表:${msg}发送 #安装+插件名 进行安装`
|
||||
|
||||
|
@ -78,7 +78,7 @@ export class install extends plugin {
|
|||
async runInstall (name, url, path) {
|
||||
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} 插件`)
|
||||
|
||||
|
@ -86,7 +86,7 @@ export class install extends plugin {
|
|||
insing = true
|
||||
let ret = await this.execSync(cm)
|
||||
if (fs.existsSync(`${path}/package.json`))
|
||||
await this.execSync('pnpm install')
|
||||
await this.execSync("pnpm install")
|
||||
insing = false
|
||||
|
||||
if (ret.error) {
|
||||
|
@ -99,18 +99,18 @@ export class install extends plugin {
|
|||
}
|
||||
|
||||
async gitErr (err, stdout) {
|
||||
let msg = '安装失败!'
|
||||
let msg = "安装失败!"
|
||||
let errMsg = err.toString()
|
||||
stdout = stdout.toString()
|
||||
|
||||
if (errMsg.includes('Timed out')) {
|
||||
let remote = errMsg.match(/'(.+?)'/g)[0].replace(/'/g, '')
|
||||
if (errMsg.includes("Timed out")) {
|
||||
let remote = errMsg.match(/'(.+?)'/g)[0].replace(/'/g, "")
|
||||
await this.reply(msg + `\n连接超时:${remote}`)
|
||||
return
|
||||
}
|
||||
|
||||
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}`)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue