2023-03-07 17:52:11 +00:00
|
|
|
|
import ProfileDetail from './ProfileDetail.js'
|
2023-10-08 12:43:48 +00:00
|
|
|
|
import { Data, Common, Format, Cfg } from '#miao'
|
2024-02-04 01:27:34 +00:00
|
|
|
|
import { Button, Character, ProfileRank, ProfileDmg, Player } from '#miao.models'
|
2023-03-27 19:42:50 +00:00
|
|
|
|
import lodash from 'lodash'
|
2022-11-08 22:04:08 +00:00
|
|
|
|
|
2024-05-13 12:05:34 +00:00
|
|
|
|
export async function groupRank (e) {
|
2022-11-12 21:35:46 +00:00
|
|
|
|
const groupRank = Common.cfg('groupRank')
|
2022-11-08 22:04:08 +00:00
|
|
|
|
let msg = e.original_msg || e.msg
|
2022-11-10 20:56:15 +00:00
|
|
|
|
let type = ''
|
|
|
|
|
if (/(排名|排行|列表)/.test(msg)) {
|
|
|
|
|
type = 'list'
|
2023-03-27 19:42:50 +00:00
|
|
|
|
} else if (/(最强|最高|最多|最高分|最牛|第一)/.test(msg)) {
|
2022-11-10 20:56:15 +00:00
|
|
|
|
type = 'detail'
|
2023-02-19 04:05:42 +00:00
|
|
|
|
} else if (/极限/.test(msg)) {
|
|
|
|
|
type = 'super'
|
2022-11-10 20:56:15 +00:00
|
|
|
|
}
|
2023-02-19 04:05:42 +00:00
|
|
|
|
let groupId = e.group_id
|
|
|
|
|
if (!type || (!groupId && type !== 'super')) {
|
2022-11-08 22:04:08 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
2024-01-27 21:59:31 +00:00
|
|
|
|
let mode = /(分|圣遗物|遗器|评分|ACE)/.test(msg) ? 'mark' : 'dmg'
|
2023-03-27 20:02:49 +00:00
|
|
|
|
mode = /(词条)/.test(msg) ? 'valid' : mode
|
2024-02-08 03:22:25 +00:00
|
|
|
|
mode = /(双爆|双暴)/.test(msg) ? 'crit' : mode
|
2024-03-28 12:46:14 +00:00
|
|
|
|
let name = msg.replace(/(#|星铁|最强|最高分|第一|词条|双爆|双暴|极限|最高|最多|最牛|圣遗物|遗器|评分|群内|群|排名|排行|面板|面版|详情|榜)/g, '')
|
2024-01-29 04:09:19 +00:00
|
|
|
|
let game = e.isSr ? 'sr' : 'gs'
|
|
|
|
|
let char = Character.get(name, game)
|
2022-11-22 20:25:36 +00:00
|
|
|
|
if (!char) {
|
|
|
|
|
// 名字不存在或不为列表模式,则返回false
|
|
|
|
|
if (name || type !== 'list') {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2024-02-08 03:22:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
e.isSr = char.game === 'sr'
|
2022-11-08 22:04:08 +00:00
|
|
|
|
}
|
2023-02-19 04:05:42 +00:00
|
|
|
|
// 对鲸泽佬的极限角色文件增加支持
|
|
|
|
|
if (type === 'super') {
|
2024-01-29 04:09:19 +00:00
|
|
|
|
let player = Player.create(100000000, game)
|
2023-02-19 04:05:42 +00:00
|
|
|
|
if (player.getProfile(char.id)) {
|
|
|
|
|
e.uid = 100000000
|
2023-10-24 13:25:54 +00:00
|
|
|
|
if (!char.isRelease && Cfg.get('notReleasedData') === false) {
|
2023-10-08 12:43:48 +00:00
|
|
|
|
e.reply('未实装角色面板已禁用...')
|
|
|
|
|
return true
|
|
|
|
|
}
|
2023-02-21 19:49:49 +00:00
|
|
|
|
return await ProfileDetail.render(e, char)
|
2023-02-19 04:05:42 +00:00
|
|
|
|
} else {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 正常群排名
|
2023-01-17 18:40:17 +00:00
|
|
|
|
let groupCfg = await ProfileRank.getGroupCfg(groupId)
|
2022-11-10 20:56:15 +00:00
|
|
|
|
if (!groupRank) {
|
2023-02-12 15:39:46 +00:00
|
|
|
|
e.reply('群面板排名功能已禁用,Bot主人可通过【#喵喵设置】启用...')
|
2023-01-17 18:40:17 +00:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
if (groupCfg.status === 1) {
|
2023-02-12 15:39:46 +00:00
|
|
|
|
e.reply('本群已关闭群排名,群管理员或Bot主人可通过【#启用排名】启用...')
|
2022-11-10 20:56:15 +00:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
if (type === 'detail') {
|
|
|
|
|
let uid = await ProfileRank.getGroupMaxUid(groupId, char.id, mode)
|
|
|
|
|
if (uid) {
|
|
|
|
|
e.uid = uid
|
2023-02-21 19:49:49 +00:00
|
|
|
|
return await ProfileDetail.render(e, char)
|
2022-11-08 22:32:20 +00:00
|
|
|
|
} else {
|
2023-05-21 18:13:38 +00:00
|
|
|
|
if (mode === 'dmg' && !ProfileDmg.dmgRulePath(char.name, char.game)) {
|
2024-02-04 01:27:34 +00:00
|
|
|
|
e.reply([`暂无排名:${char.name}暂不支持伤害计算,无法进行排名..`, new Button(e).profile(char)])
|
2022-11-10 20:56:15 +00:00
|
|
|
|
} else {
|
2022-11-12 21:35:46 +00:00
|
|
|
|
e.reply('暂无排名:请通过【#面板】查看角色面板以更新排名信息...')
|
2022-11-10 20:56:15 +00:00
|
|
|
|
}
|
2022-11-08 22:32:20 +00:00
|
|
|
|
}
|
2022-11-10 20:56:15 +00:00
|
|
|
|
} else if (type === 'list') {
|
2023-05-21 18:13:38 +00:00
|
|
|
|
if (mode === 'dmg' && char && !ProfileDmg.dmgRulePath(char.name, char.game)) {
|
2024-02-04 01:27:34 +00:00
|
|
|
|
e.reply([`暂无排名:${char.name}暂不支持伤害计算,无法进行排名..`, new Button(e).profile(char)])
|
2022-11-12 21:35:46 +00:00
|
|
|
|
} else {
|
2022-11-17 18:25:32 +00:00
|
|
|
|
let uids = []
|
|
|
|
|
if (char) {
|
|
|
|
|
uids = await ProfileRank.getGroupUidList(groupId, char ? char.id : '', mode)
|
|
|
|
|
} else {
|
2024-05-16 08:34:44 +00:00
|
|
|
|
uids = await ProfileRank.getGroupMaxUidList(groupId, mode, game)
|
2022-11-17 18:25:32 +00:00
|
|
|
|
}
|
2022-11-12 21:35:46 +00:00
|
|
|
|
if (uids.length > 0) {
|
|
|
|
|
return renderCharRankList({ e, uids, char, mode, groupId })
|
|
|
|
|
} else {
|
2024-01-27 21:59:31 +00:00
|
|
|
|
if (e.isSr) {
|
2024-02-04 01:27:34 +00:00
|
|
|
|
e.reply(['暂无排名:请通过【*面板】查看角色面板以更新排名信息...', new Button(e).profile(char)])
|
2023-09-15 00:13:11 +00:00
|
|
|
|
} else {
|
2024-02-04 01:27:34 +00:00
|
|
|
|
e.reply(['暂无排名:请通过【#面板】查看角色面板以更新排名信息...', new Button(e).profile(char)])
|
2023-09-15 00:13:11 +00:00
|
|
|
|
}
|
2022-11-12 21:35:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
2022-11-08 22:04:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-09 19:48:13 +00:00
|
|
|
|
|
2024-05-13 12:05:34 +00:00
|
|
|
|
export async function resetRank (e) {
|
2022-11-09 19:48:13 +00:00
|
|
|
|
let groupId = e.group_id
|
|
|
|
|
if (!groupId) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
if (!e.isMaster) {
|
|
|
|
|
e.reply('只有管理员可重置排名')
|
|
|
|
|
return true
|
|
|
|
|
}
|
2024-01-27 21:59:31 +00:00
|
|
|
|
let game = e.isSr ? 'sr' : 'gs'
|
2022-11-09 19:48:13 +00:00
|
|
|
|
let msg = e.original_msg || e.msg
|
2024-04-01 17:39:32 +00:00
|
|
|
|
let name = msg.replace(/(#|星铁|重置|重设|排名|排行|群|群内|面板|详情|面版)/g, '').trim()
|
2022-11-09 19:48:13 +00:00
|
|
|
|
let charId = ''
|
|
|
|
|
let charName = '全部角色'
|
|
|
|
|
if (name) {
|
2024-01-29 04:09:19 +00:00
|
|
|
|
let char = Character.get(name, game)
|
2022-11-09 19:48:13 +00:00
|
|
|
|
if (!char) {
|
|
|
|
|
e.reply(`重置排名失败,角色:${name}不存在`)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
charId = char.id
|
|
|
|
|
charName = char.name
|
|
|
|
|
}
|
2024-01-27 21:59:31 +00:00
|
|
|
|
await ProfileRank.resetRank(groupId, charId, game)
|
2024-02-08 03:22:25 +00:00
|
|
|
|
e.reply([`本群${charName}排名已重置...`, name ? new Button(e).profile(char) : ''])
|
2022-11-09 19:48:13 +00:00
|
|
|
|
}
|
2022-11-10 20:56:15 +00:00
|
|
|
|
|
2022-11-15 20:58:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* 刷新群排名信息
|
|
|
|
|
* @param e
|
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
|
*/
|
2024-05-13 12:05:34 +00:00
|
|
|
|
export async function refreshRank (e) {
|
2023-06-03 12:31:13 +00:00
|
|
|
|
let groupId = e.group_id || ''
|
2022-11-15 20:07:21 +00:00
|
|
|
|
if (!groupId) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
2023-02-12 15:39:46 +00:00
|
|
|
|
if (!e.isMaster && !this.e.member?.is_admin) {
|
|
|
|
|
e.reply('只有主人及群管理员可刷新排名...')
|
2022-11-15 20:07:21 +00:00
|
|
|
|
return true
|
|
|
|
|
}
|
2022-11-16 14:11:04 +00:00
|
|
|
|
e.reply('面板数据刷新中,等待时间可能较长,请耐心等待...')
|
2023-05-30 19:16:44 +00:00
|
|
|
|
let game = e.isSr ? 'sr' : 'gs'
|
2024-01-27 21:59:31 +00:00
|
|
|
|
await ProfileRank.resetRank({ groupId, game })
|
2023-06-03 12:31:13 +00:00
|
|
|
|
let uidMap = await ProfileRank.getUserUidMap(e, game)
|
2022-11-15 20:07:21 +00:00
|
|
|
|
let count = 0
|
2023-06-03 12:31:13 +00:00
|
|
|
|
for (let uid in uidMap) {
|
|
|
|
|
let { qq, type } = uidMap[uid]
|
|
|
|
|
let player = new Player(uid, game)
|
|
|
|
|
let profiles = player.getProfiles()
|
|
|
|
|
// 刷新rankLimit
|
|
|
|
|
await ProfileRank.setUidInfo({ uid, profiles, qq, uidType: type })
|
|
|
|
|
let rank = await ProfileRank.create({ groupId, uid, qq })
|
|
|
|
|
for (let id in profiles) {
|
|
|
|
|
let profile = profiles[id]
|
|
|
|
|
if (!profile.hasData) {
|
|
|
|
|
continue
|
2022-11-15 20:25:07 +00:00
|
|
|
|
}
|
2023-06-03 12:31:13 +00:00
|
|
|
|
await rank.getRank(profile, true)
|
|
|
|
|
}
|
|
|
|
|
if (rank.allowRank) {
|
|
|
|
|
count++
|
2022-11-15 20:07:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
e.reply(`本群排名已刷新,共刷新${count}个UID数据...`)
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-13 12:05:34 +00:00
|
|
|
|
export async function manageRank (e) {
|
2023-01-17 18:40:17 +00:00
|
|
|
|
let groupId = e.group_id
|
|
|
|
|
if (!groupId) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
let isClose = /(关闭|禁用)/.test(e.msg)
|
2023-02-12 15:39:46 +00:00
|
|
|
|
if (!e.isMaster && !this.e.member?.is_admin) {
|
|
|
|
|
e.reply(`只有主人及群管理员可${isClose ? '禁用' : '启用'}排名...`)
|
2023-01-17 18:40:17 +00:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
await ProfileRank.setGroupStatus(groupId, isClose ? 1 : 0)
|
|
|
|
|
if (isClose) {
|
|
|
|
|
e.reply('当前群排名功能已禁用...')
|
|
|
|
|
} else {
|
|
|
|
|
e.reply('当前群排名功能已启用...\n如数据有问题可通过【#刷新排名】命令来刷新当前群内排名')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-13 12:05:34 +00:00
|
|
|
|
async function renderCharRankList ({ e, uids, char, mode, groupId }) {
|
2022-11-10 20:56:15 +00:00
|
|
|
|
let list = []
|
|
|
|
|
for (let ds of uids) {
|
2022-11-17 18:25:32 +00:00
|
|
|
|
let uid = ds.uid || ds.value
|
2023-09-15 00:13:11 +00:00
|
|
|
|
let player = Player.create(uid, e.isSr ? 'sr' : 'gs')
|
2023-02-08 20:55:54 +00:00
|
|
|
|
let avatar = player.getAvatar(ds.charId || char.id)
|
2023-02-12 21:18:06 +00:00
|
|
|
|
if (!avatar) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2023-02-08 20:55:54 +00:00
|
|
|
|
let profile = avatar.getProfile()
|
2022-11-17 18:25:32 +00:00
|
|
|
|
|
2022-11-10 20:56:15 +00:00
|
|
|
|
if (profile) {
|
2022-11-12 21:35:46 +00:00
|
|
|
|
let profileRank = await ProfileRank.create({ groupId, uid })
|
|
|
|
|
let data = await profileRank.getRank(profile, true)
|
|
|
|
|
let mark = data?.mark?.data
|
2022-11-11 21:57:13 +00:00
|
|
|
|
let tmp = {
|
2022-11-10 20:56:15 +00:00
|
|
|
|
uid,
|
2022-11-17 18:55:06 +00:00
|
|
|
|
isMax: !char,
|
2022-11-11 21:57:13 +00:00
|
|
|
|
...avatar.getData('id,star,name,sName,level,fetter,cons,weapon,elem,talent,artisSet,imgs'),
|
2023-03-27 19:42:50 +00:00
|
|
|
|
artisMark: Data.getData(mark, 'mark,markClass,valid,crit')
|
2022-11-11 21:57:13 +00:00
|
|
|
|
}
|
2022-11-12 21:35:46 +00:00
|
|
|
|
let dmg = data?.dmg?.data
|
2022-11-11 21:57:13 +00:00
|
|
|
|
if (dmg && dmg.avg) {
|
2022-11-12 13:29:53 +00:00
|
|
|
|
let title = dmg.title
|
|
|
|
|
// 稍微缩短下title
|
|
|
|
|
if (title.length > 10) {
|
|
|
|
|
title = title.replace(/[ ·]*/g, '')
|
|
|
|
|
}
|
|
|
|
|
title = title.length > 10 ? title.replace(/伤害$/, '') : title
|
2024-03-01 14:09:34 +00:00
|
|
|
|
let tmpAvg = dmg.type !== 'text' ? Format.comma(dmg.avg, 1) : dmg.avg
|
2022-11-11 21:57:13 +00:00
|
|
|
|
tmp.dmg = {
|
2024-01-27 21:59:31 +00:00
|
|
|
|
title,
|
2024-03-01 14:09:34 +00:00
|
|
|
|
avg: tmpAvg,
|
|
|
|
|
rank: data.dmg.rank
|
2022-11-11 21:57:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-15 20:58:19 +00:00
|
|
|
|
if (uid) {
|
|
|
|
|
let userInfo = await ProfileRank.getUidInfo(uid)
|
2023-07-06 01:03:06 +00:00
|
|
|
|
try {
|
|
|
|
|
if (userInfo?.qq && e?.group?.pickMember) {
|
|
|
|
|
let member = e.group.pickMember(userInfo.qq)
|
|
|
|
|
if (member?.getAvatarUrl) {
|
|
|
|
|
let img = await member.getAvatarUrl()
|
|
|
|
|
if (img) {
|
|
|
|
|
tmp.qqFace = img
|
|
|
|
|
}
|
2023-06-27 04:07:12 +00:00
|
|
|
|
}
|
2022-11-15 20:58:19 +00:00
|
|
|
|
}
|
2023-07-06 01:03:06 +00:00
|
|
|
|
} catch (e) {
|
|
|
|
|
// console.log(e)
|
2022-11-15 20:58:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-27 20:02:49 +00:00
|
|
|
|
|
|
|
|
|
if (mode === 'crit') {
|
|
|
|
|
tmp._mark = mark?._crit * 6.6044 || 0
|
|
|
|
|
} else if (mode === 'valid') {
|
2023-03-27 19:42:50 +00:00
|
|
|
|
tmp._mark = mark?._valid || 0
|
2023-03-27 20:02:49 +00:00
|
|
|
|
} else {
|
2023-03-27 19:42:50 +00:00
|
|
|
|
tmp._mark = mark?._mark || 0
|
|
|
|
|
}
|
|
|
|
|
tmp._formatmark = Format.comma(tmp._mark, 1)
|
2024-03-08 03:03:50 +00:00
|
|
|
|
tmp._dmg = (0 - tmp.dmg?.rank) || 0
|
2022-11-17 19:40:32 +00:00
|
|
|
|
tmp._star = 5 - tmp.star
|
2022-11-11 21:57:13 +00:00
|
|
|
|
list.push(tmp)
|
2022-11-10 20:56:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-17 18:25:32 +00:00
|
|
|
|
let title
|
|
|
|
|
if (char) {
|
2023-09-15 00:13:11 +00:00
|
|
|
|
let modeTitleMap = {}
|
|
|
|
|
if (e.isSr) {
|
|
|
|
|
modeTitleMap = {
|
|
|
|
|
dmg: '',
|
|
|
|
|
mark: '遗器评分',
|
|
|
|
|
crit: '双爆副词条',
|
|
|
|
|
valid: '加权有效词条'
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
modeTitleMap = {
|
|
|
|
|
dmg: '',
|
|
|
|
|
mark: '圣遗物评分',
|
|
|
|
|
crit: '双爆副词条',
|
|
|
|
|
valid: '加权有效词条'
|
|
|
|
|
}
|
2023-03-27 19:42:50 +00:00
|
|
|
|
}
|
2024-05-13 12:05:34 +00:00
|
|
|
|
|
|
|
|
|
// 特殊处理开拓者的情况
|
|
|
|
|
let titleName = {
|
|
|
|
|
穹·毁灭: '开拓者·毁灭',
|
|
|
|
|
星·毁灭: '开拓者·毁灭',
|
|
|
|
|
穹·存护: '开拓者·存护',
|
|
|
|
|
星·存护: '开拓者·存护',
|
|
|
|
|
穹·同谐: '开拓者·同谐',
|
|
|
|
|
星·同谐: '开拓者·同谐'
|
|
|
|
|
}
|
|
|
|
|
if (titleName[char.name]) {
|
|
|
|
|
title = `${e.isSr ? '*' : '#'}${titleName[char.name]}${modeTitleMap[mode]}排行`
|
|
|
|
|
} else {
|
|
|
|
|
title = `${e.isSr ? '*' : '#'}${char.name}${modeTitleMap[mode]}排行`
|
|
|
|
|
}
|
2023-03-27 19:42:50 +00:00
|
|
|
|
list = lodash.sortBy(list, mode === 'dmg' ? '_dmg' : '_mark').reverse()
|
2022-11-17 18:25:32 +00:00
|
|
|
|
} else {
|
2023-09-15 00:13:11 +00:00
|
|
|
|
title = `${e.isSr ? '*' : '#'}${mode === 'mark' ? '最高分' : '最强'}排行`
|
2022-11-17 19:40:32 +00:00
|
|
|
|
list = lodash.sortBy(list, ['uid', '_star', 'id'])
|
2022-11-17 18:25:32 +00:00
|
|
|
|
}
|
2022-11-17 18:55:06 +00:00
|
|
|
|
|
2022-11-12 13:29:53 +00:00
|
|
|
|
const rankCfg = await ProfileRank.getGroupCfg(groupId)
|
2022-11-10 20:56:15 +00:00
|
|
|
|
// 渲染图像
|
2024-02-04 01:27:34 +00:00
|
|
|
|
return e.reply([await Common.render('character/rank-profile-list', {
|
2022-11-10 20:56:15 +00:00
|
|
|
|
save_id: char.id,
|
2023-09-15 00:13:11 +00:00
|
|
|
|
game: e.isSr ? 'sr' : 'gs',
|
2022-11-10 20:56:15 +00:00
|
|
|
|
list,
|
2022-11-11 21:57:13 +00:00
|
|
|
|
title,
|
2022-11-10 20:56:15 +00:00
|
|
|
|
elem: char.elem,
|
|
|
|
|
bodyClass: `char-${char.name}`,
|
2022-11-12 13:29:53 +00:00
|
|
|
|
rankCfg,
|
2024-05-17 09:42:05 +00:00
|
|
|
|
mode,
|
|
|
|
|
pageGotoParams: { waitUntil: 'networkidle2' }
|
2024-05-13 12:05:34 +00:00
|
|
|
|
}, { e, scale: 1.4, retType: 'base64' }), new Button(e).profile(char)])
|
2022-11-10 20:56:15 +00:00
|
|
|
|
}
|