mirror of
https://github.com/yoimiya-kokomi/miao-plugin.git
synced 2024-11-16 04:35:42 +00:00
6b11badb66
增加`#删除面板`命令,目前绑定CK用户使用,Bot主人可删除任意UID数据
87 lines
2.1 KiB
JavaScript
87 lines
2.1 KiB
JavaScript
import { ProfileReq, ProfileServ } from '../index.js'
|
|
import { Cfg, Data } from '../../components/index.js'
|
|
import MysAvatar from './MysAvatar.js'
|
|
|
|
import enkaCfg from './EnkaApi.js'
|
|
import MiaoApi from './MiaoApi.js'
|
|
|
|
let { diyCfg } = await Data.importCfg('profile')
|
|
|
|
const Profile = {
|
|
/**
|
|
* 根据UID分配请求服务器
|
|
* @param uid
|
|
* @returns {ProfileServ}
|
|
*/
|
|
getServ (uid) {
|
|
let token = diyCfg?.miaoApi?.token
|
|
let qq = diyCfg?.miaoApi?.qq
|
|
|
|
if (qq && token && token.length === 32 && !/^test/.test(token) && Cfg.get('profileServ') === 1) {
|
|
if (!Profile.Miao) {
|
|
Profile.Miao = new ProfileServ(MiaoApi)
|
|
}
|
|
return Profile.Miao
|
|
}
|
|
if (!Profile.Enka) {
|
|
Profile.Enka = new ProfileServ(enkaCfg)
|
|
}
|
|
return Profile.Enka
|
|
},
|
|
|
|
/**
|
|
* 更新面板数据
|
|
* @param player
|
|
* @param force
|
|
* @returns {Promise<boolean|number>}
|
|
*/
|
|
async refreshProfile (player, force = 2) {
|
|
if (!MysAvatar.needRefresh(player._profile, force, { 0: 24, 1: 2, 2: 0 })) {
|
|
return false
|
|
}
|
|
player._update = []
|
|
let { uid, e } = player
|
|
if (uid.toString().length !== 9 || !e) {
|
|
return false
|
|
}
|
|
let req = ProfileReq.create(e)
|
|
if (!req) {
|
|
return false
|
|
}
|
|
let serv = Profile.getServ(uid)
|
|
try {
|
|
await req.requestProfile(player, serv)
|
|
player._profile = new Date() * 1
|
|
player.save()
|
|
return player._update.length
|
|
} catch (err) {
|
|
if (!e._isReplyed) {
|
|
e.reply(`UID:${uid}更新面板失败,更新服务:${serv.name}`)
|
|
}
|
|
return false
|
|
}
|
|
},
|
|
|
|
isProfile (avatar) {
|
|
// 检查数据源
|
|
if (!avatar._source || !['enka', 'change', 'miao'].includes(avatar._source)) {
|
|
return false
|
|
}
|
|
// 检查武器及天赋
|
|
if (!avatar.weapon || !avatar.talent) {
|
|
return false
|
|
}
|
|
// 检查圣遗物词条是否完备
|
|
if (!avatar.artis || !avatar.artis.hasAttr) {
|
|
return false
|
|
}
|
|
// 检查旅行者
|
|
if (['空', '荧'].includes(avatar.name)) {
|
|
return !!avatar.elem
|
|
}
|
|
return true
|
|
}
|
|
}
|
|
|
|
export default Profile
|