miao-plugin/apps/gacha/Gacha.js

127 lines
3.3 KiB
JavaScript
Raw Normal View History

2023-03-07 17:52:11 +00:00
import { Common } from '#miao'
import { getTargetUid } from '../profile/ProfileCommon.js'
import GachaData from './GachaData.js'
2024-02-04 01:27:34 +00:00
import { Button, Character, Player } from '#miao.models'
let Gacha = {
async detail (e) {
let msg = e.msg.replace(/#|抽卡|记录|祈愿|分析|池/g, '')
2024-05-23 15:37:38 +00:00
let game = /星铁/.test(msg) ? 'sr' : 'gs'
msg = msg.replace(/星铁/, '')
let type
if (e.isSr) {
type = 11
switch (msg) {
case 'up':
case '抽卡':
case '角色':
case '抽奖':
type = 11
break
case '常驻':
type = 1
break
case '武器':
case '光锥':
type = 12
break
}
} else {
type = 301
switch (msg) {
case 'up':
case '抽卡':
case '角色':
case '抽奖':
type = 301
break
case '常驻':
type = 200
break
case '武器':
type = 302
break
case '集录':
type = 500
break
}
}
let uid = e.uid || await getTargetUid(e)
2024-05-23 17:55:48 +00:00
let qq = e.user.qq
if (!uid || !qq) {
return false
}
2024-05-23 17:55:48 +00:00
let gacha = GachaData.analyse(qq, uid, type, game)
2023-02-27 13:31:10 +00:00
if (!gacha) {
2024-02-04 01:27:34 +00:00
e.reply([`UID:${uid} 本地暂无抽卡信息,请通过【#抽卡帮助】获得绑定帮助...`, new Button(e).gacha()])
2023-02-27 13:31:10 +00:00
return true
}
2024-05-23 15:37:38 +00:00
if (type === 302 || type === 12) type = 'weapon'
2024-02-04 01:27:34 +00:00
this.reply([await Common.render('gacha/gacha-detail', {
save_id: uid,
uid,
gacha,
2024-05-23 15:37:38 +00:00
face: Gacha.getFace(uid, game),
game,
type,
elem: e.isSr ? 'sr' : 'hydro'
2024-04-03 16:33:14 +00:00
}, { e, scale: 1.4, retType: 'base64' }), new Button(e).gacha()])
},
async stat (e) {
2023-02-26 19:30:26 +00:00
let msg = e.msg.replace(/#|统计|分析|池/g, '')
2024-05-23 15:37:38 +00:00
let game = /星铁/.test(msg) ? 'sr' : 'gs'
msg = msg.replace(/星铁/, '')
2023-02-26 19:30:26 +00:00
let type = 'up'
2024-05-23 15:37:38 +00:00
if (/武器|光锥/.test(msg)) {
2023-02-26 19:30:26 +00:00
type = 'weapon'
} else if (/角色/.test(msg)) {
type = 'char'
} else if (/常驻/.test(msg)) {
type = 'normal'
2024-04-03 16:33:14 +00:00
} else if (/集录/.test(msg)) {
type = 'mix'
2023-02-26 19:30:26 +00:00
} else if (/全部/.test(msg)) {
type = 'all'
}
let uid = e.uid || await getTargetUid(e)
2024-05-23 17:55:48 +00:00
let qq = e.user.qq
if (!uid || !qq) {
return false
}
2024-05-23 17:55:48 +00:00
let gacha = GachaData.stat(qq, uid, type, game)
2023-02-27 13:31:10 +00:00
if (!gacha) {
2024-02-04 01:27:34 +00:00
e.reply([`UID:${uid} 本地暂无抽卡信息,请通过【#抽卡帮助】获得绑定帮助...`, new Button(e).gacha()])
2023-02-27 13:31:10 +00:00
return true
}
2024-02-04 01:27:34 +00:00
e.reply([await Common.render('gacha/gacha-stat', {
save_id: uid,
uid,
gacha,
2024-05-23 15:37:38 +00:00
face: Gacha.getFace(uid, game),
game,
elem: e.isSr ? 'sr' : 'hydro'
2024-04-03 16:33:14 +00:00
}, { e, scale: 1.4, retType: 'base64' }), new Button(e).gacha()])
},
2024-05-23 15:37:38 +00:00
getFace (uid, game) {
let player = Player.create(uid, game)
let defaultFaceChar = game === 'gs' ? 10000014 : 1005
let faceChar = Character.get(player.face || defaultFaceChar, game)
let imgs = faceChar?.imgs
if (!imgs?.face) {
2024-05-23 17:28:22 +00:00
imgs = game === 'gs' ? Character.get(10000079, game).imgs : Character.get(1005, game).imgs
2023-02-28 17:59:13 +00:00
}
return {
banner: imgs?.banner,
face: imgs?.face,
qFace: imgs?.qFace,
2023-02-28 17:59:13 +00:00
name: player.name || '旅行者',
sign: player.sign,
level: player.level
}
}
}
2024-04-03 16:33:14 +00:00
export default Gacha