From f017107e9e3c4163a34dbc02938a33fd9fcdfa42 Mon Sep 17 00:00:00 2001 From: CuteLittleSky <62592731+CuteLittleSky@users.noreply.github.com> Date: Tue, 28 Mar 2023 03:43:18 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=85=B3=E4=BA=8E=E7=AD=BE=E5=88=B0=E7=9A=84=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=20(#46)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update user.js * Update help.yaml * Update README.md --- plugins/genshin/README.md | 3 --- plugins/genshin/defSet/bot/help.yaml | 4 ++-- plugins/genshin/model/user.js | 2 -- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/genshin/README.md b/plugins/genshin/README.md index 14bc782..f9a823c 100644 --- a/plugins/genshin/README.md +++ b/plugins/genshin/README.md @@ -14,9 +14,6 @@ |#刻晴攻略|米游社西风攻略| |#练度统计,#五星列表,#天赋列表|米游社角色详情列表| |#体力|原神体力查询| -|#签到|米游社原神签到,自动签到| -|#开启、关闭签到|开启或关闭原神自动签到| -|#全部签到|签到全部ck| |#原石、#原石七月|查询米游社原石札记| |#原石统计|查询米游社原石札记,会自动保存数据| |#2022年原石统计| 按年份查询保存的历史原石札记数据| diff --git a/plugins/genshin/defSet/bot/help.yaml b/plugins/genshin/defSet/bot/help.yaml index 1a2a39e..9bf36b8 100644 --- a/plugins/genshin/defSet/bot/help.yaml +++ b/plugins/genshin/defSet/bot/help.yaml @@ -22,8 +22,8 @@ title: '#原石 #原石统计' desc: 查询体力,需要绑定cookie - icon: 打卡 - title: '#签到、删除cookie' - desc: 米游社原神自动签到 + title: '#删除cookie' + desc: 删除米游社cookie - icon: 统计 title: '#角色养成' desc: 计算角色养成消耗素材 diff --git a/plugins/genshin/model/user.js b/plugins/genshin/model/user.js index 5b1938c..e4f1378 100644 --- a/plugins/genshin/model/user.js +++ b/plugins/genshin/model/user.js @@ -99,8 +99,6 @@ export default class User extends base { await this.e.reply(uidMsg.join('\n')) let msg = '【#体力】查询当前树脂' - msg += '\n【#签到】米游社原神自动签到' - msg += '\n【#关闭签到】开启或关闭原神自动签到' msg += '\n【#原石】查看原石札记' msg += '\n【#原石统计】原石统计数据' msg += '\n【#练度统计】技能统计列表' From 2865c0aba454c8df15cd28d1f33e50ae4ca69128 Mon Sep 17 00:00:00 2001 From: ikuaki1009 Date: Sat, 1 Apr 2023 00:28:33 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=B0=86=E8=B5=84=E8=AE=AF=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E5=88=86=E7=89=87=E6=88=AA=E5=9B=BE=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=88=B0=20puppeteer=20=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复 typo (rander => render) --- lib/puppeteer/puppeteer.js | 81 +++++++++++++++++++++++++++++ plugins/genshin/model/mysNews.js | 89 +++----------------------------- 2 files changed, 89 insertions(+), 81 deletions(-) diff --git a/lib/puppeteer/puppeteer.js b/lib/puppeteer/puppeteer.js index 06b98b8..adbe808 100644 --- a/lib/puppeteer/puppeteer.js +++ b/lib/puppeteer/puppeteer.js @@ -246,6 +246,87 @@ class Puppeteer { return segment.image(buff) } + /** + * `chromium` 分片截图 + */ + async screenshots (name, data = {}) { + // FIXME: pageHeight 作为参数? + const pageHeight = 7000 + + await this.browserInit() + + if (!this.browser) return false + + const savePath = this.dealTpl(this.model, data) + if (!savePath) return false + + const page = await this.browser.newPage() + try { + await page.goto(`file://${_path}${lodash.trim(savePath, '.')}`, { timeout: 120000 }) + const body = await page.$('#container') || await page.$('body') + const boundingBox = await body.boundingBox() + + const num = Math.round(boundingBox.height / pageHeight) || 1 + + if (num > 1) { + await page.setViewport({ + width: boundingBox.width, + height: pageHeight + 100 + }) + } + + const img = [] + for (let i = 1; i <= num; i++) { + const randData = { + type: 'jpeg', + quality: 90 + } + + if (i != 1 && i == num) { + await page.setViewport({ + width: boundingBox.width, + height: parseInt(boundingBox.height) - pageHeight * (num - 1) + }) + } + + if (i != 1 && i <= num) { + await page.evaluate(() => window.scrollBy(0, 7000)) + } + + let buff + if (num == 1) { + buff = await body.screenshot(randData) + } else { + buff = await page.screenshot(randData) + } + + if (num > 2) await common.sleep(200) + + this.renderNum++ + /** 计算图片大小 */ + const kb = (buff.length / 1024).toFixed(2) + 'kb' + + logger.mark(`[图片生成][${name}][${this.renderNum}次] ${kb}`) + + img.push(segment.image(buff)) + } + + await page.close().catch((err) => logger.error(err)) + + if (num > 1) { + logger.mark(`[图片生成][${name}] 处理完成`) + } + return img + } catch (error) { + logger.error(`图片生成失败:${name}:${error}`) + /** 关闭浏览器 */ + if (this.browser) { + await this.browser.close().catch((err) => logger.error(err)) + } + this.browser = false + } + } + /** 模板 */ dealTpl (name, data) { let { tplFile, saveId = name } = data diff --git a/plugins/genshin/model/mysNews.js b/plugins/genshin/model/mysNews.js index a7a0dda..353897e 100644 --- a/plugins/genshin/model/mysNews.js +++ b/plugins/genshin/model/mysNews.js @@ -44,87 +44,14 @@ export default class MysNews extends base { const param = await this.newsDetail(postId) - const img = await this.rander(param) + const img = await this.render(param) return await this.replyMsg(img, `原神${typeName}:${param.data.post.subject}`) } - async rander (param) { - const pageHeight = 7000 - - await puppeteer.browserInit() - - if (!puppeteer.browser) return false - - const savePath = puppeteer.dealTpl('mysNews', param) - if (!savePath) return false - - const page = await puppeteer.browser.newPage() - try { - await page.goto(`file://${_path}${lodash.trim(savePath, '.')}`, { timeout: 120000 }) - const body = await page.$('#container') || await page.$('body') - const boundingBox = await body.boundingBox() - - const num = Math.round(boundingBox.height / pageHeight) || 1 - - if (num > 1) { - await page.setViewport({ - width: boundingBox.width, - height: pageHeight + 100 - }) - } - - const img = [] - for (let i = 1; i <= num; i++) { - const randData = { - type: 'jpeg', - quality: 90 - } - - if (i != 1 && i == num) { - await page.setViewport({ - width: boundingBox.width, - height: parseInt(boundingBox.height) - pageHeight * (num - 1) - }) - } - - if (i != 1 && i <= num) { - await page.evaluate(() => window.scrollBy(0, 7000)) - } - - let buff - if (num == 1) { - buff = await body.screenshot(randData) - } else { - buff = await page.screenshot(randData) - } - - if (num > 2) await common.sleep(200) - - puppeteer.renderNum++ - /** 计算图片大小 */ - const kb = (buff.length / 1024).toFixed(2) + 'kb' - - logger.mark(`[图片生成][${this.model}][${puppeteer.renderNum}次] ${kb}`) - - img.push(segment.image(buff)) - } - - await page.close().catch((err) => logger.error(err)) - - if (num > 1) { - logger.mark(`[图片生成][${this.model}] 处理完成`) - } - return img - } catch (error) { - logger.error(`图片生成失败:${this.model}:${error}`) - /** 关闭浏览器 */ - if (puppeteer.browser) { - await puppeteer.browser.close().catch((err) => logger.error(err)) - } - puppeteer.browser = false - } - } + async render (param) { + return await puppeteer.screenshots(this.model, param); + } async newsDetail (postId) { const res = await this.postData('getPostFull', { gids: 2, read: 1, post_id: postId }) @@ -282,7 +209,7 @@ export default class MysNews extends base { const param = await this.newsDetail(postId) - const img = await this.rander(param) + const img = await this.render(param) return await this.replyMsg(img, `${param.data.post.subject}`) } @@ -295,7 +222,7 @@ export default class MysNews extends base { const param = await this.newsDetail(postId) - const img = await this.rander(param) + const img = await this.render(param) return await this.replyMsg(img, `${param.data.post.subject}`) } @@ -322,7 +249,7 @@ export default class MysNews extends base { const param = await this.newsDetail(postId) - const img = await this.rander(param) + const img = await this.render(param) if (img.length > 1) { img.push(segment.image(param.data.post.images[0] + '?x-oss-process=image//resize,s_600/quality,q_80/auto-orient,0/interlace,1/format,jpg')) @@ -407,7 +334,7 @@ export default class MysNews extends base { logger.mark(`[米游社${typeName}推送] ${param.data.post.subject}`) this[postId] = { - img: await this.rander(param), + img: await this.render(param), title: param.data.post.subject } } From 2e3a9f4987b51d5edfc22b827d48b4226437d351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E9=9B=A8=E2=97=8E=E6=98=9F=E7=A9=BA?= Date: Sat, 1 Apr 2023 03:19:01 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20e.bot=20=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=20(#50)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/plugins/loader.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/plugins/loader.js b/lib/plugins/loader.js index 3db9b30..abd0ab3 100644 --- a/lib/plugins/loader.js +++ b/lib/plugins/loader.js @@ -162,6 +162,7 @@ class PluginsLoader { * @param e icqq Events */ async deal (e) { + e.bot = Bot /** 检查频道消息 */ if (this.checkGuildMsg(e)) return /** 检查黑白名单 */