Browse Source

feat(Plugins): 在命令执行前添加表情点赞功能

在命令处理前后添加对QQ消息的表情点赞操作,使用固定emoji_id '124'。这有助于提升用户交互体验。

refactor(Puppeteer): 优化HTML截图功能

将无头模式默认设为true以提高性能
修改默认宽高为-1表示自动计算
调整视口设置逻辑,仅在指定宽高时才进行设置
枫林 2 months ago
parent
commit
45536ac0af
2 changed files with 15 additions and 5 deletions
  1. 11 1
      src/lib/Plugins.ts
  2. 4 4
      src/lib/Puppeteer.ts

+ 11 - 1
src/lib/Plugins.ts

@@ -276,7 +276,12 @@ export async function runplugins() {
                             return;
                         }
                     }
-                    // 执行命令
+                    console.log(JSON.stringify(context))
+                    qqBot.set_msg_emoji_like({
+                        message_id: context.message_id,
+                        set: true,
+                        emoji_id: '124'
+                    })
                     await handleCommand(context, easyplugin, command, parts.slice(1), true);
                     return;
                 }
@@ -327,6 +332,11 @@ export async function runplugins() {
                     }
                 }
                 // 执行命令
+                qqBot.set_msg_emoji_like({
+                    message_id: context.message_id,
+                    set: true,
+                    emoji_id: '124'
+                })
                 await handleCommand(context, plugin, command, args);
 
             } catch (error) {

+ 4 - 4
src/lib/Puppeteer.ts

@@ -9,7 +9,7 @@ export class HtmlImg {
     async init() {
         if (!this.browser) {
             const options: PuppeteerLaunchOptions = {
-                headless: false, // 无头模式,可根据需要设置为false,
+                headless: true, // 无头模式,可根据需要设置为false,
                 args: [
                     '--no-sandbox',
                     '--disable-setuid-sandbox',
@@ -39,8 +39,8 @@ export class HtmlImg {
                 template,
                 templateIsPath = true,
                 data,
-                width = 800,
-                height = 1,
+                width = -1,
+                height = -1,
                 type = 'png',
                 quality = 100,
                 fullPage = false,
@@ -86,7 +86,7 @@ export class HtmlImg {
             const bodyheight = await page.evaluate(() => document.body.scrollHeight)  as number;
             const bodywidth = await page.evaluate(() => document.body.scrollWidth)  as number;
             botlogger.info(`获取body高度${bodyheight}和宽度${bodywidth}`)
-            if(bodyheight!= height || bodywidth!= width){
+            if(-1 != height &&  -1 != width){
                 await page.setViewport({ width: bodywidth, height: bodyheight });
                 await page.waitForNetworkIdle();
             }