优化角色列表的天赋获取逻辑

This commit is contained in:
Kokomi 2023-02-18 18:29:09 +08:00
parent 6b11badb66
commit 7ea4dafd6f
5 changed files with 106 additions and 79 deletions

View File

@ -1,4 +1,4 @@
import { App } from '../components/index.js' import { App, Cfg } from '../components/index.js'
import { profileHelp } from './profile/ProfileCommon.js' import { profileHelp } from './profile/ProfileCommon.js'
import { profileArtisList } from './profile/ProfileArtis.js' import { profileArtisList } from './profile/ProfileArtis.js'
import { profileDetail } from './profile/ProfileDetail.js' import { profileDetail } from './profile/ProfileDetail.js'
@ -15,112 +15,122 @@ let app = App.init({
app.reg({ app.reg({
profileDetail: { profileDetail: {
rule: /^#*([^#]+)\s*(详细|详情|面板|面版|圣遗物|伤害[1-7]?)\s*(\d{9})*(.*[换变改].*)?$/, name: '角色面板',
fn: profileDetail, fn: profileDetail,
name: '角色面板' rule: /^#*([^#]+)\s*(详细|详情|面板|面版|圣遗物|伤害[1-7]?)\s*(\d{9})*(.*[换变改].*)?$/
}, },
profileChange: { profileChange: {
rule: /^#.+换.+$/, name: '角色面板计算',
fn: profileDetail, fn: profileDetail,
name: '角色面板计算' rule: /^#.+换.+$/
}, },
groupProfile: { groupProfile: {
rule: /^#(群|群内)?(排名|排行)?(最强|最高|最高分|最牛|第一)+.+/, name: '群内最强',
fn: groupRank, fn: groupRank,
name: '群内最强' rule: /^#(群|群内)?(排名|排行)?(最强|最高|最高分|最牛|第一)+.+/
}, },
resetRank: { resetRank: {
rule: /^#(重置|重设)(.*)(排名|排行)$/, name: '重置排名',
fn: resetRank, fn: resetRank,
name: '重置排名' rule: /^#(重置|重设)(.*)(排名|排行)$/
}, },
refreshRank: { refreshRank: {
rule: /^#(刷新|更新|重新加载)(群内|群|全部)*(排名|排行)$/, name: '重置排名',
fn: refreshRank, fn: refreshRank,
name: '重置排名' rule: /^#(刷新|更新|重新加载)(群内|群|全部)*(排名|排行)$/
}, },
manageRank: { manageRank: {
rule: /^#(开启|打开|启用|关闭|禁用)(群内|群|全部)*(排名|排行)$/, name: '打开关闭',
fn: manageRank, fn: manageRank,
name: '打开关闭' rule: /^#(开启|打开|启用|关闭|禁用)(群内|群|全部)*(排名|排行)$/
}, },
rankList: { rankList: {
rule: /^#(群|群内)?.+(排名|排行)(榜)?$/, name: '面板排名榜',
fn: groupRank, fn: groupRank,
name: '面板排名榜' rule: /^#(群|群内)?.+(排名|排行)(榜)?$/
}, },
artisList: { artisList: {
rule: /^#圣遗物列表\s*(\d{9})?$/, name: '面板圣遗物列表',
fn: profileArtisList, fn: profileArtisList,
name: '面板圣遗物列表' rule: /^#圣遗物列表\s*(\d{9})?$/
}, },
profileList: { profileList: {
rule: /^#(面板角色|角色面板|面板)(列表)?\s*(\d{9})?$/,
fn: ProfileList.render,
name: '面板角色列表', name: '面板角色列表',
desc: '查看当前已获取面板数据的角色列表' desc: '查看当前已获取面板数据的角色列表',
fn: ProfileList.render,
rule: /^#(面板角色|角色面板|面板)(列表)?\s*(\d{9})?$/
}, },
profileStat: { profileStat: {
rule: /^#(面板|喵喵|角色|武器|天赋|技能|圣遗物)?练度统计$/, name: '面板练度统计',
fn: ProfileStat.stat, fn: ProfileStat.stat,
name: '面板练度统计' rule: /^#(面板|喵喵)练度统计$/,
yzRule: /^#*(我的)*(技能|天赋|武器|角色|练度|五|四|5|4|星)+(汇总|统计|列表)(force|五|四|5|4|星)*[ |0-9]*$/,
yzCheck: () => Cfg.get('profileStat', false)
}, },
avatarList: { avatarList: {
rule: /^(#(角色|查询|查询角色|角色查询|人物)[ |0-9]*$)|(^(#*uid|#*UID)\+*[1|2|5-9][0-9]{8}$)|(^#[\+|]*[1|2|5-9][0-9]{8})/, name: '角色查询',
fn: ProfileStat.avatarList, fn: ProfileStat.avatarList,
name: '角色查询' rule: /^#喵喵(角色|查询)[ |0-9]*$/,
yzRule: /^(#(角色|查询|查询角色|角色查询|人物)[ |0-9]*$)|(^(#*uid|#*UID)\+*[1|2|5-9][0-9]{8}$)|(^#[\+|]*[1|2|5-9][0-9]{8})/,
yzCheck: () => Cfg.get('avatarList', false)
}, },
profileHelp: { profileHelp: {
rule: /^#(角色|换|更换)?面[板版]帮助$/, name: '角色面板帮助',
fn: profileHelp, fn: profileHelp,
name: '角色面板帮助' rule: /^#(角色|换|更换)?面[板版]帮助$/
}, },
enemyLv: { enemyLv: {
rule: /^#(敌人|怪物)等级\s*\d{1,3}\s*$/, name: '敌人等级',
fn: enemyLv, fn: enemyLv,
describe: '【#角色】 设置伤害计算中目标敌人的等级' describe: '【#角色】 设置伤害计算中目标敌人的等级',
rule: /^#(敌人|怪物)等级\s*\d{1,3}\s*$/
}, },
profileRefresh: { profileRefresh: {
rule: /^#(全部面板更新|更新全部面板|获取游戏角色详情|更新面板|面板更新)\s*(\d{9})?$/, name: '面板更新',
describe: '【#角色】 获取游戏橱窗详情数据',
fn: ProfileList.refresh, fn: ProfileList.refresh,
describe: '【#角色】 获取游戏橱窗详情数据' rule: /^#(全部面板更新|更新全部面板|获取游戏角色详情|更新面板|面板更新)\s*(\d{9})?$/
}, },
uploadImg: { uploadImg: {
rule: /^#?\s*(?:上传|添加)(.+)(?:面板图)\s*$/, name: '上传面板图',
describe: '【#上传刻晴面板图】 上传角色面板图',
fn: uploadCharacterImg, fn: uploadCharacterImg,
describe: '【#上传刻晴面板图】 上传角色面板图' rule: /^#?\s*(?:上传|添加)(.+)(?:面板图)\s*$/
}, },
delProfile: { delProfile: {
rule: /^#?\s*(?:移除|清除|删除)(.+)(?:面板图)(\d){1,}\s*$/, name: '删除面板图',
describe: '【#删除刻晴面板图1】 删除指定角色面板图(序号)',
fn: delProfileImg, fn: delProfileImg,
describe: '【#删除刻晴面板图1】 删除指定角色面板图(序号)' rule: /^#?\s*(?:移除|清除|删除)(.+)(?:面板图)(\d){1,}\s*$/
}, },
profileImgList: { profileImgList: {
rule: /^#?\s*(.+)(?:面板图列表)\s*$/, name: '面板图列表',
describe: '【#刻晴面板图列表】 删除指定角色面板图(序号)',
fn: profileImgList, fn: profileImgList,
describe: '【#刻晴面板图列表】 删除指定角色面板图(序号)' rule: /^#?\s*(.+)(?:面板图列表)\s*$/
}, },
profileDel: { profileDel: {
rule: /^#(删除全部面板|删除面板|删除面板数据)\s*(\d{9})?$/, name: '删除面板',
describe: '【#角色】 删除游戏橱窗详情数据',
fn: ProfileList.del, fn: ProfileList.del,
describe: '【#角色】 删除游戏橱窗详情数据' rule: /^#(删除全部面板|删除面板|删除面板数据)\s*(\d{9})?$/
} }
}) })

View File

@ -1,19 +1,13 @@
import { Cfg, Common } from '../../components/index.js' import { Common } from '../../components/index.js'
import { MysApi, Player, Character } from '../../models/index.js' import { MysApi, Player, Character } from '../../models/index.js'
const ProfileStat = { const ProfileStat = {
async stat (e) { async stat (e) {
let isMatch = /^#(面板|喵喵|角色|武器|天赋|技能|圣遗物)练度统计?$/.test(e.original_msg || e.msg || '') return ProfileStat.render(e, false)
if (!Cfg.get('profileStat', false) && !isMatch) {
return false
}
return await ProfileStat.render(e)
}, },
async avatarList (e) { async avatarList (e) {
if (!Cfg.get('avatarList', false)) { return ProfileStat.render(e, true)
return false
}
return await ProfileStat.render(e, true)
}, },
async render (e, isAvatarList = false) { async render (e, isAvatarList = false) {
// 缓存时间,单位小时 // 缓存时间,单位小时
@ -30,11 +24,9 @@ const ProfileStat = {
let player = Player.create(e) let player = Player.create(e)
await player.refreshMysInfo()
let avatarRet = await player.refreshAndGetAvatarData({ let avatarRet = await player.refreshAndGetAvatarData({
detail: 1, detail: 1,
talent: 0, talent: isAvatarList ? 0 : 1,
rank: true, rank: true,
retType: 'array', retType: 'array',
sort: true sort: true

View File

@ -69,6 +69,8 @@ class App {
fnc: key fnc: key
}) })
console.log('rule', rule)
if (app.check) { if (app.check) {
check.push(app.check) check.push(app.check)
} }
@ -92,6 +94,24 @@ class App {
e.original_msg = e.original_msg || e.msg e.original_msg = e.original_msg || e.msg
return await app.fn.call(this, e) return await app.fn.call(this, e)
} }
if (app.yzRule && app.yzCheck) {
let yzKey = `Yz${key}`
let yzRule = lodash.trim(app.yzRule.toString(), '/')
rules.push({
reg: yzRule,
fnc: yzKey
})
cls.prototype[yzKey] = async function () {
if (!app.yzCheck()) {
return false
}
let e = this.e
e.original_msg = e.original_msg || e.msg
return await app.fn.call(this, e)
}
}
} }
return cls return cls
} }
@ -139,6 +159,14 @@ class App {
if (ret === true) { if (ret === true) {
return true return true
} }
} else if (app.yzRule && app.yzCheck()) {
rule = new RegExp(app.yzRule)
if (rule.test(msg)) {
let ret = await app.fn(e, {})
if (ret === true) {
return true
}
}
} }
} else if (event === 'poke' && msg === '#poke#') { } else if (event === 'poke' && msg === '#poke#') {
let ret = await app.fn(e, {}) let ret = await app.fn(e, {})

View File

@ -155,16 +155,17 @@ export default class AvatarData extends Base {
} }
} }
setTalent (ds = {}, mode = 'original', source = '') { setTalent (ds = false, mode = 'original', updateTime = '') {
const now = this._now || (new Date()) * 1 const now = this._now || (new Date()) * 1
if (ds) {
let ret = this.char.getAvatarTalent(ds, this.cons, mode) let ret = this.char.getAvatarTalent(ds, this.cons, mode)
if (!ret) { if (ret) {
return false
}
this.talent = ret || this.talent this.talent = ret || this.talent
// 设置天赋更新时间 // 设置天赋更新时间
this._talent = ds._talent || this._talent || ds._time || now this._talent = ds._talent || this._talent || ds._time || now
if (source && ret) { }
}
if (updateTime) {
this._talent = now this._talent = now
} }
} }

View File

@ -12,11 +12,12 @@ const MysAvatar = {
if (force === true) { if (force === true) {
force = 0 force = 0
} }
let duration = new Date() * 1 - time * 1 let duration = (new Date() * 1 - time * 1) / 1000
if (isNaN(duration) || duration < 0) { if (isNaN(duration) || duration < 0) {
return true return true
} }
return duration > (forceMap[force] || 60) * 60 * 1000 let reqTime = forceMap[force] === 0 ? 0 : (forceMap[force] || 60)
return duration > reqTime * 60
}, },
/** /**
* 更新米游社角色信息 * 更新米游社角色信息
@ -194,21 +195,18 @@ const MysAvatar = {
if (needReqIds.length > 8) { if (needReqIds.length > 8) {
e && e.reply('正在获取角色信息,请稍候...') e && e.reply('正在获取角色信息,请稍候...')
} }
let num = 10 let failCount = 0
let ms = 100 // 并发5请求天赋数据
let skillRet = [] await Data.asyncPool(5, needReqIds, async (id) => {
let avatarArr = lodash.chunk(needReqIds, num)
for (let val of avatarArr) {
for (let id of val) {
let avatar = player.getAvatar(id) let avatar = player.getAvatar(id)
if (avatar) { if (!avatar || failCount > 5) {
skillRet.push(await MysAvatar.refreshAvatarTalent(avatar, mys)) return false
} }
let ret = await MysAvatar.refreshAvatarTalent(avatar, mys)
if (ret === false) {
failCount++
} }
skillRet = await Promise.all(skillRet) })
skillRet = skillRet.filter(item => item.id)
await Common.sleep(ms)
}
} }
player.save() player.save()
}, },
@ -241,10 +239,8 @@ const MysAvatar = {
} }
} }
let ret = char.getAvatarTalent(talent, avatar.cons, 'original') let ret = char.getAvatarTalent(talent, avatar.cons, 'original')
if (ret) { avatar.setTalent(ret, 'original', true)
avatar.setTalent(ret, 'original', 'mys') return !!ret
}
return true
} }
return false return false
}, },