2022-06-25 23:45:43 +00:00
|
|
|
|
/*
|
|
|
|
|
* 面板公共方法及处理
|
|
|
|
|
* */
|
2022-07-23 20:32:10 +00:00
|
|
|
|
import lodash from 'lodash'
|
|
|
|
|
import { segment } from 'oicq'
|
2022-08-18 10:13:42 +00:00
|
|
|
|
import { profileList } from './profile-list.js'
|
|
|
|
|
import { Profile, Version } from '../../components/index.js'
|
|
|
|
|
import { Character } from '../../models/index.js'
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 获取面板查询的 目标uid
|
|
|
|
|
* */
|
2022-07-23 20:32:10 +00:00
|
|
|
|
export async function getTargetUid (e) {
|
|
|
|
|
let uidReg = /[1-9][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
|
|
|
|
let getUid = async function (qq) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let nCookie = global.NoteCookie || false
|
|
|
|
|
if (nCookie && nCookie[qq]) {
|
|
|
|
|
let nc = nCookie[qq]
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (nc.uid && uidReg.test(nc.uid)) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return nc.uid
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
uid = await redis.get(`genshin:id-uid:${qq}`) || await redis.get(`genshin:uid:${qq}`)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (uid && uidReg.test(uid)) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return uid
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-18 10:13:42 +00:00
|
|
|
|
if (!Version.isV3) {
|
2022-07-27 18:36:49 +00:00
|
|
|
|
let botQQ = global.BotConfig ? global.BotConfig.account.qq : false
|
|
|
|
|
if (e.at && e.at !== botQQ) {
|
|
|
|
|
uid = await getUid(e.at)
|
|
|
|
|
if (uid) {
|
|
|
|
|
return uid
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uid = await getUid(e.user_id)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (uid) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return uid
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
let MysApi = await e.getMysApi({
|
2022-07-23 20:32:10 +00:00
|
|
|
|
auth: 'all',
|
|
|
|
|
targetType: 'all',
|
|
|
|
|
cookieType: 'all'
|
|
|
|
|
})
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
|
|
|
|
if (!MysApi || !e.targetUser) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
uid = e.targetUser.uid
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (!uid || !uidReg.test(uid)) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply('请先发送【#绑定+你的UID】来绑定查询目标')
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 自动更新面板数据
|
|
|
|
|
* */
|
2022-07-23 20:32:10 +00:00
|
|
|
|
export async function autoRefresh (e) {
|
|
|
|
|
let uid = await getTargetUid(e)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (!uid || e.isRefreshed) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let refreshMark = await redis.get(`miao:profile-refresh-cd:${uid}`)
|
|
|
|
|
let inCd = await redis.get(`miao:role-all:${uid}`)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
|
|
|
|
if (refreshMark || inCd) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
await redis.set(`miao:profile-refresh-cd:${uid}`, 'TRUE', { EX: 3600 * 12 })
|
|
|
|
|
e.isRefreshed = true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
|
|
|
|
// 数据更新
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let data = await Profile.request(uid, e)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (!data) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!data.chars) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply('请确认角色已在【游戏内】橱窗展示并开放了查看详情。请在设置完毕5分钟后使用 #面板更新 重新获取')
|
|
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
} else {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let ret = []
|
2022-06-25 23:45:43 +00:00
|
|
|
|
lodash.forEach(data.chars, (ds) => {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let char = Character.get(ds.id)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (char) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
ret.push(char.name)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if (ret.length === 0) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply('请确认角色已在【游戏内】橱窗展示并开放了查看详情。请在设置完毕5分钟后使用 #面板更新 重新获取')
|
|
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
} else {
|
|
|
|
|
// e.reply(`本次获取成功角色: ${ret.join(", ")} `)
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
export async function autoGetProfile (e, uid, avatar, callback) {
|
2022-06-27 20:46:49 +00:00
|
|
|
|
let refresh = async () => {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let refreshRet = await autoRefresh(e)
|
2022-06-27 20:46:49 +00:00
|
|
|
|
if (refreshRet) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
await callback()
|
2022-06-27 20:46:49 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return refreshRet
|
2022-06-27 20:46:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let char = Character.get(avatar)
|
2022-06-27 20:46:49 +00:00
|
|
|
|
if (!char) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return { err: true }
|
2022-06-27 20:46:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-18 10:13:42 +00:00
|
|
|
|
let profile = Profile.get(uid, char.id)
|
2022-08-24 01:07:06 +00:00
|
|
|
|
if (!profile || !profile.hasData) {
|
2022-06-27 20:46:49 +00:00
|
|
|
|
if (await refresh()) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return { err: true }
|
2022-06-27 20:46:49 +00:00
|
|
|
|
} else {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply(`请确认${char.name}已展示在【游戏内】的角色展柜中,并打开了“显示角色详情”。然后请使用 #更新面板\n命令来获取${char.name}的面板详情`)
|
2022-06-27 20:46:49 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return { err: true }
|
2022-08-16 20:04:12 +00:00
|
|
|
|
} else if (!['enka', 'input2', 'miao'].includes(profile.dataSource)) {
|
2022-06-27 20:46:49 +00:00
|
|
|
|
if (!await refresh()) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply('由于数据格式升级,请重新获取面板信息后查看')
|
2022-06-27 20:46:49 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return { err: true }
|
2022-06-27 20:46:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { profile, char, refresh }
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-05 22:12:57 +00:00
|
|
|
|
export async function inputProfile (e) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let uid = await getTargetUid(e)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (!uid) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-05 22:12:57 +00:00
|
|
|
|
if (e.inputData.trim().length < 5) {
|
|
|
|
|
e.reply('【输入示例】\n#录入夜兰面板 生命14450+25469, 攻击652+444, 防御548+144, 元素精通84, 暴击76.3, 爆伤194.2, 治疗0,充能112.3,元素伤害61.6,物伤0')
|
|
|
|
|
return true
|
|
|
|
|
// await profileHelp(e);
|
|
|
|
|
}
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-08-05 22:12:57 +00:00
|
|
|
|
let ret = Profile.inputProfile(uid, e)
|
|
|
|
|
let char = Character.get(e.avatar)
|
|
|
|
|
if (lodash.isString(ret)) {
|
|
|
|
|
e.reply(ret)
|
|
|
|
|
return true
|
|
|
|
|
} else if (ret) {
|
|
|
|
|
e.reply(`${char.name}信息手工录入完成,你可以使用 #角色名+面板 / #角色名+伤害 来查看详细角色面板属性了`)
|
|
|
|
|
} else {
|
|
|
|
|
e.reply(`${char.name}信息手工录入失败,请检查录入格式。回复 #角色面板帮助 可查看录入提示`)
|
|
|
|
|
e.reply('【输入示例】\n#录入夜兰面板 生命14450+25469, 攻击652+444, 防御548+144, 元素精通84, 暴击76.3, 爆伤194.2, 治疗0,充能112.3,元素伤害61.6,物伤0')
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 面板数据更新
|
|
|
|
|
* */
|
2022-08-24 01:07:06 +00:00
|
|
|
|
export async function getProfile (e) {
|
2022-08-05 22:12:57 +00:00
|
|
|
|
let uid = await getTargetUid(e)
|
|
|
|
|
if (!uid) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 数据更新
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let data = await Profile.request(uid, e)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (!data) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!data.chars) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply('获取角色面板数据失败,请确认角色已在游戏内橱窗展示,并开放了查看详情。设置完毕后请5分钟后再进行请求~')
|
2022-06-25 23:45:43 +00:00
|
|
|
|
} else {
|
2022-08-05 22:12:57 +00:00
|
|
|
|
let ret = {}
|
2022-06-25 23:45:43 +00:00
|
|
|
|
lodash.forEach(data.chars, (ds) => {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let char = Character.get(ds.id)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (char) {
|
2022-08-05 22:12:57 +00:00
|
|
|
|
ret[char.name] = true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if (ret.length === 0) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply('获取角色面板数据失败,未能请求到角色数据。请确认角色已在游戏内橱窗展示,并开放了查看详情。设置完毕后请5分钟后再进行请求~')
|
2022-06-25 23:45:43 +00:00
|
|
|
|
} else {
|
2022-08-05 22:12:57 +00:00
|
|
|
|
e.newChar = ret
|
2022-08-24 01:07:06 +00:00
|
|
|
|
return await profileList(e)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 获取面板列表
|
|
|
|
|
* */
|
2022-07-23 20:32:10 +00:00
|
|
|
|
export async function getProfileAll (e) {
|
|
|
|
|
let uid = await getTargetUid(e)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (!uid) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let profiles = Profile.getAll(uid) || {}
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let chars = []
|
2022-06-25 23:45:43 +00:00
|
|
|
|
lodash.forEach(profiles || [], (ds) => {
|
2022-08-16 20:04:12 +00:00
|
|
|
|
if (!['enka', 'input2', 'miao'].includes(ds.dataSource)) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
ds.name && chars.push(ds.name)
|
2022-07-23 20:32:10 +00:00
|
|
|
|
})
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
|
|
|
|
if (chars.length === 0) {
|
|
|
|
|
if (await autoRefresh(e)) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
await getProfileAll(e)
|
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
} else {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply('尚未获取任何角色数据')
|
|
|
|
|
await profileHelp(e)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply(`uid${uid} 已获取面板角色: ` + chars.join(', '))
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 面板帮助
|
|
|
|
|
* */
|
2022-07-23 20:32:10 +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
|
|
|
|
|
}
|