Merge pull request #654 from ikechan8370/master

feat: 新增两个星铁面板api及星铁面板服务的设置项
This commit is contained in:
Aluxes 2023-10-08 04:37:43 +08:00 committed by GitHub
commit c384ceeb9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 260 additions and 4 deletions

View File

@ -87,6 +87,14 @@ export const cfgSchema = {
input: (n) => /[0-4]{1,3}/.test(n) ? n : 0,
desc: '面板服务选择0:自动1:喵Api(需具备Token) 2:Enka-API 3:MiniGG-Api, 4:Hutao-Enka代理。如设置三位数字则为分服务器设置按顺序分别为 国服/B服/外服例如112代表国服B服Miao,国外Enka'
},
srProfileServer: {
title: '星铁面板服务',
key: '星铁面板服务',
type: 'num',
def: 0,
input: (n) => /[0-4]{1,3}/.test(n) ? n : 0,
desc: '星铁面板服务选择0:自动1:喵Api(需具备Token) 2:Mihomo 3:Avocado(鳄梨), 4:EnkaHSR。如设置三位数字则为分服务器设置按顺序分别为 国服/B服/外服例如114代表国服B服Miao,国外Enka'
},
costumeSplash: {
title: '使用自定义面板插图',
key: '面板图',

View File

@ -44,6 +44,21 @@ export const homoApi = {
}
}
export const avocadoApi = {
url: 'https://avocado.wiki/v1/raw/info',
userAgent: 'Miao-Plugin/3.1',
listApi: ({ url, uid, diyCfg }) => {
return `${url}/${uid}`
}
}
export const enkaHSRApi = {
url: 'https://enka.network/',
userAgent: 'Miao-Plugin/3.1',
listApi: ({ url, uid, diyCfg }) => {
return `${url}api/hsr/uid/${uid}/`
}
}
export const requestInterval = 3
export const isSys = true

112
models/player/AvocadoApi.js Normal file
View File

@ -0,0 +1,112 @@
import lodash from 'lodash'
import { Data } from '#miao'
import { Character } from '#miao.models'
/**
* 鳄梨
*/
export default {
id: 'avocado',
name: 'avocado.wiki',
cfgKey: 'avocadoApi',
// 处理请求参数
async request (api) {
let params = {
headers: { 'User-Agent': this.getCfg('userAgent') }
}
return { api, params }
},
// 处理服务返回
async response (data, req) {
if (!data.playerDetailInfo) {
return req.err('error', 60)
}
let ds = data.playerDetailInfo
let ac = ds.assistAvatar
let avatars = {}
if (ac && !lodash.isEmpty(ac)) {
avatars[ac.avatarId] = ac
}
lodash.forEach(ds.displayAvatars, (ds) => {
avatars[ds.avatarId] = ds
})
if (lodash.isEmpty(avatars)) {
return req.err('empty', 5 * 60)
}
ds.avatars = avatars
return ds
},
updatePlayer (player, data) {
try {
player.setBasicData(Data.getData(data, 'name:nickname,face:headIconID,level:level,word:level,sign:signature'))
lodash.forEach(data.avatars, (ds, id) => {
let ret = AvocadoData.setAvatar(player, ds)
if (ret) {
player._update.push(ds.avatarId)
}
})
} catch (e) {
console.log(e)
}
},
// 获取冷却时间
cdTime (data) {
return data.ttl || 60
}
}
const AvocadoData = {
setAvatar (player, data) {
let char = Character.get(data.avatarId)
if (!char) {
return false
}
let avatar = player.getAvatar(char.id, true)
let setData = {
level: data.level,
promote: data.promotion,
cons: data.rank || 0,
weapon: Data.getData(data.equipment, 'id:id,promote:promotion,level,affix:rank'),
...AvocadoData.getTalent(data.behaviorList, char),
artis: AvocadoData.getArtis(data.relics)
}
avatar.setAvatar(setData, 'avocado.wiki')
return avatar
},
getTalent (ds, char) {
let talent = {}
let trees = []
lodash.forEach(ds, (d) => {
let key = char.getTalentKey(d.id)
if (key || d.level > 1) {
talent[key || d.id] = d.level
} else {
trees.push(d.id)
}
})
return { talent, trees }
},
getArtis (artis) {
let ret = {}
lodash.forEach(artis, (ds) => {
let tmp = {
id: ds.id,
level: ds.level || 1,
mainId: ds.main_affix_id,
attrIds: []
}
lodash.forEach(ds.sub_affix_id, (s) => {
if (!s.id) {
return true
}
tmp.attrIds.push([s.id, s.cnt, s.step || 0].join(','))
})
ret[ds.type] = tmp
})
return ret
}
}

