2022-06-25 23:45:43 +00:00
|
|
|
/*
|
|
|
|
* 面板公共方法及处理
|
|
|
|
* */
|
2023-03-07 17:52:11 +00:00
|
|
|
import { Version } from '#miao'
|
2024-02-04 01:27:34 +00:00
|
|
|
import { Button, Character, MysApi, Player } from '#miao.models'
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 获取面板查询的 目标uid
|
|
|
|
* */
|
2023-02-09 16:57:25 +00:00
|
|
|
const _getTargetUid = async function (e) {
|
2024-02-04 02:04:27 +00:00
|
|
|
let uidReg = /([1-9]|18)[0-9]{8}/
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
|
|
if (e.uid && uidReg.test(e.uid)) {
|
2022-07-23 20:32:10 +00:00
|
|
|
return e.uid
|
2022-06-25 23:45:43 +00:00
|
|
|
}
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
let uidRet = uidReg.exec(e.msg)
|
2022-06-25 23:45:43 +00:00
|
|
|
if (uidRet) {
|
|
|
|
return uidRet[0]
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
let uid = false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
|
|
try {
|
2022-12-27 20:01:22 +00:00
|
|
|
let user = await MysApi.initUser(e)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
2022-12-27 20:01:22 +00:00
|
|
|
if (!user || !user.uid) {
|
2022-07-23 20:32:10 +00:00
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
}
|
2022-12-27 20:01:22 +00:00
|
|
|
uid = user.uid
|
2023-02-13 19:47:22 +00:00
|
|
|
if ((!uid || !uidReg.test(uid)) && !e._replyNeedUid) {
|
2024-02-04 01:27:34 +00:00
|
|
|
e.reply(['请先发送【#绑定+你的UID】来绑定查询目标\n星铁请使用【#星铁绑定+UID】', new Button(e).bindUid()])
|
2023-03-21 19:03:01 +00:00
|
|
|
e._replyNeedUid = true
|
2022-07-23 20:32:10 +00:00
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
}
|
|
|
|
} catch (err) {
|
2022-07-23 20:32:10 +00:00
|
|
|
console.log(err)
|
2022-06-25 23:45:43 +00:00
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
return uid || false
|
2022-06-25 23:45:43 +00:00
|
|
|
}
|
|
|
|
|
2024-02-04 02:04:27 +00:00
|
|
|
export async function getTargetUid(e) {
|
2023-02-09 16:57:25 +00:00
|
|
|
let uid = await _getTargetUid(e)
|
|
|
|
if (uid) {
|
|
|
|
e.uid = uid
|
|
|
|
}
|
|
|
|
return uid
|
|
|
|
}
|
|
|
|
|
2024-02-04 02:04:27 +00:00
|
|
|
export async function getProfileRefresh(e, avatar) {
|
2022-07-23 20:32:10 +00:00
|
|
|
let char = Character.get(avatar)
|
2022-06-27 20:46:49 +00:00
|
|
|
if (!char) {
|
2023-02-13 19:47:22 +00:00
|
|
|
return false
|
2022-06-27 20:46:49 +00:00
|
|
|
}
|
|
|
|
|
2023-02-09 16:57:25 +00:00
|
|
|
let player = Player.create(e)
|
|
|
|
let profile = player.getProfile(char.id)
|
2022-08-24 01:07:06 +00:00
|
|
|
if (!profile || !profile.hasData) {
|
2023-02-13 19:47:22 +00:00
|
|
|
logger.mark(`本地无UID:${player.uid}的${char.name}面板数据,尝试自动请求...`)
|
|
|
|
await player.refresh({ profile: true })
|
|
|
|
profile = player.getProfile(char.id)
|
2022-06-25 23:45:43 +00:00
|
|
|
}
|
2023-02-13 19:47:22 +00:00
|
|
|
if (!profile || !profile.hasData) {
|
2023-02-17 20:42:05 +00:00
|
|
|
if (!e._isReplyed) {
|
2024-02-04 01:27:34 +00:00
|
|
|
e.reply([`请确认${char.name}已展示在【游戏内】的角色展柜中,并打开了“显示角色详情”。然后请使用 #更新面板\n命令来获取${char.name}的面板详情`, new Button(e).profileList(player.uid), new Button(e).profile(char, player.uid)])
|
2023-02-17 20:42:05 +00:00
|
|
|
}
|
2023-02-13 19:47:22 +00:00
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
}
|
2023-02-13 19:47:22 +00:00
|
|
|
return profile
|
2022-06-25 23:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 面板帮助
|
|
|
|
* */
|
2024-02-04 02:04:27 +00:00
|
|
|
export async function profileHelp(e) {
|
2022-06-25 23:45:43 +00:00
|
|
|
e.reply(segment.image(`file://${process.cwd()}/plugins/miao-plugin/resources/character/imgs/help.jpg`))
|
2022-07-23 20:32:10 +00:00
|
|
|
return true
|
|
|
|
}
|