diff --git a/apps/guide.js b/apps/guide.js index b3aaf01..9d56271 100644 --- a/apps/guide.js +++ b/apps/guide.js @@ -6,11 +6,12 @@ import common from '../../../lib/common/common.js'; import { ZZZPlugin } from '../lib/plugin.js'; import { rulePrefix } from '../lib/common.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 settings from '../lib/settings.js'; const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides'); +const ZZZ_GUIDES_CONFIG_PATH = path.join(configPath, 'guide.yaml'); export class Guide extends ZZZPlugin { constructor() { @@ -20,10 +21,22 @@ export class Guide extends ZZZPlugin { event: 'message', priority: _.get(settings.getConfig('priority'), 'guide', 70), rule: [ + { + reg: `^${rulePrefix}攻略(说明|帮助)$`, + fnc: 'GuideHelp' + }, + { + reg: `^${rulePrefix}设置默认攻略(\\d+|all)$`, + fnc: 'SetDefaultGuide' + }, + { + reg: `^${rulePrefix}设置所有攻略显示个数(\\d+)$`, + fnc: 'SetMaxForwardGuide' + }, { reg: `${rulePrefix}(更新)?\\S+攻略(\\d+|all)?$`, fnc: 'Guide', - }, + } ], }); @@ -84,20 +97,20 @@ export class Guide extends ZZZPlugin { , , isUpdate, - name, + atlas, group = _.get(settings.getConfig('guide'), 'default_guide', 1).toString(), ] = this.e.msg.match(reg); // all -> 0 if (group == 'all') { group = '0'; } - group = +group; + group = Number(group); if (group > this.maxNum) { await this.reply(`超过攻略数量(${this.maxNum})`); return; } - let id = atlasToName(name); - if (!id) { + let name = atlasToName(atlas); + if (!name) { await this.reply('该角色不存在'); return; } @@ -148,10 +161,13 @@ export class Guide extends ZZZPlugin { return false; } + // 搜索时过滤特殊符号,譬如「11号」 + const filtered_name = name.replace(/[^\w\s]|_/g, '') + let posts = lodash.flatten(lodash.map(mysRes, item => item.data.posts)); let url, created_at, updated_at; 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; val.image_list.forEach((v, i) => { if ( @@ -169,7 +185,7 @@ export class Guide extends ZZZPlugin { } if (!url) { this.e.reply( - `暂无${name}攻略(${this.source[group - 1]})\n请尝试其他的攻略来源查询` + `暂无${name}攻略 (${this.source[group - 1]})\n请尝试其他的攻略来源查询` ); return false; } @@ -194,4 +210,57 @@ export class Guide extends ZZZPlugin { } 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}`) + } } diff --git a/defSet/atlas.yaml b/defSet/atlas.yaml index 7cc990f..c299101 100644 --- a/defSet/atlas.yaml +++ b/defSet/atlas.yaml @@ -4,25 +4,33 @@ - 11号 - '11' - 「11号」 + - 玛卡巴卡 + - 火刀 艾莲: - 爱莲 - 爱怜 - 艾莲·乔 + - 艾莲乔 - 鲨鱼妹 - 鲨鱼 安东: - 安东 - 安东·伊万诺夫 + - 安东伊万诺夫 本: - 熊本 - 熊本熊 - ben - 比格 - 本·比格 + - 本比格 + - 大本 + - 熊哥 比利: - 比例 - bili - 比利·奇德 + - 比利奇德 - Billy 苍角: - 苍绝 @@ -31,10 +39,12 @@ 格莉丝: - 格利斯 - 格莉丝·霍华德 + - 格莉丝霍华德 珂蕾妲: - 柯雷妲 - 珂雷哒 - 柯蕾妲 + - 锤妹 猫又: - 猫猫 - 猫妖 @@ -50,16 +60,21 @@ - 妮克 - 妮寇 - 妮可·德玛拉 + - 妮可德玛拉 - Nicole 朱鸢: - 朱元 + - 警员 丽娜: - 莉娜 - 李娜 - 亚历山德丽娜·莎芭丝缇安 + - 亚历山德丽娜莎芭丝缇安 - rina 莱卡恩: - 冯·莱卡恩 + - 冯莱卡恩 + - 狼哥 安比: - 安比 - 安笔 @@ -73,6 +88,7 @@ 露西: - 路西 - 露西亚娜·德·蒙特夫 + - 露西亚娜德蒙特夫 - 露西亚娜 - 鲁西 莱特: @@ -89,12 +105,14 @@ - 青医 赛斯: - 赛斯·洛威尔 + - 赛斯洛威尔 - 塞斯 - 洛威尔 派派: - 拍拍 - 韦尔 - 派派·韦尔 + - 派派韦尔 哲: - 哲 铃: