2022-07-27 18:36:49 +00:00
|
|
|
import lodash from 'lodash'
|
2023-02-09 16:57:25 +00:00
|
|
|
import MiaoData from './MiaoData.js'
|
2023-03-07 17:52:11 +00:00
|
|
|
import { Data } from '#miao'
|
2022-06-14 22:07:24 +00:00
|
|
|
|
2023-02-09 16:57:25 +00:00
|
|
|
export default {
|
2022-07-27 18:36:49 +00:00
|
|
|
key: 'miao',
|
2022-10-21 14:48:19 +00:00
|
|
|
name: '喵喵Api',
|
2022-08-20 23:40:32 +00:00
|
|
|
cfgKey: 'miaoApi',
|
2023-02-23 19:23:57 +00:00
|
|
|
async request (api) {
|
|
|
|
api = this.getCfg('api') || api
|
|
|
|
return { api }
|
|
|
|
},
|
2023-05-19 18:50:39 +00:00
|
|
|
async response (data, req, game = 'gs') {
|
2022-08-20 23:40:32 +00:00
|
|
|
if (data.status !== 0) {
|
|
|
|
return req.err(data.msg || 'error', 60)
|
2022-06-14 22:07:24 +00:00
|
|
|
}
|
2023-05-19 18:50:39 +00:00
|
|
|
if (game === 'sr') {
|
|
|
|
return data.data
|
|
|
|
}
|
2023-02-19 17:08:05 +00:00
|
|
|
if (data.version === 2) {
|
|
|
|
data = data.data || {}
|
|
|
|
if (!data.avatars || data.avatars.length === 0) {
|
|
|
|
return req.err('empty', 5 * 60)
|
|
|
|
}
|
|
|
|
data.version = 2
|
|
|
|
return data
|
|
|
|
} else {
|
2023-05-19 18:50:39 +00:00
|
|
|
return req.err('empty', 5 * 60)
|
2022-08-16 20:04:12 +00:00
|
|
|
}
|
2022-06-14 22:07:24 +00:00
|
|
|
},
|
|
|
|
|
2023-02-08 20:55:54 +00:00
|
|
|
updatePlayer (player, data) {
|
2023-05-19 18:50:39 +00:00
|
|
|
player.setBasicData(data)
|
|
|
|
lodash.forEach(data.avatars, (avatar) => {
|
|
|
|
let ret = MiaoData.setAvatar(player, avatar)
|
|
|
|
if (ret) {
|
|
|
|
player._update.push(ret.id)
|
|
|
|
}
|
|
|
|
})
|
2022-08-20 23:40:32 +00:00
|
|
|
},
|
2022-06-14 22:07:24 +00:00
|
|
|
|
2022-08-20 23:40:32 +00:00
|
|
|
// 获取冷却时间
|
|
|
|
cdTime (data = {}) {
|
|
|
|
if (data.cacheExpireAt) {
|
|
|
|
let exp = Math.max(0, Math.round(data.cacheExpireAt - (new Date() / 1000)))
|
|
|
|
return Math.max(60, exp)
|
2022-08-18 10:13:42 +00:00
|
|
|
}
|
2022-08-20 23:40:32 +00:00
|
|
|
return 60
|
2022-08-18 10:13:42 +00:00
|
|
|
}
|
2023-02-09 16:57:25 +00:00
|
|
|
}
|