Merge branch 'master' into patch-2

This commit is contained in:
UCPr 2024-11-13 13:44:52 +08:00 committed by GitHub
commit ed3ea78ad3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 71 additions and 13 deletions

View File

@ -2,8 +2,8 @@ import { Common } from '#miao'
import { MysApi, Player, Character } from '#miao.models' import { MysApi, Player, Character } from '#miao.models'
import moment from 'moment' import moment from 'moment'
import lodash from 'lodash' import lodash from 'lodash'
import axios from 'axios' import fetch from 'node-fetch'
import cheerio from 'cheerio' import * as cheerio from 'cheerio'
const ProfileStat = { const ProfileStat = {
async stat (e) { async stat (e) {
@ -120,8 +120,7 @@ const ProfileStat = {
const request_url = 'https://homdgcat.wiki/gi/CH/maze.js' const request_url = 'https://homdgcat.wiki/gi/CH/maze.js'
let resData = false let resData = false
try { try {
const response = await axios.get(request_url, {timeout: 5000}) resData = await (await fetch(request_url)).text()
resData = response.data
} catch (error) { } catch (error) {
logger.error('请求失败:', error) logger.error('请求失败:', error)
return false // 直接返回以停止后续逻辑 return false // 直接返回以停止后续逻辑
@ -138,12 +137,49 @@ const ProfileStat = {
return overallMazeInfo 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() { 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' 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 { try {
// 发送 GET 请求 // 发送 GET 请求
const response = await axios.get(request_url, {timeout: 5000}); const html = await (await fetch(request_url)).text()
const html = response.data;
// 加载 HTML // 加载 HTML
const $ = cheerio.load(html); const $ = cheerio.load(html);
@ -171,8 +207,7 @@ const ProfileStat = {
const request_url = `https://wiki.biligame.com/${links[mazeId]}` const request_url = `https://wiki.biligame.com/${links[mazeId]}`
// 发送 GET 请求 // 发送 GET 请求
const response = await axios.get(request_url, {timeout: 5000}); const html = await (await fetch(request_url)).text()
const html = response.data;
// 加载 HTML // 加载 HTML
const $ = cheerio.load(html); const $ = cheerio.load(html);
@ -303,7 +338,8 @@ const ProfileStat = {
mergedAvatars = Array.from(avatarMap.values()); 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 = lodash.orderBy(mergedAvatars, sortKey)
mergedAvatars = mergedAvatars.reverse() mergedAvatars = mergedAvatars.reverse()
@ -360,13 +396,24 @@ const ProfileStat = {
} }
let currentMazeData = ProfileStat.extractRequestedMazeData(e, overallMazeData) let currentMazeData = ProfileStat.extractRequestedMazeData(e, overallMazeData)
if (!currentMazeData) { 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 return false
} }
let initialCharacterIds = ProfileStat.extractInitialCharacterIds(currentMazeData) let initialCharacterIds = ProfileStat.extractInitialCharacterIds(currentMazeData)
let invitationCharacterIds = ProfileStat.extractInvitationCharacterIds(currentMazeData) let invitationCharacterIds = ProfileStat.extractInvitationCharacterIds(currentMazeData)
let elements = ProfileStat.extractElements(currentMazeData) let elements = ProfileStat.extractElements(currentMazeData)
// 发送简要的信息
ProfileStat.sendRoleCombatInfo(e, elements, initialCharacterIds, invitationCharacterIds)
avatarRet = ProfileStat.mergeStart(avatarRet, initialCharacterIds) avatarRet = ProfileStat.mergeStart(avatarRet, initialCharacterIds)
filterFunc = ProfileStat.getRoleFilterFunc(e, elements, invitationCharacterIds) filterFunc = ProfileStat.getRoleFilterFunc(e, elements, invitationCharacterIds)
} else { } else {

View File

@ -69,6 +69,10 @@ export const helpList = [{
icon: 64, icon: 64,
title: '#幻想 #幻想真境剧诗', title: '#幻想 #幻想真境剧诗',
desc: '幻想真境剧诗数据' desc: '幻想真境剧诗数据'
}, {
icon: 55,
title: '#202407幻想角色列表',
desc: '幻想真境剧诗入场角色查询'
}, { }, {
icon: 67, icon: 67,
title: '#五星 #武器 #今日素材', title: '#五星 #武器 #今日素材',

View File

@ -53,6 +53,10 @@ export const helpList = [{
icon: 64, icon: 64,
title: '#幻想 #幻想真境剧诗', title: '#幻想 #幻想真境剧诗',
desc: '幻想真境剧诗数据' desc: '幻想真境剧诗数据'
}, {
icon: 55,
title: '#202407幻想角色列表',
desc: '幻想真境剧诗入场角色查询'
}, { }, {
icon: 67, icon: 67,
title: '#五星 #武器 #今日素材', title: '#五星 #武器 #今日素材',

View File

@ -7,8 +7,7 @@
"scripts": {}, "scripts": {},
"dependencies": { "dependencies": {
"image-size": "^1.0.2", "image-size": "^1.0.2",
"cheerio": "1.0.0-rc.12", "cheerio": "1.0.0"
"axios": "^1.7.7"
}, },
"devDependencies": { "devDependencies": {
"request": "^2.88.2" "request": "^2.88.2"

View File

@ -477,6 +477,10 @@
"1317209": { "1317209": {
"key": "speed", "key": "speed",
"value": 4 "value": 4
},
"1317210": {
"key": "atk",
"value": 8
} }
}, },
"treeData": { "treeData": {
@ -692,4 +696,4 @@
} }
} }
} }
} }