109
models/player/EnkaHSRApi.js Normal file
View File

@ -0,0 +1,109 @@
import lodash from 'lodash'
import { Data } from '#miao'
import { Character } from '#miao.models'
export default {
id: 'enkahsr',
name: 'EnkaHSR',
cfgKey: 'enkaHSRApi',
// 处理请求参数
async request (api) {
let params = {
headers: { 'User-Agent': this.getCfg('userAgent') }
}
return { api, params }
},
// 处理服务返回
async response (data, req) {
if (!data.detailInfo) {
return req.err('error', 60)
}
let ds = data.detailInfo
let ac = ds.assistAvatarDetail
let avatars = {}
if (ac && !lodash.isEmpty(ac)) {
avatars[ac.AvatarID] = ac
}
lodash.forEach(ds.avatarDetailList, (ds) => {
avatars[ds.avatarId] = ds
})
if (lodash.isEmpty(avatars)) {
return req.err('empty', 5 * 60)
}
ds.avatars = avatars
return ds
},
updatePlayer (player, data) {
try {
player.setBasicData(Data.getData(data, 'name:nickname,face:headIcon,level:level,word:level,sign:signature'))
lodash.forEach(data.avatars, (ds, id) => {
let ret = HomoData.setAvatar(player, ds)
if (ret) {
player._update.push(ds.avatarId)
}
})
} catch (e) {
console.log(e)
}
},
// 获取冷却时间
cdTime (data) {
return data.ttl || 60
}
}
const HomoData = {
setAvatar (player, data) {
let char = Character.get(data.avatarId)
if (!char) {
return false
}
let avatar = player.getAvatar(char.id, true)
let setData = {
level: data.level,
promote: data.promotion,
cons: data.rank || 0,
weapon: Data.getData(data.equipment, 'id:tid,promote:promotion,level,affix:rank'),
...HomoData.getTalent(data.skillTreeList, char),
artis: HomoData.getArtis(data.relicList)
}
avatar.setAvatar(setData, 'EnkaHSR')
return avatar
},
getTalent (ds, char) {
let talent = {}
let trees = []
lodash.forEach(ds, (d) => {
let key = char.getTalentKey(d.pointId)
if (key || d.Level > 1) {
talent[key || d.pointId] = d.level
} else {
trees.push(d.pointId)
}
})
return { talent, trees }
},
getArtis (artis) {
let ret = {}
lodash.forEach(artis, (ds) => {
let tmp = {
id: ds.tid,
level: ds.level || 1,
mainId: ds.mainAffixId,
attrIds: []
}
lodash.forEach(ds.subAffixList, (s) => {
if (!s.affixId) {
return true
}
tmp.attrIds.push([s.affixId, s.cnt, s.step || 0].join(','))
})
ret[ds.type] = tmp
})
return ret
}
}

View File

@ -9,6 +9,8 @@ import hutaoApi from './HutaoApi.js'
import homoApi from './HomoApi.js'
import lodash from 'lodash'
import avocadoApi from './AvocadoApi.js'
import enkaHSRApi from './EnkaHSRApi.js'
let { diyCfg } = await Data.importCfg('profile')
@ -21,7 +23,9 @@ const Profile = {
mgg: mggApi,
enka: enkaApi,
hutao: hutaoApi,
homo: homoApi
homo: homoApi,
avocado: avocadoApi,
enkaHSR: enkaHSRApi
}[key])
}
return Profile.servs[key]
@ -41,15 +45,23 @@ const Profile = {
// 判断国服、B服、外服获取在配置中的idx
let servIdx = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 1, 6: 2, 7: 2, 8: 2, 9: 2 }[uid[0]]
// 获取对应服务选择的配置数字0自动1喵2Enka3Mgg, 4:Hutao
// 获取原神对应服务选择的配置数字0自动1喵2Enka3Mgg, 4:Hutao
let servCfg = Cfg.get('profileServer', '0').toString() || '0'
// 获取星穹铁道对应服务选择的配置数字0自动1喵2Mihomo3Avocado, 4EnkaHSR
let srServCfg = Cfg.get('srProfileServer', '0').toString() || '0'
servCfg = servCfg[servIdx] || servCfg[0] || '0'
if (game === 'sr') {
if ((servCfg === '0' || servCfg === '1') && hasToken) {
if ((srServCfg === '0' || srServCfg === '1') && hasToken) {
return Profile.serv('miao')
}
return Profile.serv('homo')
if (srServCfg === '4') {
return Profile.serv('enkaHSR')
} else if (srServCfg === '3') {
return Profile.serv('avocado')
} else {
return Profile.serv('homo')
}
}
if ((servCfg === '0' || servCfg === '1') && hasToken) {