Use 'all' to indicate displaying all guides

This commit is contained in:
ZM.J 2024-07-25 12:07:19 +08:00
parent 8a047b5f5e
commit 39af2acb64
2 changed files with 12 additions and 7 deletions

View file

@ -21,7 +21,7 @@ export class Guide extends ZZZPlugin {
priority: _.get(settings.getConfig('priority'), 'guide', 70),
rule: [
{
reg: `${rulePrefix}(更新)?\\S+攻略(\\d+)?$`,
reg: `${rulePrefix}(更新)?\\S+攻略(\\d+|all)?$`,
fnc: 'Guide',
},
],
@ -49,7 +49,7 @@ export class Guide extends ZZZPlugin {
this.maxNum = this.source.length;
// 最大显示攻略数量
this.maxForwardGuides = 4;
this.maxForwardGuides = _.get(settings.getConfig('guide'), 'max_forward_guides', 4);
}
async init() {
@ -77,7 +77,7 @@ export class Guide extends ZZZPlugin {
}
async Guide() {
let reg = new RegExp(`${rulePrefix}(更新)?(\\S+)攻略(\\d+)?$`);
let reg = new RegExp(`${rulePrefix}(更新)?(\\S+)攻略(\\d+|all)?$`);
let [
,
,
@ -87,6 +87,10 @@ export class Guide extends ZZZPlugin {
name,
group = _.get(settings.getConfig('guide'), 'default_guide', 1).toString(),
] = this.e.msg.match(reg);
// all -> 0
if (group == 'all') {
group = '0';
}
group = +group;
if (group > this.maxNum) {
await this.reply(`超过攻略数量(${this.maxNum}`);
@ -108,7 +112,7 @@ export class Guide extends ZZZPlugin {
msg.push(segment.image(`file://${guidePath}`));
continue;
}
if (i < this.maxForwardGuides && (await this.getImg(name, i))) {
if (i <= this.maxForwardGuides && (await this.getImg(name, i))) {
msg.push(segment.image(`file://${guidePath}`));
}
}
@ -169,7 +173,7 @@ export class Guide extends ZZZPlugin {
);
return false;
}
console.log(`${this.e.logFnc} 下载${name}攻略图`);
console.log(`${this.e.logFnc} 下载${name}攻略图 - ${this.source[group - 1]}`);
const download = await fetch(url);
const arrayBuffer = await download.arrayBuffer();
@ -177,7 +181,7 @@ export class Guide extends ZZZPlugin {
let guidePath = this.getGuidePath(group, name);
fs.writeFileSync(guidePath, buffer);
console.log(`${this.e.logFnc} 下载${name}攻略成功`);
console.log(`${this.e.logFnc} 下载${name}攻略成功 - ${this.source[group - 1]}`);
return true;
}

View file

@ -1 +1,2 @@
default_guide: 1
default_guide: 1
max_forward_guides: 4