Merge branch 'master' of github.com:yoimiya-kokomi/Miao-Yunzai

 Conflicts:
	lib/puppeteer/puppeteer.js
This commit is contained in:
Kokomi 2023-03-10 04:42:02 +08:00
commit 4938028e24
4 changed files with 101 additions and 37 deletions

View File

@ -343,6 +343,12 @@ class PluginsLoader {
* @param e.isMaster 是否管理员
* @param e.logText 日志用户字符串
* @param e.logFnc 日志方法字符串
* 频道
* @param e.isGuild 是否频道
* @param e.at 支持频道 tiny_id
* @param e.atBot 支持频道
*/
dealMsg (e) {
if (e.message) {
@ -366,8 +372,12 @@ class PluginsLoader {
case 'at':
if (val.qq == Bot.uin) {
e.atBot = true
} else {
} else if (val.id == Bot.tiny_id) {
e.atBot = true
/** 多个at 以最后的为准 */
} else if (val.id) {
e.at = val.id
} else {
e.at = val.qq
}
break
@ -418,6 +428,8 @@ class PluginsLoader {
if (!e.group_name) e.group_name = e.group?.name
e.logText = `[${e.group_name}(${e.sender.card})]`
} else if (e.detail_type === 'guild') {
e.isGuild = true
}
if (e.user_id && cfg.masterQQ.includes(Number(e.user_id))) {

View File

@ -3,11 +3,15 @@ import fs from 'fs'
import lodash from 'lodash'
import chokidar from 'chokidar'
import cfg from '../config/config.js'
import os from 'os'
const _path = process.cwd()
let puppeteer = {}
// mac地址
let mac =''
class Puppeteer {
constructor () {
this.browser = false
@ -69,7 +73,38 @@ class Puppeteer {
logger.mark('puppeteer Chromium 启动中...')
/** 初始化puppeteer */
let connectFlag = false
try {
//如果是pm2启动尝试连接已有实例
if (process.env.pm_id) {
//获取Mac地址
if (!mac){
mac = await this.getMac()
this.browserMacKey = `Yz:chromium:browserWSEndpoint:${mac}`
}
//是否有browser实例
const browserUrl = await redis.get(this.browserMacKey)
if (browserUrl){
const browserWSEndpoint = await puppeteer.connect({browserWSEndpoint: browserUrl}).catch((err) => {
logger.error("puppeteer Chromium 缓存的实例已关闭")
redis.del(this.browserMacKey)
})
//如果有实例,直接使用
if (browserWSEndpoint) {
this.browser = browserWSEndpoint
if (this.browser) {
connectFlag = true
}
}
}
}
}catch (e) {
logger.error("puppeteer Chromium 尝试连接已有实例失败")
}
if (!this.browser||!connectFlag){
//如果没有实例初始化puppeteer
this.browser = await puppeteer.launch(this.config).catch((err, trace) => {
let errMsg = err.toString() + (trace ? trace.toString() : '')
if (typeof err == 'object') {
@ -84,6 +119,7 @@ class Puppeteer {
}
console.log(err, trace)
})
}
this.lock = false
@ -91,8 +127,17 @@ class Puppeteer {
logger.error('puppeteer Chromium 启动失败')
return false
}
if (connectFlag){
logger.mark('puppeteer Chromium 已连接启动的实例')
}else {
console.log("chromium",this.browser.wsEndpoint())
if (this.browserMacKey) {
//缓存一下实例30天
const expireTime = 60 * 60 * 24 * 30
await redis.set(this.browserMacKey, this.browser.wsEndpoint(), { EX: expireTime })
}
logger.mark('puppeteer Chromium 启动成功')
}
/** 监听Chromium实例是否断开 */
this.browser.on('disconnected', (e) => {
@ -103,6 +148,33 @@ class Puppeteer {
return this.browser
}
//获取Mac地址
async getMac () {
//获取Mac地址
let mac="00:00:00:00:00:00"
try {
const network = os.networkInterfaces()
let osMac
//判断系统
if (os.platform() === 'win32') {
//windows下获取mac地址
let osMacList = Object.keys(network).map(key => network[key]).flat()
osMacList=osMacList.filter(item => item.family === 'IPv4'&&item.mac!==mac)
osMac = osMacList[0].mac
} else if (os.platform() === 'linux') {
//linux下获取mac地址
osMac = network.eth0.filter(item => item.family === 'IPv4'&&item.mac!==mac)[0].mac
}
if (osMac) {
mac = String(osMac)
}
} catch (e) {
console.log("获取Mac地址失败", e.toString())
}
mac = mac.replace(/:/g, '')
return mac
}
/**
* `chromium` 截图
* @param data 模板参数

View File

@ -49,8 +49,5 @@
"imports": {
"#miao": "./plugins/miao-plugin/components/index.js",
"#miao.models": "./plugins/miao-plugin/models/index.js"
},
"pnpm": {
"patchedDependencies": {}
}
}

View File

@ -1,17 +0,0 @@
diff --git a/lib/core/device.js b/lib/core/device.js
index ffadc63f15e8b0b435e640af60c6b854d0236a83..8a09faebae021f845d961086c8bb2b9ee19096f3 100644
--- a/lib/core/device.js
+++ b/lib/core/device.js
@@ -105,9 +105,9 @@ var Platform;
})(Platform = exports.Platform || (exports.Platform = {}));
const mobile = {
id: "com.tencent.mobileqq",
- name: "A8.8.80.7400",
- version: "8.8.80.7400",
- ver: "8.8.80",
+ name: "A8.9.25.10005",
+ version: "A8.9.25.10005",
+ ver: "8.9.25",
sign: Buffer.from([166, 183, 69, 191, 36, 162, 194, 119, 82, 119, 22, 246, 243, 110, 182, 141]),
buildtime: 1640921786,
appid: 16,