From d101401ca1c17f8ccb535759cc18eb92f2e053f0 Mon Sep 17 00:00:00 2001 From: "ZM.J" Date: Thu, 11 Jul 2024 14:47:03 +0800 Subject: [PATCH 1/2] calculate maxNum dynamically --- apps/guide.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/guide.js b/apps/guide.js index 1d5103d..7f91c83 100644 --- a/apps/guide.js +++ b/apps/guide.js @@ -8,8 +8,6 @@ import fetch from 'node-fetch' import lodash from 'lodash' const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides') -// 最大攻略数量 -const maxNum = 2 export class Guide extends ZZZPlugin { constructor() { @@ -20,7 +18,7 @@ export class Guide extends ZZZPlugin { priority: 100, rule: [ { - reg: `${rulePrefix}(更新)?\\S+攻略([0-${maxNum}])?$`, + reg: `${rulePrefix}(更新)?\\S+攻略(\\d+)?$`, fnc: 'Guide', }, ], @@ -31,16 +29,22 @@ export class Guide extends ZZZPlugin { [], // 来源:新艾利都快讯 [2712859], - [2727116] + [2727116], + [2721968], + [2724610] ] this.source = [ '新艾利都快讯', - '清茶沐沐Kiyotya' + '清茶沐沐Kiyotya', + '小橙子阿', + '猫冬' ] + // 最大攻略数量 + this.maxNum = this.source.length } async init () { - for (let group = 1; group <= maxNum; group++) { + for (let group = 1; group <= this.maxNum; group++) { let guideFolder = this.getGuideFolder(group) if (!fs.existsSync(guideFolder)) { fs.mkdirSync(guideFolder, { recursive: true }) @@ -61,10 +65,15 @@ export class Guide extends ZZZPlugin { async Guide() { logger.warn('123') - let reg = new RegExp(`${rulePrefix}(更新)?(\\S+)攻略([0-${maxNum}])?$`) + let reg = new RegExp(`${rulePrefix}(更新)?(\\S+)攻略(\\d+)?$`) let [,,,, isUpdate, name, - group = 1 // setting.getConfig('mys')?.defaultSource + group = '1' // setting.getConfig('mys')?.defaultSource ] = this.e.msg.match(reg) + group = +group + if (group > this.maxNum) { + await this.reply(`超过攻略数量(${this.maxNum})`) + return + } let id = atlasToName(name) if (!id) { await this.reply('该角色不存在') @@ -75,8 +84,8 @@ export class Guide extends ZZZPlugin { // eslint-disable-next-line no-unused-vars let msg = [] // eslint-disable-next-line no-unused-vars - for (let i = 1; i <= maxNum; i++) { - let guildePath = this.getGuidePath(i, name) + for (let i = 1; i <= this.maxNum; i++) { + let guidePath = this.getGuidePath(i, name) if (fs.existsSync(this.sfPath) && !isUpdate) { msg.push(segment.image(`file://${guidePath}`)) continue From b6424b50c24ff77342767d86cee28caf36bbdc83 Mon Sep 17 00:00:00 2001 From: "ZM.J" Date: Thu, 11 Jul 2024 15:05:55 +0800 Subject: [PATCH 2/2] Filter out gif --- apps/guide.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/apps/guide.js b/apps/guide.js index 7f91c83..70d536d 100644 --- a/apps/guide.js +++ b/apps/guide.js @@ -31,13 +31,15 @@ export class Guide extends ZZZPlugin { [2712859], [2727116], [2721968], - [2724610] + [2724610], + [2722266] ] this.source = [ '新艾利都快讯', '清茶沐沐Kiyotya', '小橙子阿', - '猫冬' + '猫冬', + '月光中心' ] // 最大攻略数量 this.maxNum = this.source.length @@ -63,8 +65,14 @@ export class Guide extends ZZZPlugin { return guidePath } + canGetImageFromFile(guidePath, isUpdate) { + return ( + fs.existsSync(guidePath) && + !isUpdate + ) + } + async Guide() { - logger.warn('123') let reg = new RegExp(`${rulePrefix}(更新)?(\\S+)攻略(\\d+)?$`) let [,,,, isUpdate, name, group = '1' // setting.getConfig('mys')?.defaultSource @@ -86,7 +94,7 @@ export class Guide extends ZZZPlugin { // eslint-disable-next-line no-unused-vars for (let i = 1; i <= this.maxNum; i++) { let guidePath = this.getGuidePath(i, name) - if (fs.existsSync(this.sfPath) && !isUpdate) { + if (this.canGetImageFromFile(guidePath, isUpdate)) { msg.push(segment.image(`file://${guidePath}`)) continue } @@ -99,7 +107,7 @@ export class Guide extends ZZZPlugin { } let guidePath = this.getGuidePath(group, name) - if (fs.existsSync(guidePath)) { + if (this.canGetImageFromFile(guidePath, isUpdate)) { await this.e.reply(segment.image(`file://${guidePath}`)) return } @@ -128,7 +136,12 @@ export class Guide extends ZZZPlugin { if (val.post.subject.includes(name)) { let max = 0 val.image_list.forEach((v, i) => { - if (Number(v.size) >= Number(val.image_list[max].size)) max = i + if ( + Number(v.size) >= Number(val.image_list[max].size) && + v.format != 'gif' // 动图天生 size 会撑得很大 + ) { + max = i + } }) url = val.image_list[max].url break