From e37b545aff7652c9c2a620320873f2af47867b02 Mon Sep 17 00:00:00 2001 From: "ZM.J" Date: Sun, 27 Oct 2024 23:10:41 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=91=BD=E4=BB=A4=20`#20?= =?UTF-8?q?2410=E5=B9=BB=E6=83=B3=E8=A7=92=E8=89=B2=E5=88=97=E8=A1=A8`=20(?= =?UTF-8?q?#819)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Display info in role character query * Add range hint * Reduce the number of message sent by bot * Fix range display bug * Add command help --- apps/profile/ProfileStat.js | 54 ++++++++++++++++++++++++++++++++++-- config/help_default.js | 4 +++ config/system/help_system.js | 4 +++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/apps/profile/ProfileStat.js b/apps/profile/ProfileStat.js index c9e65941..9722a2dd 100644 --- a/apps/profile/ProfileStat.js +++ b/apps/profile/ProfileStat.js @@ -138,6 +138,44 @@ const ProfileStat = { return overallMazeInfo }, + sendRoleCombatInfo(e, elements, initialCharacterIds, invitationCharacterIds) { + const response = [ + ProfileStat.getElementInfo(elements), + ProfileStat.getInitialCharacterInfo(initialCharacterIds), + ProfileStat.getInvitationCharacterInfo(invitationCharacterIds), + ].join('\n') + e.reply(response) + }, + + getElementInfo(elements) { + // 让我们说中文! + const englishToChineseElements = { + 'anemo': '风', + 'geo': '岩', + 'electro': '雷', + 'dendro': '草', + 'hydro': '水', + 'pyro': '火', + 'cryo': '冰' + } + // 使用 lodash 将元素转换为中文名称,并用'、'组合成'风、岩' + const chineseElements = lodash.map(elements, (element) => englishToChineseElements[element]).join('、'); + return `限制元素:${chineseElements}` + }, + + getInitialCharacterInfo(initialCharacterIds) { + let characters = lodash.compact(lodash.map(initialCharacterIds, (id) => Character.get(id))) + let characterNames = lodash.map(characters, (character) => character.name).join('、') + return `开幕角色:${characterNames}` + }, + + getInvitationCharacterInfo(invitationCharacterIds) { + let characters = lodash.compact(lodash.map(invitationCharacterIds, (id) => Character.get(id))) + let characterNames = lodash.map(characters, (character) => character.name).join('、') + return `特邀角色:${characterNames}` + }, + + // TODO: BWiki 源的数据暂时没弄完,没接入逻辑中,暂时没啥必要? async getOverallMazeLinkFromBWiki() { const request_url = 'https://wiki.biligame.com/ys/%E5%B9%BB%E6%83%B3%E7%9C%9F%E5%A2%83%E5%89%A7%E8%AF%97' try { @@ -303,7 +341,8 @@ const ProfileStat = { mergedAvatars = Array.from(avatarMap.values()); // 排序 - let sortKey = 'level,star,aeq,cons,weapon.level,weapon.star,weapon.affix,fetter'.split(',') + // 按照元素进行区分 + let sortKey = 'elem,level,star,aeq,cons,weapon.level,weapon.star,weapon.affix,fetter'.split(',') mergedAvatars = lodash.orderBy(mergedAvatars, sortKey) mergedAvatars = mergedAvatars.reverse() @@ -360,13 +399,24 @@ const ProfileStat = { } let currentMazeData = ProfileStat.extractRequestedMazeData(e, overallMazeData) if (!currentMazeData) { - e.reply(`当前月份不在 HomDGCat 数据库中`) + const n = overallMazeData.length - 1 + 4 * 12 + 7 - 1 + const maxYear = Math.floor(n / 12) + const maxMonth = n % 12 + 1 + const formattedMonth = String(maxMonth).padStart(2, '0'); // 将月份格式化为两位数 + const response = [ + `当前月份不在 HomDGCat 数据库中`, + `可供查询的月份:202407 - 202${maxYear}${formattedMonth}` + ].join('\n') + e.reply(response) return false } let initialCharacterIds = ProfileStat.extractInitialCharacterIds(currentMazeData) let invitationCharacterIds = ProfileStat.extractInvitationCharacterIds(currentMazeData) let elements = ProfileStat.extractElements(currentMazeData) + // 发送简要的信息 + ProfileStat.sendRoleCombatInfo(e, elements, initialCharacterIds, invitationCharacterIds) + avatarRet = ProfileStat.mergeStart(avatarRet, initialCharacterIds) filterFunc = ProfileStat.getRoleFilterFunc(e, elements, invitationCharacterIds) } else { diff --git a/config/help_default.js b/config/help_default.js index b597fa77..f21ea434 100644 --- a/config/help_default.js +++ b/config/help_default.js @@ -69,6 +69,10 @@ export const helpList = [{ icon: 64, title: '#幻想 #幻想真境剧诗', desc: '幻想真境剧诗数据' + }, { + icon: 55, + title: '#202407幻想角色列表', + desc: '幻想真境剧诗入场角色查询' }, { icon: 67, title: '#五星 #武器 #今日素材', diff --git a/config/system/help_system.js b/config/system/help_system.js index b8550928..fd5d9c20 100644 --- a/config/system/help_system.js +++ b/config/system/help_system.js @@ -53,6 +53,10 @@ export const helpList = [{ icon: 64, title: '#幻想 #幻想真境剧诗', desc: '幻想真境剧诗数据' + }, { + icon: 55, + title: '#202407幻想角色列表', + desc: '幻想真境剧诗入场角色查询' }, { icon: 67, title: '#五星 #武器 #今日素材', From 4286c6c0aa0b86aa71e1cd6ab9aed6bd671579c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=8C?= Date: Wed, 30 Oct 2024 00:00:11 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fetch=20=E6=98=AF=E7=A5=96=E5=AE=97?= =?UTF-8?q?=E4=B9=8B=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/profile/ProfileStat.js | 11 ++++------- package.json | 8 +++----- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/apps/profile/ProfileStat.js b/apps/profile/ProfileStat.js index 9722a2dd..3e80b946 100644 --- a/apps/profile/ProfileStat.js +++ b/apps/profile/ProfileStat.js @@ -2,8 +2,8 @@ import { Common } from '#miao' import { MysApi, Player, Character } from '#miao.models' import moment from 'moment' import lodash from 'lodash' -import axios from 'axios' import cheerio from 'cheerio' +import fetch from 'node-fetch' const ProfileStat = { async stat (e) { @@ -120,8 +120,7 @@ const ProfileStat = { const request_url = 'https://homdgcat.wiki/gi/CH/maze.js' let resData = false try { - const response = await axios.get(request_url, {timeout: 5000}) - resData = response.data + resData = await (await fetch(request_url)).text() } catch (error) { logger.error('请求失败:', error) return false // 直接返回以停止后续逻辑 @@ -180,8 +179,7 @@ const ProfileStat = { const request_url = 'https://wiki.biligame.com/ys/%E5%B9%BB%E6%83%B3%E7%9C%9F%E5%A2%83%E5%89%A7%E8%AF%97' try { // 发送 GET 请求 - const response = await axios.get(request_url, {timeout: 5000}); - const html = response.data; + const html = await (await fetch(request_url)).text() // 加载 HTML const $ = cheerio.load(html); @@ -209,8 +207,7 @@ const ProfileStat = { const request_url = `https://wiki.biligame.com/${links[mazeId]}` // 发送 GET 请求 - const response = await axios.get(request_url, {timeout: 5000}); - const html = response.data; + const html = await (await fetch(request_url)).text() // 加载 HTML const $ = cheerio.load(html); diff --git a/package.json b/package.json index 229719e0..1ee88e34 100644 --- a/package.json +++ b/package.json @@ -4,14 +4,12 @@ "author": "Yoimiya-Kokomi", "description": "miao-plugin", "type": "module", - "scripts": { - }, + "scripts": {}, "dependencies": { - "image-size": "^1.0.2", - "axios": "^1.7.7" + "image-size": "^1.1.1" }, "devDependencies": { - "cheerio": "1.0.0-rc.12", + "cheerio": "1.0.0", "request": "^2.88.2" }, "imports": { From 0d302f43945d2924156d9b91ec625dc6bcb36160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=8C?= Date: Wed, 30 Oct 2024 00:44:53 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20cheerio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/profile/ProfileStat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/profile/ProfileStat.js b/apps/profile/ProfileStat.js index 3e80b946..893dc32d 100644 --- a/apps/profile/ProfileStat.js +++ b/apps/profile/ProfileStat.js @@ -2,8 +2,8 @@ import { Common } from '#miao' import { MysApi, Player, Character } from '#miao.models' import moment from 'moment' import lodash from 'lodash' -import cheerio from 'cheerio' import fetch from 'node-fetch' +import * as cheerio from 'cheerio' const ProfileStat = { async stat (e) { From 59c9c5f5e338cf30758b9afd6f188d908f8a8d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B6=E5=AE=9E=E9=9B=A8=E5=BE=88=E5=A5=BD?= <2122840028@qq.com> Date: Sun, 3 Nov 2024 16:01:57 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E6=BB=A1=E8=A1=8C=E8=BF=B9=E4=B9=B1?= =?UTF-8?q?=E7=A0=B4=E9=9D=A2=E6=9D=BF=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/meta-sr/character/乱破/data.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/meta-sr/character/乱破/data.json b/resources/meta-sr/character/乱破/data.json index 30e3ee53..20f40fc8 100644 --- a/resources/meta-sr/character/乱破/data.json +++ b/resources/meta-sr/character/乱破/data.json @@ -477,6 +477,10 @@ "1317209": { "key": "speed", "value": 4 + }, + "1317210": { + "key": "atk", + "value": 8 } }, "treeData": { @@ -692,4 +696,4 @@ } } } -} \ No newline at end of file +}