From 0e146c4fc982345f4f208072d3fc6a6e7001f990 Mon Sep 17 00:00:00 2001 From: "ZM.J" Date: Thu, 25 Jul 2024 16:04:07 +0800 Subject: [PATCH 1/4] Change guide config via chatting --- apps/guide.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/apps/guide.js b/apps/guide.js index b3aaf01..101a877 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', - }, + } ], }); @@ -91,7 +104,7 @@ export class Guide extends ZZZPlugin { if (group == 'all') { group = '0'; } - group = +group; + group = Number(group); if (group > this.maxNum) { await this.reply(`超过攻略数量(${this.maxNum})`); return; @@ -194,4 +207,57 @@ export class Guide extends ZZZPlugin { } return await response.json(); } + + /** #攻略帮助 */ + async GuideHelp () { + reply_msg = [ + '绝区零角色攻略帮助:', + '%艾莲攻略+攻略id', + '%更新艾莲攻略+攻略id', + '%设置默认攻略+攻略id', + '%设置默认攻略+攻略id', + '示例: %艾莲攻略2', + '', + '攻略来源:' + ] + 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}`) + } } From 74d4441e6743dc995ffdeb3abc5519cd18cb46ee Mon Sep 17 00:00:00 2001 From: "ZM.J" Date: Thu, 25 Jul 2024 16:11:22 +0800 Subject: [PATCH 2/4] Fuck js --- apps/guide.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/guide.js b/apps/guide.js index 101a877..dcfe07f 100644 --- a/apps/guide.js +++ b/apps/guide.js @@ -182,7 +182,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; } @@ -208,18 +208,18 @@ export class Guide extends ZZZPlugin { return await response.json(); } - /** #攻略帮助 */ + /** %攻略帮助 */ async GuideHelp () { - reply_msg = [ + let reply_msg = [ '绝区零角色攻略帮助:', '%艾莲攻略+攻略id', '%更新艾莲攻略+攻略id', '%设置默认攻略+攻略id', - '%设置默认攻略+攻略id', + '%设置所有攻略显示个数+攻略id', '示例: %艾莲攻略2', '', '攻略来源:' - ] + this.source.map((element, index) => `${index + 1}: ${element}`) + ].concat(this.source.map((element, index) => `${index + 1}: ${element}`)) await this.e.reply(reply_msg.join('\n')) } From b764e5cd773e047ff62fa72ba94177a0afb493ac Mon Sep 17 00:00:00 2001 From: "ZM.J" Date: Thu, 25 Jul 2024 16:26:10 +0800 Subject: [PATCH 3/4] Fix name --- apps/guide.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/guide.js b/apps/guide.js index dcfe07f..9d56271 100644 --- a/apps/guide.js +++ b/apps/guide.js @@ -97,7 +97,7 @@ export class Guide extends ZZZPlugin { , , isUpdate, - name, + atlas, group = _.get(settings.getConfig('guide'), 'default_guide', 1).toString(), ] = this.e.msg.match(reg); // all -> 0 @@ -109,8 +109,8 @@ export class Guide extends ZZZPlugin { await this.reply(`超过攻略数量(${this.maxNum})`); return; } - let id = atlasToName(name); - if (!id) { + let name = atlasToName(atlas); + if (!name) { await this.reply('该角色不存在'); return; } @@ -161,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 ( From c292ee50d7ed118b7bf3ce35c8f52bd49bb2d21f Mon Sep 17 00:00:00 2001 From: "ZM.J" Date: Thu, 25 Jul 2024 16:29:42 +0800 Subject: [PATCH 4/4] Add more atlas --- defSet/atlas.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 @@ - 青医 赛斯: - 赛斯·洛威尔 + - 赛斯洛威尔 - 塞斯 - 洛威尔 派派: - 拍拍 - 韦尔 - 派派·韦尔 + - 派派韦尔 哲: - 哲 铃: