diff --git a/apps/profile.js b/apps/profile.js index 8eadb3ea..a01c54fe 100644 --- a/apps/profile.js +++ b/apps/profile.js @@ -1,4 +1,4 @@ -import { App } from '../components/index.js' +import { App, Cfg } from '../components/index.js' import { profileHelp } from './profile/ProfileCommon.js' import { profileArtisList } from './profile/ProfileArtis.js' import { profileDetail } from './profile/ProfileDetail.js' @@ -15,112 +15,122 @@ let app = App.init({ app.reg({ profileDetail: { - rule: /^#*([^#]+)\s*(详细|详情|面板|面版|圣遗物|伤害[1-7]?)\s*(\d{9})*(.*[换变改].*)?$/, + name: '角色面板', fn: profileDetail, - name: '角色面板' + rule: /^#*([^#]+)\s*(详细|详情|面板|面版|圣遗物|伤害[1-7]?)\s*(\d{9})*(.*[换变改].*)?$/ }, profileChange: { - rule: /^#.+换.+$/, + name: '角色面板计算', fn: profileDetail, - name: '角色面板计算' + rule: /^#.+换.+$/ }, groupProfile: { - rule: /^#(群|群内)?(排名|排行)?(最强|最高|最高分|最牛|第一)+.+/, + name: '群内最强', fn: groupRank, - name: '群内最强' + rule: /^#(群|群内)?(排名|排行)?(最强|最高|最高分|最牛|第一)+.+/ }, resetRank: { - rule: /^#(重置|重设)(.*)(排名|排行)$/, + name: '重置排名', fn: resetRank, - name: '重置排名' + rule: /^#(重置|重设)(.*)(排名|排行)$/ }, refreshRank: { - rule: /^#(刷新|更新|重新加载)(群内|群|全部)*(排名|排行)$/, + name: '重置排名', fn: refreshRank, - name: '重置排名' + rule: /^#(刷新|更新|重新加载)(群内|群|全部)*(排名|排行)$/ }, manageRank: { - rule: /^#(开启|打开|启用|关闭|禁用)(群内|群|全部)*(排名|排行)$/, + name: '打开关闭', fn: manageRank, - name: '打开关闭' + rule: /^#(开启|打开|启用|关闭|禁用)(群内|群|全部)*(排名|排行)$/ }, rankList: { - rule: /^#(群|群内)?.+(排名|排行)(榜)?$/, + name: '面板排名榜', fn: groupRank, - name: '面板排名榜' + rule: /^#(群|群内)?.+(排名|排行)(榜)?$/ }, artisList: { - rule: /^#圣遗物列表\s*(\d{9})?$/, + name: '面板圣遗物列表', fn: profileArtisList, - name: '面板圣遗物列表' + rule: /^#圣遗物列表\s*(\d{9})?$/ }, profileList: { - rule: /^#(面板角色|角色面板|面板)(列表)?\s*(\d{9})?$/, - fn: ProfileList.render, name: '面板角色列表', - desc: '查看当前已获取面板数据的角色列表' + desc: '查看当前已获取面板数据的角色列表', + fn: ProfileList.render, + rule: /^#(面板角色|角色面板|面板)(列表)?\s*(\d{9})?$/ }, profileStat: { - rule: /^#(面板|喵喵|角色|武器|天赋|技能|圣遗物)?练度统计$/, + name: '面板练度统计', fn: ProfileStat.stat, - name: '面板练度统计' + rule: /^#(面板|喵喵)练度统计$/, + yzRule: /^#*(我的)*(技能|天赋|武器|角色|练度|五|四|5|4|星)+(汇总|统计|列表)(force|五|四|5|4|星)*[ |0-9]*$/, + yzCheck: () => Cfg.get('profileStat', false) }, avatarList: { - rule: /^(#(角色|查询|查询角色|角色查询|人物)[ |0-9]*$)|(^(#*uid|#*UID)\+*[1|2|5-9][0-9]{8}$)|(^#[\+|+]*[1|2|5-9][0-9]{8})/, + name: '角色查询', 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: { - rule: /^#(角色|换|更换)?面[板版]帮助$/, + name: '角色面板帮助', fn: profileHelp, - name: '角色面板帮助' + rule: /^#(角色|换|更换)?面[板版]帮助$/ }, enemyLv: { - rule: /^#(敌人|怪物)等级\s*\d{1,3}\s*$/, + name: '敌人等级', fn: enemyLv, - describe: '【#角色】 设置伤害计算中目标敌人的等级' + describe: '【#角色】 设置伤害计算中目标敌人的等级', + rule: /^#(敌人|怪物)等级\s*\d{1,3}\s*$/ }, profileRefresh: { - rule: /^#(全部面板更新|更新全部面板|获取游戏角色详情|更新面板|面板更新)\s*(\d{9})?$/, + name: '面板更新', + describe: '【#角色】 获取游戏橱窗详情数据', fn: ProfileList.refresh, - describe: '【#角色】 获取游戏橱窗详情数据' + rule: /^#(全部面板更新|更新全部面板|获取游戏角色详情|更新面板|面板更新)\s*(\d{9})?$/ }, uploadImg: { - rule: /^#?\s*(?:上传|添加)(.+)(?:面板图)\s*$/, + name: '上传面板图', + describe: '【#上传刻晴面板图】 上传角色面板图', fn: uploadCharacterImg, - describe: '【#上传刻晴面板图】 上传角色面板图' + rule: /^#?\s*(?:上传|添加)(.+)(?:面板图)\s*$/ }, delProfile: { - rule: /^#?\s*(?:移除|清除|删除)(.+)(?:面板图)(\d){1,}\s*$/, + name: '删除面板图', + describe: '【#删除刻晴面板图1】 删除指定角色面板图(序号)', fn: delProfileImg, - describe: '【#删除刻晴面板图1】 删除指定角色面板图(序号)' + rule: /^#?\s*(?:移除|清除|删除)(.+)(?:面板图)(\d){1,}\s*$/ }, profileImgList: { - rule: /^#?\s*(.+)(?:面板图列表)\s*$/, + name: '面板图列表', + describe: '【#刻晴面板图列表】 删除指定角色面板图(序号)', fn: profileImgList, - describe: '【#刻晴面板图列表】 删除指定角色面板图(序号)' + rule: /^#?\s*(.+)(?:面板图列表)\s*$/ }, profileDel: { - rule: /^#(删除全部面板|删除面板|删除面板数据)\s*(\d{9})?$/, + name: '删除面板', + describe: '【#角色】 删除游戏橱窗详情数据', fn: ProfileList.del, - describe: '【#角色】 删除游戏橱窗详情数据' + rule: /^#(删除全部面板|删除面板|删除面板数据)\s*(\d{9})?$/ } }) diff --git a/apps/profile/ProfileStat.js b/apps/profile/ProfileStat.js index 160f0f18..a5c5d571 100644 --- a/apps/profile/ProfileStat.js +++ b/apps/profile/ProfileStat.js @@ -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' const ProfileStat = { async stat (e) { - let isMatch = /^#(面板|喵喵|角色|武器|天赋|技能|圣遗物)练度统计?$/.test(e.original_msg || e.msg || '') - if (!Cfg.get('profileStat', false) && !isMatch) { - return false - } - return await ProfileStat.render(e) + return ProfileStat.render(e, false) }, + async avatarList (e) { - if (!Cfg.get('avatarList', false)) { - return false - } - return await ProfileStat.render(e, true) + return ProfileStat.render(e, true) }, async render (e, isAvatarList = false) { // 缓存时间,单位小时 @@ -30,11 +24,9 @@ const ProfileStat = { let player = Player.create(e) - await player.refreshMysInfo() - let avatarRet = await player.refreshAndGetAvatarData({ detail: 1, - talent: 0, + talent: isAvatarList ? 0 : 1, rank: true, retType: 'array', sort: true diff --git a/components/App.js b/components/App.js index ca8d3b56..49006355 100644 --- a/components/App.js +++ b/components/App.js @@ -69,6 +69,8 @@ class App { fnc: key }) + console.log('rule', rule) + if (app.check) { check.push(app.check) } @@ -92,6 +94,24 @@ class App { e.original_msg = e.original_msg || e.msg 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 } @@ -139,6 +159,14 @@ class App { if (ret === 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#') { let ret = await app.fn(e, {}) diff --git a/models/AvatarData.js b/models/AvatarData.js index 2eaad25b..dab6b859 100644 --- a/models/AvatarData.js +++ b/models/AvatarData.js @@ -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 - let ret = this.char.getAvatarTalent(ds, this.cons, mode) - if (!ret) { - return false + if (ds) { + let ret = this.char.getAvatarTalent(ds, this.cons, mode) + if (ret) { + this.talent = ret || this.talent + // 设置天赋更新时间 + this._talent = ds._talent || this._talent || ds._time || now + } } - this.talent = ret || this.talent - // 设置天赋更新时间 - this._talent = ds._talent || this._talent || ds._time || now - if (source && ret) { + if (updateTime) { this._talent = now } } diff --git a/models/player/MysAvatar.js b/models/player/MysAvatar.js index af9f5469..d9d9383f 100644 --- a/models/player/MysAvatar.js +++ b/models/player/MysAvatar.js @@ -12,11 +12,12 @@ const MysAvatar = { if (force === true) { force = 0 } - let duration = new Date() * 1 - time * 1 + let duration = (new Date() * 1 - time * 1) / 1000 if (isNaN(duration) || duration < 0) { 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) { e && e.reply('正在获取角色信息,请稍候...') } - let num = 10 - let ms = 100 - let skillRet = [] - let avatarArr = lodash.chunk(needReqIds, num) - for (let val of avatarArr) { - for (let id of val) { - let avatar = player.getAvatar(id) - if (avatar) { - skillRet.push(await MysAvatar.refreshAvatarTalent(avatar, mys)) - } + let failCount = 0 + // 并发5,请求天赋数据 + await Data.asyncPool(5, needReqIds, async (id) => { + let avatar = player.getAvatar(id) + if (!avatar || failCount > 5) { + return false } - skillRet = await Promise.all(skillRet) - skillRet = skillRet.filter(item => item.id) - await Common.sleep(ms) - } + let ret = await MysAvatar.refreshAvatarTalent(avatar, mys) + if (ret === false) { + failCount++ + } + }) } player.save() }, @@ -241,10 +239,8 @@ const MysAvatar = { } } let ret = char.getAvatarTalent(talent, avatar.cons, 'original') - if (ret) { - avatar.setTalent(ret, 'original', 'mys') - } - return true + avatar.setTalent(ret, 'original', true) + return !!ret } return false },