适配亚服新UID (#706)

This commit is contained in:
Ca(HCO₃)₂ 2024-02-04 09:02:58 +08:00 committed by GitHub
parent 3e3d976885
commit 942cac4fb2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 69 additions and 62 deletions

View File

@ -18,13 +18,13 @@ app.reg({
name: '面板角色列表', name: '面板角色列表',
desc: '查看当前已获取面板数据的角色列表', desc: '查看当前已获取面板数据的角色列表',
fn: ProfileList.render, fn: ProfileList.render,
rule: /^#(星铁|原神)?(面板角色|角色面板|面板)(列表)?\s*(\d{9})?$/ rule: /^#(星铁|原神)?(面板角色|角色面板|面板)(列表)?\s*(\d{9,10})?$/
}, },
profileDetail: { profileDetail: {
name: '角色面板', name: '角色面板',
fn: ProfileDetail.detail, fn: ProfileDetail.detail,
rule: /^#*([^#]+)\s*(详细|详情|面板|面版|圣遗物|武器[1-7]?|伤害([1-9]+\d*)?)\s*(\d{9})*(.*[换变改].*)?$/ rule: /^#*([^#]+)\s*(详细|详情|面板|面版|圣遗物|武器[1-7]?|伤害([1-9]+\d*)?)\s*(\d{9,10})*(.*[换变改].*)?$/
}, },
profileChange: { profileChange: {
@ -66,7 +66,7 @@ app.reg({
artisList: { artisList: {
name: '面板圣遗物列表', name: '面板圣遗物列表',
fn: profileArtisList, fn: profileArtisList,
rule: /^#圣遗物列表\s*(\d{9})?$/ rule: /^#圣遗物列表\s*(\d{9,10})?$/
}, },
profileStat: { profileStat: {
@ -87,7 +87,7 @@ app.reg({
name: '角色查询', name: '角色查询',
fn: ProfileStat.avatarList, fn: ProfileStat.avatarList,
rule: /^#喵喵(角色|查询)[ |0-9]*$/, rule: /^#喵喵(角色|查询)[ |0-9]*$/,
yzRule: /^(#(五|四|5|4|星)*(角色|查询|查询角色|角色查询|人物)[ |0-9]*$)|(^(#*uid|#*UID)\+*[1|2|5-9][0-9]{8}$)|(^#[\+|]*[1|2|5-9][0-9]{8})/, yzRule: /^(#(五|四|5|4|星)*(角色|查询|查询角色|角色查询|人物)[ |0-9]*$)|(^(#*uid|#*UID)\+*([1-9]|18)[0-9]{8}$)|(^#[\+|]*([1-9]|18)[0-9]{8})/,
yzCheck: () => Cfg.get('avatarList', false) yzCheck: () => Cfg.get('avatarList', false)
}, },
@ -114,7 +114,7 @@ app.reg({
name: '面板更新', name: '面板更新',
describe: '【#角色】 获取游戏橱窗详情数据', describe: '【#角色】 获取游戏橱窗详情数据',
fn: ProfileList.refresh, fn: ProfileList.refresh,
rule: /^#(星铁|原神)?(全部面板更新|更新全部面板|获取游戏角色详情|更新面板|面板更新)\s*(\d{9})?$/ rule: /^#(星铁|原神)?(全部面板更新|更新全部面板|获取游戏角色详情|更新面板|面板更新)\s*(\d{9,10})?$/
}, },
uploadImg: { uploadImg: {
@ -142,13 +142,13 @@ app.reg({
name: '删除面板', name: '删除面板',
describe: '【#角色】 删除游戏橱窗详情数据', describe: '【#角色】 删除游戏橱窗详情数据',
fn: ProfileList.del, fn: ProfileList.del,
rule: /^#(删除全部面板|删除面板|删除面板数据)\s*(\d{9})?$/ rule: /^#(删除全部面板|删除面板|删除面板数据)\s*(\d{9,10})?$/
}, },
profileReload: { profileReload: {
name: '重新加载面板', name: '重新加载面板',
fn: ProfileList.reload, fn: ProfileList.reload,
rule: /^#(星铁|原神)?(加载|重新加载|重载)面板\s*(\d{9})?$/ rule: /^#(星铁|原神)?(加载|重新加载|重载)面板\s*(\d{9,10})?$/
} }
}) })

View File

@ -20,12 +20,12 @@ const ProfileChange = {
* @param msg * @param msg
* @returns {{}} * @returns {{}}
*/ */
matchMsg (msg) { matchMsg(msg) {
if (!/(变|改|换)/.test(msg)) { if (!/(变|改|换)/.test(msg)) {
return false return false
} }
msg = msg.toLowerCase().replace(/uid ?:? ?/, '').replace('', '') msg = msg.toLowerCase().replace(/uid ?:? ?/, '').replace('', '')
let regRet = /^#*(\d{9})?(.+?)(详细|详情|面板|面版|圣遗物|伤害[1-7]?)?\s*(\d{9})?[变换改](.+)/.exec(msg) let regRet = /^#*(\d{9,10})?(.+?)(详细|详情|面板|面版|圣遗物|伤害[1-7]?)?\s*(\d{9,10})?[变换改](.+)/.exec(msg)
if (!regRet || !regRet[2]) { if (!regRet || !regRet[2]) {
return false return false
} }
@ -39,31 +39,31 @@ const ProfileChange = {
const isGs = game === 'gs' const isGs = game === 'gs'
const keyMap = isGs const keyMap = isGs
? { ? {
artis: '圣遗物', artis: '圣遗物',
arti1: '花,生之花', arti1: '花,生之花',
arti2: '毛,羽,羽毛,死之羽', arti2: '毛,羽,羽毛,死之羽',
arti3: '沙,沙漏,表,时之沙', arti3: '沙,沙漏,表,时之沙',
arti4: '杯,杯子,空之杯', arti4: '杯,杯子,空之杯',
arti5: '头,冠,理之冠,礼冠,帽子,帽', arti5: '头,冠,理之冠,礼冠,帽子,帽',
weapon: '武器' weapon: '武器'
} }
: { : {
artis: '圣遗物,遗器', artis: '圣遗物,遗器',
arti1: '头,帽子,头部', arti1: '头,帽子,头部',
arti2: '手,手套,手部', arti2: '手,手套,手部',
arti3: '衣,衣服,甲,躯干,', arti3: '衣,衣服,甲,躯干,',
arti4: '鞋,靴,鞋子,靴子,脚,脚部', arti4: '鞋,靴,鞋子,靴子,脚,脚部',
arti5: '球,位面球', arti5: '球,位面球',
arti6: '绳,线,链接绳,连接绳', arti6: '绳,线,链接绳,连接绳',
weapon: '武器,光锥' weapon: '武器,光锥'
} }
let keyTitleMap = {} let keyTitleMap = {}
lodash.forEach(keyMap, (val, key) => { lodash.forEach(keyMap, (val, key) => {
lodash.forEach(val.split(','), (v) => { lodash.forEach(val.split(','), (v) => {
keyTitleMap[v] = key keyTitleMap[v] = key
}) })
}) })
const keyReg = new RegExp(`^(\\d{9})?\\s*(.+?)\\s*(\\d{9})?\\s*((?:${lodash.keys(keyTitleMap).join('|')}|\\+)+)$`) const keyReg = new RegExp(`^(\\d{9,10})?\\s*(.+?)\\s*(\\d{9,10})?\\s*((?:${lodash.keys(keyTitleMap).join('|')}|\\+)+)$`)
ret.char = char.id ret.char = char.id
ret.mode = regRet[3] === '换' ? '面板' : regRet[3] ret.mode = regRet[3] === '换' ? '面板' : regRet[3]
@ -197,7 +197,7 @@ const ProfileChange = {
* @param game * @param game
* @returns {Avatar|boolean} * @returns {Avatar|boolean}
*/ */
getProfile (uid, charid, ds, game = 'gs') { getProfile(uid, charid, ds, game = 'gs') {
if (!charid) { if (!charid) {
return false return false
} }

View File

@ -8,7 +8,7 @@ import { Character, MysApi, Player } from '#miao.models'
* 获取面板查询的 目标uid * 获取面板查询的 目标uid
* */ * */
const _getTargetUid = async function (e) { const _getTargetUid = async function (e) {
let uidReg = /[1-9][0-9]{8}/ let uidReg = /([1-9]|18)[0-9]{8}/
if (e.uid && uidReg.test(e.uid)) { if (e.uid && uidReg.test(e.uid)) {
return e.uid return e.uid
@ -38,7 +38,7 @@ const _getTargetUid = async function (e) {
return uid || false return uid || false
} }
export async function getTargetUid (e) { export async function getTargetUid(e) {
let uid = await _getTargetUid(e) let uid = await _getTargetUid(e)
if (uid) { if (uid) {
e.uid = uid e.uid = uid
@ -46,7 +46,7 @@ export async function getTargetUid (e) {
return uid return uid
} }
export async function getProfileRefresh (e, avatar) { export async function getProfileRefresh(e, avatar) {
let char = Character.get(avatar) let char = Character.get(avatar)
if (!char) { if (!char) {
return false return false
@ -71,7 +71,7 @@ export async function getProfileRefresh (e, avatar) {
/* /*
* 面板帮助 * 面板帮助
* */ * */
export async function profileHelp (e) { export async function profileHelp(e) {
e.reply(segment.image(`file://${process.cwd()}/plugins/miao-plugin/resources/character/imgs/help.jpg`)) e.reply(segment.image(`file://${process.cwd()}/plugins/miao-plugin/resources/character/imgs/help.jpg`))
return true return true
} }

View File

@ -9,7 +9,7 @@ const ProfileList = {
* @param e * @param e
* @returns {Promise<boolean|*>} * @returns {Promise<boolean|*>}
*/ */
async refresh (e) { async refresh(e) {
let uid = await getTargetUid(e) let uid = await getTargetUid(e)
if (!uid) { if (!uid) {
e._replyNeedUid || e.reply('请先发送【#绑定+你的UID】来绑定查询目标\n星铁请使用【#星铁绑定+UID】') e._replyNeedUid || e.reply('请先发送【#绑定+你的UID】来绑定查询目标\n星铁请使用【#星铁绑定+UID】')
@ -48,7 +48,7 @@ const ProfileList = {
* @returns {Promise<boolean|*>} * @returns {Promise<boolean|*>}
*/ */
async render (e) { async render(e) {
let uid = await getTargetUid(e) let uid = await getTargetUid(e)
if (!uid) { if (!uid) {
e._replyNeedUid || e.reply('请先发送【#绑定+你的UID】来绑定查询目标\n星铁请使用【#星铁绑定+UID】') e._replyNeedUid || e.reply('请先发送【#绑定+你的UID】来绑定查询目标\n星铁请使用【#星铁绑定+UID】')
@ -149,8 +149,8 @@ const ProfileList = {
* @param e * @param e
* @returns {Promise<boolean>} * @returns {Promise<boolean>}
*/ */
async del (e) { async del(e) {
let ret = /^#(删除全部面板|删除面板|删除面板数据)\s*(\d{9})?$/.exec(e.msg) let ret = /^#(删除全部面板|删除面板|删除面板数据)\s*(\d{9,10})?$/.exec(e.msg)
let uid = await getTargetUid(e) let uid = await getTargetUid(e)
if (!uid) { if (!uid) {
return true return true
@ -179,7 +179,7 @@ const ProfileList = {
return true return true
}, },
async reload (e) { async reload(e) {
let uid = await getTargetUid(e) let uid = await getTargetUid(e)
if (!uid) { if (!uid) {
return true return true

View File

@ -3,7 +3,7 @@ import moment from 'moment'
import { Cfg, Common, Data, Version } from '#miao' import { Cfg, Common, Data, Version } from '#miao'
export default class ProfileRank { export default class ProfileRank {
constructor (data) { constructor(data) {
this.groupId = data.groupId || data.groupId || '' this.groupId = data.groupId || data.groupId || ''
if (!this.groupId || this.groupId === 'undefined') { if (!this.groupId || this.groupId === 'undefined') {
return false return false
@ -13,7 +13,7 @@ export default class ProfileRank {
this.allowRank = false this.allowRank = false
} }
static async create (data) { static async create(data) {
let rank = new ProfileRank(data) let rank = new ProfileRank(data)
rank.allowRank = await ProfileRank.checkRankLimit(rank.uid) rank.allowRank = await ProfileRank.checkRankLimit(rank.uid)
return rank return rank
@ -26,12 +26,12 @@ export default class ProfileRank {
* @param type * @param type
* @returns {Promise<string|boolean>} * @returns {Promise<string|boolean>}
*/ */
static async getGroupMaxUid (groupId, charId, type = 'mark') { static async getGroupMaxUid(groupId, charId, type = 'mark') {
let uids = await redis.zRange(`miao:rank:${groupId}:${type}:${charId}`, -1, -1) let uids = await redis.zRange(`miao:rank:${groupId}:${type}:${charId}`, -1, -1)
return uids ? uids[0] : false return uids ? uids[0] : false
} }
static async getGroupMaxUidList (groupId, type = 'mark') { static async getGroupMaxUidList(groupId, type = 'mark') {
let keys = await redis.keys(`miao:rank:${groupId}:${type}:*`) let keys = await redis.keys(`miao:rank:${groupId}:${type}:*`)
let ret = [] let ret = []
for (let key of keys) { for (let key of keys) {
@ -57,7 +57,7 @@ export default class ProfileRank {
* @param type * @param type
* @returns {Promise<ConvertArgumentType<ZMember, string>[]|boolean>} * @returns {Promise<ConvertArgumentType<ZMember, string>[]|boolean>}
*/ */
static async getGroupUidList (groupId, charId, type = 'mark') { static async getGroupUidList(groupId, charId, type = 'mark') {
let number = Cfg.get('rankNumber', 15) let number = Cfg.get('rankNumber', 15)
let uids = await redis.zRangeWithScores(`miao:rank:${groupId}:${type}:${charId}`, -`${number}`, -1) let uids = await redis.zRangeWithScores(`miao:rank:${groupId}:${type}:${charId}`, -`${number}`, -1)
return uids ? uids.reverse() : false return uids ? uids.reverse() : false
@ -69,7 +69,7 @@ export default class ProfileRank {
* @param charId * @param charId
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
static async resetRank (groupId, charId = '', game = 'gs') { static async resetRank(groupId, charId = '', game = 'gs') {
let keys = await redis.keys(`miao:rank:${groupId}:*`) let keys = await redis.keys(`miao:rank:${groupId}:*`)
for (let key of keys) { for (let key of keys) {
let charRet = game === 'gs' ? /^miao:rank:\d+:(?:mark|dmg|crit|valid):(\d{8})$/.exec(key) : /^miao:rank:\d+:(?:mark|dmg|crit|valid):(\d{4})$/.exec(key) let charRet = game === 'gs' ? /^miao:rank:\d+:(?:mark|dmg|crit|valid):(\d{8})$/.exec(key) : /^miao:rank:\d+:(?:mark|dmg|crit|valid):(\d{4})$/.exec(key)
@ -84,7 +84,7 @@ export default class ProfileRank {
} }
} }
static async getGroupCfg (groupId) { static async getGroupCfg(groupId) {
const rankLimitTxt = { const rankLimitTxt = {
1: '无限制', 1: '无限制',
2: '绑定有CK的用户', 2: '绑定有CK的用户',
@ -110,7 +110,7 @@ export default class ProfileRank {
* @param status0开启1关闭 * @param status0开启1关闭
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
static async setGroupStatus (groupId, status = 0) { static async setGroupStatus(groupId, status = 0) {
let cfg = await Data.redisGet(`miao:rank:${groupId}:cfg`, { let cfg = await Data.redisGet(`miao:rank:${groupId}:cfg`, {
timestamp: (new Date()) * 1, timestamp: (new Date()) * 1,
status status
@ -119,7 +119,7 @@ export default class ProfileRank {
await Data.redisSet(`miao:rank:${groupId}:cfg`, cfg, 3600 * 24 * 365) await Data.redisSet(`miao:rank:${groupId}:cfg`, cfg, 3600 * 24 * 365)
} }
static async setUidInfo ({ uid, qq, profiles, uidType = 'bind' }) { static async setUidInfo({ uid, qq, profiles, uidType = 'bind' }) {
if (!uid) { if (!uid) {
return false return false
} }
@ -165,10 +165,10 @@ export default class ProfileRank {
await redis.set(`miao:rank:uid-info:${uid}`, JSON.stringify(data), { EX: 3600 * 24 * 365 }) await redis.set(`miao:rank:uid-info:${uid}`, JSON.stringify(data), { EX: 3600 * 24 * 365 })
} }
static async delUidInfo (uid) { static async delUidInfo(uid) {
let keys = await redis.keys('miao:rank:*') let keys = await redis.keys('miao:rank:*')
uid = uid + '' uid = uid + ''
if (!/\d{9}/.test(uid)) { if (!/\d{9,10}/.test(uid)) {
return false return false
} }
for (let key of keys) { for (let key of keys) {
@ -179,7 +179,7 @@ export default class ProfileRank {
} }
} }
static async getUidInfo (uid) { static async getUidInfo(uid) {
try { try {
let data = await redis.get(`miao:rank:uid-info:${uid}`) let data = await redis.get(`miao:rank:uid-info:${uid}`)
return JSON.parse(data) return JSON.parse(data)
@ -188,7 +188,7 @@ export default class ProfileRank {
return false return false
} }
static async getUserUidMap (e, game = 'gs') { static async getUserUidMap(e, game = 'gs') {
let rn = e.runtime let rn = e.runtime
let groupMemMap = await e.group?.getMemberMap() || [] let groupMemMap = await e.group?.getMemberMap() || []
let users = {} let users = {}
@ -208,7 +208,7 @@ export default class ProfileRank {
let data = await Data.redisGet(key) let data = await Data.redisGet(key)
let { qq, uidType } = data let { qq, uidType } = data
if (!users[qq]) continue if (!users[qq]) continue
let uidRet = /miao:rank:uid-info:(\d{9})/.exec(key) let uidRet = /miao:rank:uid-info:(\d{9,10})/.exec(key)
if (qq && uidType && uidRet?.[1]) { if (qq && uidType && uidRet?.[1]) {
add(qq, uidRet[1], uidType === 'ck' ? 'ck' : 'bind') add(qq, uidRet[1], uidType === 'ck' ? 'ck' : 'bind')
} }
@ -257,7 +257,7 @@ export default class ProfileRank {
* @param uid * @param uid
* @returns {Promise<boolean>} * @returns {Promise<boolean>}
*/ */
static async checkRankLimit (uid) { static async checkRankLimit(uid) {
if (!uid) { if (!uid) {
return false return false
} }
@ -290,7 +290,7 @@ export default class ProfileRank {
} }
} }
key (profile, type) { key(profile, type) {
return `miao:rank:${this.groupId}:${type}:${profile.id}` return `miao:rank:${this.groupId}:${type}:${profile.id}`
} }
@ -300,7 +300,7 @@ export default class ProfileRank {
* @param force * @param force
* @returns {Promise<{}|boolean>} * @returns {Promise<{}|boolean>}
*/ */
async getRank (profile, force = false) { async getRank(profile, force = false) {
if (!profile || !this.groupId || !this.allowRank || !profile.hasData) { if (!profile || !this.groupId || !this.allowRank || !profile.hasData) {
return false return false
} }
@ -318,7 +318,7 @@ export default class ProfileRank {
return ret return ret
} }
async getTypeRank (profile, type, force) { async getTypeRank(profile, type, force) {
if (!profile || !profile.hasData || !type) { if (!profile || !profile.hasData || !type) {
return false return false
} }
@ -357,7 +357,7 @@ export default class ProfileRank {
} }
} }
async getTypeValue (profile, type) { async getTypeValue(profile, type) {
if (!profile || !profile.hasData) { if (!profile || !profile.hasData) {
return false return false
} }

View File

@ -26,14 +26,20 @@ const servs = {}
const Serv = { const Serv = {
// 根据UID获取 ProfileServ // 根据UID获取 ProfileServ
getServ (uid, game = 'gs') { getServ(uid, game = 'gs') {
let token = diyCfg?.miaoApi?.token let token = diyCfg?.miaoApi?.token
let qq = diyCfg?.miaoApi?.qq let qq = diyCfg?.miaoApi?.qq
let hasToken = !!(qq && token && token.length === 32 && !/^test/.test(token)) let hasToken = !!(qq && token && token.length === 32 && !/^test/.test(token))
let isGs = game === 'gs' let isGs = game === 'gs'
// 根据uid判断当前服务器类型。官服0 B服1 国际2 // 根据uid判断当前服务器类型。官服0 B服1 国际2
let servType = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 1, 6: 2, 7: 2, 8: 2, 9: 2 }[uid[0]] let uidPrefix = uid.toString()
if (uidPrefix.length == 10) {
uidPrefix = uidPrefix.slice(0, 2)
} else {
uidPrefix = uidPrefix.slice(0, 1)
}
let servType = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 1, 6: 2, 7: 2, 8: 2, 18: 2, 9: 2 }[uidPrefix]
// 获取原神、星铁对应服务选择的配置 // 获取原神、星铁对应服务选择的配置
let servCfg = (Cfg.get(isGs ? 'profileServer' : 'srProfileServer', '0') || '0').toString() let servCfg = (Cfg.get(isGs ? 'profileServer' : 'srProfileServer', '0') || '0').toString()
@ -66,7 +72,7 @@ const Serv = {
}, },
// 根据key获取ProfileServ // 根据key获取ProfileServ
serv (key) { serv(key) {
if (!servs[key]) { if (!servs[key]) {
servs[key] = new ProfileServ(apis[key]) servs[key] = new ProfileServ(apis[key])
} }
@ -74,7 +80,7 @@ const Serv = {
}, },
// 发起请求 // 发起请求
async req (e, player) { async req(e, player) {
let req = ProfileReq.create(e, player.game) let req = ProfileReq.create(e, player.game)
if (!req) { if (!req) {
return false return false

View File

@ -173,13 +173,14 @@ body, .container {
background: rgba(255, 255, 255, .5); background: rgba(255, 255, 255, .5);
height: 80px; height: 80px;
vertical-align: middle; vertical-align: middle;
margin: 15px 10px 0; margin: 15px 8px 0;
} }
} }
.abyss-team { .abyss-team {
display: flex; display: flex;
margin-right: -5px;
margin-left: -5px;
} }
.abyss-detail { .abyss-detail {