Merge pull request #26 from ZM-J/Add-guide-settings

加上攻略的设置
This commit is contained in:
bietiaop 2024-07-25 16:32:59 +08:00 committed by GitHub
commit ce5f067f42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 95 additions and 8 deletions

View file

@ -6,11 +6,12 @@ import common from '../../../lib/common/common.js';
import { ZZZPlugin } from '../lib/plugin.js'; import { ZZZPlugin } from '../lib/plugin.js';
import { rulePrefix } from '../lib/common.js'; import { rulePrefix } from '../lib/common.js';
import { atlasToName } from '../lib/convert/char.js'; import { atlasToName } from '../lib/convert/char.js';
import { imageResourcesPath } from '../lib/path.js'; import { imageResourcesPath, configPath } from '../lib/path.js';
import _ from 'lodash'; import _ from 'lodash';
import settings from '../lib/settings.js'; import settings from '../lib/settings.js';
const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides'); const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides');
const ZZZ_GUIDES_CONFIG_PATH = path.join(configPath, 'guide.yaml');
export class Guide extends ZZZPlugin { export class Guide extends ZZZPlugin {
constructor() { constructor() {
@ -20,10 +21,22 @@ export class Guide extends ZZZPlugin {
event: 'message', event: 'message',
priority: _.get(settings.getConfig('priority'), 'guide', 70), priority: _.get(settings.getConfig('priority'), 'guide', 70),
rule: [ rule: [
{
reg: `^${rulePrefix}攻略(说明|帮助)$`,
fnc: 'GuideHelp'
},
{
reg: `^${rulePrefix}设置默认攻略(\\d+|all)$`,
fnc: 'SetDefaultGuide'
},
{
reg: `^${rulePrefix}设置所有攻略显示个数(\\d+)$`,
fnc: 'SetMaxForwardGuide'
},
{ {
reg: `${rulePrefix}(更新)?\\S+攻略(\\d+|all)?$`, reg: `${rulePrefix}(更新)?\\S+攻略(\\d+|all)?$`,
fnc: 'Guide', fnc: 'Guide',
}, }
], ],
}); });
@ -84,20 +97,20 @@ export class Guide extends ZZZPlugin {
, ,
, ,
isUpdate, isUpdate,
name, atlas,
group = _.get(settings.getConfig('guide'), 'default_guide', 1).toString(), group = _.get(settings.getConfig('guide'), 'default_guide', 1).toString(),
] = this.e.msg.match(reg); ] = this.e.msg.match(reg);
// all -> 0 // all -> 0
if (group == 'all') { if (group == 'all') {
group = '0'; group = '0';
} }
group = +group; group = Number(group);
if (group > this.maxNum) { if (group > this.maxNum) {
await this.reply(`超过攻略数量(${this.maxNum}`); await this.reply(`超过攻略数量(${this.maxNum}`);
return; return;
} }
let id = atlasToName(name); let name = atlasToName(atlas);
if (!id) { if (!name) {
await this.reply('该角色不存在'); await this.reply('该角色不存在');
return; return;
} }
@ -148,10 +161,13 @@ export class Guide extends ZZZPlugin {
return false; return false;
} }
// 搜索时过滤特殊符号譬如「11号」
const filtered_name = name.replace(/[^\w\s]|_/g, '')
let posts = lodash.flatten(lodash.map(mysRes, item => item.data.posts)); let posts = lodash.flatten(lodash.map(mysRes, item => item.data.posts));
let url, created_at, updated_at; let url, created_at, updated_at;
for (let val of posts) { for (let val of posts) {
if (val.post.subject.replace(/【[^】]*本[^】]*】/g, '').includes(name)) { if (val.post.subject.replace(/【[^】]*本[^】]*】/g, '').includes(filtered_name)) {
let max = 0; let max = 0;
val.image_list.forEach((v, i) => { val.image_list.forEach((v, i) => {
if ( if (
@ -169,7 +185,7 @@ export class Guide extends ZZZPlugin {
} }
if (!url) { if (!url) {
this.e.reply( this.e.reply(
`暂无${name}攻略${this.source[group - 1]}\n请尝试其他的攻略来源查询` `暂无${name}攻略 (${this.source[group - 1]})\n请尝试其他的攻略来源查询`
); );
return false; return false;
} }
@ -194,4 +210,57 @@ export class Guide extends ZZZPlugin {
} }
return await response.json(); return await response.json();
} }
/** %攻略帮助 */
async GuideHelp () {
let reply_msg = [
'绝区零角色攻略帮助:',
'%艾莲攻略+攻略id',
'%更新艾莲攻略+攻略id',
'%设置默认攻略+攻略id',
'%设置所有攻略显示个数+攻略id',
'示例: %艾莲攻略2',
'',
'攻略来源:'
].concat(this.source.map((element, index) => `${index + 1}: ${element}`))
await this.e.reply(reply_msg.join('\n'))
}
setConfig(key, value) {
let config = fs.readFileSync(ZZZ_GUIDES_CONFIG_PATH, 'utf8')
let newREG = new RegExp(`^${key}: (.*)`, 'gm')
config = config.replace(newREG, `${key}: ${value}`)
fs.writeFileSync(ZZZ_GUIDES_CONFIG_PATH, config, 'utf8')
}
/** %设置默认攻略1 */
async SetDefaultGuide () {
let match = /设置默认攻略(\d+|all)$/g.exec(this.e.msg)
let guide_id = match[1]
if (guide_id == 'all') {
guide_id = 0
}
if (guide_id > this.maxNum) {
let reply_msg = [
'绝区零默认攻略设置方式为:',
'%设置默认攻略[0123...]',
`请增加数字0-${this.maxNum}其中一个,或者增加 all 以显示所有攻略`,
'攻略来源请输入 %攻略帮助 查看'
]
await this.e.reply(reply_msg.join('\n'))
return
}
this.setConfig('default_guide', guide_id)
let source_name = guide_id == 0 ? 'all' : this.source[guide_id - 1]
await this.e.reply(`绝区零默认攻略已设置为: ${guide_id} (${source_name})`)
}
/** %设置所有攻略显示个数3 */
async SetMaxForwardGuide () {
let match = /设置所有攻略显示个数(\d+)$/g.exec(this.e.msg)
let max_forward_guide = Number(match[1])
this.setConfig('max_forward_guides', max_forward_guide)
await this.e.reply(`绝区零所有攻略显示个数已设置为: ${max_forward_guide}`)
}
} }

View file

@ -4,25 +4,33 @@
- 11号 - 11号
- '11' - '11'
- 「11号」 - 「11号」
- 玛卡巴卡
- 火刀
艾莲: 艾莲:
- 爱莲 - 爱莲
- 爱怜 - 爱怜
- 艾莲·乔 - 艾莲·乔
- 艾莲乔
- 鲨鱼妹 - 鲨鱼妹
- 鲨鱼 - 鲨鱼
安东: 安东:
- 安东 - 安东
- 安东·伊万诺夫 - 安东·伊万诺夫
- 安东伊万诺夫
本: 本:
- 熊本 - 熊本
- 熊本熊 - 熊本熊
- ben - ben
- 比格 - 比格
- 本·比格 - 本·比格
- 本比格
- 大本
- 熊哥
比利: 比利:
- 比例 - 比例
- bili - bili
- 比利·奇德 - 比利·奇德
- 比利奇德
- Billy - Billy
苍角: 苍角:
- 苍绝 - 苍绝
@ -31,10 +39,12 @@
格莉丝: 格莉丝:
- 格利斯 - 格利斯
- 格莉丝·霍华德 - 格莉丝·霍华德
- 格莉丝霍华德
珂蕾妲: 珂蕾妲:
- 柯雷妲 - 柯雷妲
- 珂雷哒 - 珂雷哒
- 柯蕾妲 - 柯蕾妲
- 锤妹
猫又: 猫又:
- 猫猫 - 猫猫
- 猫妖 - 猫妖
@ -50,16 +60,21 @@
- 妮克 - 妮克
- 妮寇 - 妮寇
- 妮可·德玛拉 - 妮可·德玛拉
- 妮可德玛拉
- Nicole - Nicole
朱鸢: 朱鸢:
- 朱元 - 朱元
- 警员
丽娜: 丽娜:
- 莉娜 - 莉娜
- 李娜 - 李娜
- 亚历山德丽娜·莎芭丝缇安 - 亚历山德丽娜·莎芭丝缇安
- 亚历山德丽娜莎芭丝缇安
- rina - rina
莱卡恩: 莱卡恩:
- 冯·莱卡恩 - 冯·莱卡恩
- 冯莱卡恩
- 狼哥
安比: 安比:
- 安比 - 安比
- 安笔 - 安笔
@ -73,6 +88,7 @@
露西: 露西:
- 路西 - 路西
- 露西亚娜·德·蒙特夫 - 露西亚娜·德·蒙特夫
- 露西亚娜德蒙特夫
- 露西亚娜 - 露西亚娜
- 鲁西 - 鲁西
莱特: 莱特:
@ -89,12 +105,14 @@
- 青医 - 青医
赛斯: 赛斯:
- 赛斯·洛威尔 - 赛斯·洛威尔
- 赛斯洛威尔
- 塞斯 - 塞斯
- 洛威尔 - 洛威尔
派派: 派派:
- 拍拍 - 拍拍
- 韦尔 - 韦尔
- 派派·韦尔 - 派派·韦尔
- 派派韦尔
哲: 哲:
- -
铃: 铃: