抽卡记录增加颜色,fix 抽卡统计获取uid和暂无抽卡记录提示 (#269)

* 抽卡记录增加颜色
fix 暂无抽卡记录提示

* fix 抽卡统计获取uid

* 星铁抽卡记录增加颜色
This commit is contained in:
story-x 2023-10-09 02:46:03 +08:00 committed by GitHub
parent 990f932ce6
commit ec9d2a6e92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 99 additions and 52 deletions

View File

@ -32,7 +32,7 @@ export class gcLog extends plugin {
fnc: 'logJson' fnc: 'logJson'
}, },
{ {
reg: '^#*(原神|星铁)?(全部)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥)池*(记录|祈愿|分析)$', reg: '^#*(原神|星铁)?(全部)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥|全部)池*(记录|祈愿|分析)$',
fnc: 'getLog' fnc: 'getLog'
}, },
{ {

View File

@ -6,7 +6,7 @@ import common from '../../../lib/common/common.js'
import gsCfg from './gsCfg.js' import gsCfg from './gsCfg.js'
export default class GachaLog extends base { export default class GachaLog extends base {
constructor(e) { constructor (e) {
super(e) super(e)
this.model = 'gachaLog' this.model = 'gachaLog'
@ -33,7 +33,7 @@ export default class GachaLog extends base {
} }
} }
async logUrl() { async logUrl () {
let url = this.e.msg let url = this.e.msg
/** 处理url */ /** 处理url */
@ -58,7 +58,7 @@ export default class GachaLog extends base {
if (i <= 1) await common.sleep(500) if (i <= 1) await common.sleep(500)
} }
MakeMsg.push(tmpMsg) MakeMsg.push(tmpMsg)
MakeMsg.push(`\n抽卡记录更新完成,您还可回复\n${this?.e?.isSr ? '*' : '#'}全部抽卡记录】展示全部抽卡数据\n${this?.e?.isSr ? '*光锥' : '#武器'}记录】统计${this?.e?.isSr ? '星铁光锥' : '武器'}池数据\n${this?.e?.isSr ? '*' : '#'}角色统计】按卡池统计数据\n【#导出记录】导出记录数据`) MakeMsg.push(`\n抽卡记录更新完成,您还可回复\n${this?.e?.isSr ? '*' : '#'}全部记录】统计全部抽卡数据\n${this?.e?.isSr ? '*光锥' : '#武器'}记录】统计${this?.e?.isSr ? '星铁光锥' : '武器'}池数据\n${this?.e?.isSr ? '*' : '#'}角色统计】按卡池统计数据\n${this?.e?.isSr ? '' : '【#导出记录】导出记录数据'}`)
await this.e.reply(MakeMsg) await this.e.reply(MakeMsg)
this.isLogUrl = true this.isLogUrl = true
@ -71,7 +71,7 @@ export default class GachaLog extends base {
return data return data
} }
async logFile() { async logFile () {
let url = await this.downFile() let url = await this.downFile()
if (!url) { if (!url) {
if (this.e?.file?.name.includes('output')) { if (this.e?.file?.name.includes('output')) {
@ -84,7 +84,7 @@ export default class GachaLog extends base {
return this.logUrl() return this.logUrl()
} }
dealUrl(url) { dealUrl (url) {
// timestamp=1641338980〈=zh-cn 修复链接有奇怪符号 // timestamp=1641338980〈=zh-cn 修复链接有奇怪符号
url = url.replace(/〈=/g, '&') url = url.replace(/〈=/g, '&')
if (url.includes('getGachaLog?')) url = url.split('getGachaLog?')[1] if (url.includes('getGachaLog?')) url = url.split('getGachaLog?')[1]
@ -109,7 +109,7 @@ export default class GachaLog extends base {
return params return params
} }
async downFile() { async downFile () {
this.creatFile() this.creatFile()
let textPath = `${this.path}output_log.txt` let textPath = `${this.path}output_log.txt`
@ -138,7 +138,7 @@ export default class GachaLog extends base {
return url[0] return url[0]
} }
async checkUrl(param) { async checkUrl (param) {
if (!param.region) { if (!param.region) {
let res = await this.logApi({ let res = await this.logApi({
size: 6, size: 6,
@ -207,7 +207,7 @@ export default class GachaLog extends base {
} }
} }
async logApi(param) { async logApi (param) {
// 调用一次接口判断链接是否正确 // 调用一次接口判断链接是否正确
let logUrl = 'https://hk4e-api.mihoyo.com/event/gacha_info/api/getGachaLog?' let logUrl = 'https://hk4e-api.mihoyo.com/event/gacha_info/api/getGachaLog?'
/** 国际服 */ /** 国际服 */
@ -250,7 +250,7 @@ export default class GachaLog extends base {
} }
/** 更新抽卡记录 */ /** 更新抽卡记录 */
async updateLog() { async updateLog () {
/** 获取authkey */ /** 获取authkey */
let authkey = await redis.get(`${this.urlKey}${this.uid}`) let authkey = await redis.get(`${this.urlKey}${this.uid}`)
if (!authkey) return false if (!authkey) return false
@ -293,7 +293,7 @@ export default class GachaLog extends base {
} }
/** 递归获取所有数据 */ /** 递归获取所有数据 */
async getAllLog(ids, authkey, page = 1, endId = 0) { async getAllLog (ids, authkey, page = 1, endId = 0) {
let res = await this.logApi({ let res = await this.logApi({
gacha_type: this.type, gacha_type: this.type,
page, page,
@ -340,7 +340,7 @@ export default class GachaLog extends base {
} }
// 读取本地json // 读取本地json
readJson() { readJson () {
let logJson = []; let ids = new Map() let logJson = []; let ids = new Map()
let file = `${this.path}/${this.uid}/${this.type}.json` let file = `${this.path}/${this.uid}/${this.type}.json`
if (fs.existsSync(file)) { if (fs.existsSync(file)) {
@ -356,7 +356,7 @@ export default class GachaLog extends base {
return { list: logJson, ids } return { list: logJson, ids }
} }
creatFile() { creatFile () {
if (!fs.existsSync(this.path)) { if (!fs.existsSync(this.path)) {
fs.mkdirSync(this.path) fs.mkdirSync(this.path)
} }
@ -367,7 +367,7 @@ export default class GachaLog extends base {
} }
} }
writeJson(data) { writeJson (data) {
this.creatFile() this.creatFile()
let file = `${this.path}${this.uid}/` let file = `${this.path}${this.uid}/`
@ -376,7 +376,7 @@ export default class GachaLog extends base {
} }
/** #抽卡记录 */ /** #抽卡记录 */
async getLogData() { async getLogData () {
/** 判断uid */ /** 判断uid */
await this.getUid() await this.getUid()
if (!this.uid) { if (!this.uid) {
@ -389,7 +389,7 @@ export default class GachaLog extends base {
} }
} }
async getAllGcLogData() { async getAllGcLogData () {
this.model = 'gachaAllLog' this.model = 'gachaAllLog'
const poolList = ['角色', this.e?.isSr ? '光锥' : '武器', '常驻'] const poolList = ['角色', this.e?.isSr ? '光锥' : '武器', '常驻']
const logData = [] const logData = []
@ -426,7 +426,7 @@ export default class GachaLog extends base {
return data return data
} }
async getGcLogData() { async getGcLogData () {
/** 卡池 */ /** 卡池 */
this.getPool() this.getPool()
/** 更新记录 */ /** 更新记录 */
@ -438,7 +438,7 @@ export default class GachaLog extends base {
return data return data
} }
getPool() { getPool () {
let msg = this.e.msg.replace(/#|抽卡|记录|祈愿|分析|池|原神|星铁|崩坏星穹铁道|铁道/g, '') let msg = this.e.msg.replace(/#|抽卡|记录|祈愿|分析|池|原神|星铁|崩坏星穹铁道|铁道/g, '')
this.type = this.e.isSr ? 11 : 301 this.type = this.e.isSr ? 11 : 301
this.typeName = '角色' this.typeName = '角色'
@ -469,21 +469,22 @@ export default class GachaLog extends base {
} }
} }
async getUid() { async getUid () {
if (!fs.existsSync(this.path)) { if (!fs.existsSync(this.path)) {
this.e.reply('暂无抽卡记录\n#记录帮助,查看配置说明', false, { at: true }) this.e.reply(`暂无抽卡记录\n${this.e?.isSr ? '*' : '#'}记录帮助,查看配置说明`, false, { at: true })
return false return false
} }
let logs = fs.readdirSync(this.path) let logs = fs.readdirSync(this.path)
if (lodash.isEmpty(logs)) { if (lodash.isEmpty(logs)) {
this.e.reply('暂无抽卡记录\n#记录帮助,查看配置说明', false, { at: true }) this.e.reply(`暂无抽卡记录\n${this.e?.isSr ? '*' : '#'}记录帮助,查看配置说明`, false, { at: true })
return false return false
} }
this.uid = this?.e?.isSr ? this.e.user?._games?.sr?.uid : this.e.user?._games?.gs?.uid
if (!this.uid) { if (!this.uid) {
this.uid = await redis.get(this.uidKey) this.e.at = false
this.uid = this?.e?.isSr ? this.e.user?._games?.sr?.uid : this.e.user?._games?.gs?.uid || await this.e.runtime.getUid(this.e) || await redis.get(this.uidKey)
} }
/** 记录有绑定的uid */ /** 记录有绑定的uid */
@ -519,7 +520,7 @@ export default class GachaLog extends base {
} }
/** 统计计算记录 */ /** 统计计算记录 */
analyse() { analyse () {
if (lodash.isEmpty(this.all)) { if (lodash.isEmpty(this.all)) {
this.all = this.readJson().list this.all = this.readJson().list
} }
@ -682,7 +683,7 @@ export default class GachaLog extends base {
} }
} }
checkIsUp() { checkIsUp () {
if (['莫娜', '七七', '迪卢克', '琴', '姬子', '杰帕德', '彦卿', '白露', '瓦尔特', '克拉拉', '布洛妮娅'].includes(this.role.name)) { if (['莫娜', '七七', '迪卢克', '琴', '姬子', '杰帕德', '彦卿', '白露', '瓦尔特', '克拉拉', '布洛妮娅'].includes(this.role.name)) {
return false return false
} }
@ -715,7 +716,8 @@ export default class GachaLog extends base {
} }
/** 渲染数据 */ /** 渲染数据 */
randData(data) { randData (data) {
const max = this.type === 12 || this.type === 302 ? 80 : 90
let line = [] let line = []
let weapon = this.e.isSr ? '光锥' : '武器' let weapon = this.e.isSr ? '光锥' : '武器'
if ([301, 11].includes(this.type)) { if ([301, 11].includes(this.type)) {
@ -790,11 +792,12 @@ export default class GachaLog extends base {
lastTime: data.lastTime, lastTime: data.lastTime,
fiveLog: data.fiveLog, fiveLog: data.fiveLog,
line, line,
hasMore hasMore,
max
} }
} }
getServer() { getServer () {
let uid = this.uid let uid = this.uid
switch (String(uid)[0]) { switch (String(uid)[0]) {
case '1': case '1':
@ -813,4 +816,4 @@ export default class GachaLog extends base {
} }
return 'cn_gf01' return 'cn_gf01'
} }
} }

View File

@ -5,7 +5,7 @@ import gsCfg from './gsCfg.js'
import moment from 'moment' import moment from 'moment'
export default class LogCount extends base { export default class LogCount extends base {
constructor(e) { constructor (e) {
super(e) super(e)
this.model = 'logCount' this.model = 'logCount'
@ -44,7 +44,7 @@ export default class LogCount extends base {
} }
// 读取本地json // 读取本地json
readJson() { readJson () {
let logJson = []; let ids = [] let logJson = []; let ids = []
let file = `${this.path}/${this.uid}/${this.type}.json` let file = `${this.path}/${this.uid}/${this.type}.json`
if (fs.existsSync(file)) { if (fs.existsSync(file)) {
@ -61,7 +61,7 @@ export default class LogCount extends base {
} }
/** #抽卡统计 */ /** #抽卡统计 */
async count() { async count () {
/** 卡池 */ /** 卡池 */
this.getPool() this.getPool()
@ -84,9 +84,9 @@ export default class LogCount extends base {
} }
} }
getPool() { getPool () {
let msg = this.e.msg.replace(/#|抽卡|记录|祈愿|分析|池|原神|星铁|崩坏星穹铁道|铁道|抽卡|统计|池/g, '') let msg = this.e.msg.replace(/#|抽卡|记录|祈愿|分析|池|原神|星铁|崩坏星穹铁道|铁道|抽卡|统计|池/g, '')
this.type = this.e.isSr?11:301 this.type = this.e.isSr ? 11 : 301
this.typeName = '角色' this.typeName = '角色'
switch (msg) { switch (msg) {
case 'up': case 'up':
@ -104,31 +104,34 @@ export default class LogCount extends base {
this.type = this.e.isSr ? 12 : 302 this.type = this.e.isSr ? 12 : 302
this.typeName = this.e.isSr ? '光锥' : '武器' this.typeName = this.e.isSr ? '光锥' : '武器'
break break
case "光锥": case '光锥':
this.type = 12 this.type = 12
this.typeName = '光锥' this.typeName = '光锥'
break break
case "新手": case '新手':
this.type = this.e.isSr? 2:100 this.type = this.e.isSr ? 2 : 100
this.typeName = '新手' this.typeName = '新手'
break break
} }
} }
async getUid() { async getUid () {
if (!fs.existsSync(this.path)) { if (!fs.existsSync(this.path)) {
this.e.reply('暂无抽卡记录\n#记录帮助,查看配置说明', false, { at: true }) this.e.reply(`暂无抽卡记录\n${this.e?.isSr ? '*' : '#'}记录帮助,查看配置说明`, false, { at: true })
return false return false
} }
let logs = fs.readdirSync(this.path) let logs = fs.readdirSync(this.path)
if (lodash.isEmpty(logs)) { if (lodash.isEmpty(logs)) {
this.e.reply('暂无抽卡记录\n#记录帮助,查看配置说明', false, { at: true }) this.e.reply(`暂无抽卡记录\n${this.e?.isSr ? '*' : '#'}记录帮助,查看配置说明`, false, { at: true })
return false return false
} }
this.uid = await redis.get(this.uidKey) if (!this.uid) {
this.e.at = false
this.uid = this?.e?.isSr ? this.e.user?._games?.sr?.uid : this.e.user?._games?.gs?.uid || await this.e.runtime.getUid(this.e) || await redis.get(this.uidKey)
}
/** 记录有绑定的uid */ /** 记录有绑定的uid */
if (this.uid && logs.includes(String(this.uid))) { if (this.uid && logs.includes(String(this.uid))) {
@ -162,7 +165,7 @@ export default class LogCount extends base {
return uidArr[0].uid return uidArr[0].uid
} }
getPoolCfg() { getPoolCfg () {
let poolCfg = gsCfg.getdefSet('pool', this.type) let poolCfg = gsCfg.getdefSet('pool', this.type)
poolCfg.forEach(v => { poolCfg.forEach(v => {
@ -174,7 +177,7 @@ export default class LogCount extends base {
} }
/** 统计计算记录 */ /** 统计计算记录 */
analyseHistory() { analyseHistory () {
let all = this.readJson().list let all = this.readJson().list
all = all.reverse() all = all.reverse()

View File

@ -37,7 +37,7 @@ body {
.head_box .id_text { .head_box .id_text {
color: #f5e7f4; color: #f5e7f4;
padding: 5px 0; padding: 5px 0;
font-size: 26px; font-size: 26px;
} }
@ -352,4 +352,24 @@ body {
font-size: 12px; font-size: 12px;
margin: 6px 0; margin: 6px 0;
color: #7f858a; color: #7f858a;
} }
.gold {
background: #ffeb73;
color: #6f4b00;
}
.good {
background: #168b2c;
color: #fff;
}
.normal {
background: #6939b7;
color: #fff;
}
.bad {
background: #9d3333;
color: #fff;
}

View File

@ -45,7 +45,7 @@
<div class="card_list"> <div class="card_list">
{{each fiveLog val}} {{each fiveLog val}}
<div class="item star5"> <div class="item star5 {{val.num<=10?'gold': (val.num<max*0.5 ? 'good' : (num<max*0.83) ? 'normal': 'bad')}}">
{{ if val.isUp && typeName == '角色' }} {{ if val.isUp && typeName == '角色' }}
<span class="minimum">UP</span> <span class="minimum">UP</span>
{{/if}} {{/if}}
@ -53,7 +53,7 @@
src="{{pluResPath}}img/{{val.item_type=='角色'?'role':'weapon'}}/{{val.name}}.webp" src="{{pluResPath}}img/{{val.item_type=='角色'?'role':'weapon'}}/{{val.name}}.webp"
onerror="whenError(this,'{{val.item_type=='角色'?'role':'weapon'}}')"/> onerror="whenError(this,'{{val.item_type=='角色'?'role':'weapon'}}')"/>
<!-- <div class="num">{{val.num}}</div>--> <!-- <div class="num">{{val.num}}</div>-->
<div class="num_name">{{val.num}}</div> <div class="num_name {{val.num<=10?'gold': (val.num<log.max*0.5 ? 'good' : (val.num<log.max*0.83) ? 'normal': 'bad')}}" >{{val.num}}</div>
</div> </div>
{{/each}} {{/each}}
</div> </div>
@ -75,4 +75,4 @@
// } // }
} }
</script> </script>
</html> </html>

View File

@ -348,4 +348,25 @@ body {
font-size: 12px; font-size: 12px;
margin: 6px 0; margin: 6px 0;
color: #7f858a; color: #7f858a;
} }
.gold {
background: #ffeb73;
color: #6f4b00;
}
.good {
background: #168b2c;
color: #fff;
}
.normal {
background: #6939b7;
color: #fff;
}
.bad {
background: #9d3333;
color: #fff;
}

View File

@ -46,7 +46,7 @@
<div class="card_list"> <div class="card_list">
{{each fiveLog val}} {{each fiveLog val}}
<div class="item star5"> <div class="item star5 {{val.num<=10?'gold': (val.num<max*0.5 ? 'good' : (num<max*0.83) ? 'normal': 'bad')}}">
{{ if val.isUp && typeName == '角色' }} {{ if val.isUp && typeName == '角色' }}
<span class="minimum">UP</span> <span class="minimum">UP</span>
{{/if}} {{/if}}
@ -54,7 +54,7 @@
src="{{pluResPath}}img/{{val.item_type=='角色'?'role':'weapon'}}/{{val.name}}.png" src="{{pluResPath}}img/{{val.item_type=='角色'?'role':'weapon'}}/{{val.name}}.png"
onerror="whenError(this,'{{val.item_type=='角色'?'role':'weapon'}}')"/> onerror="whenError(this,'{{val.item_type=='角色'?'role':'weapon'}}')"/>
<!-- <div class="num">{{val.num}}</div>--> <!-- <div class="num">{{val.num}}</div>-->
<div class="num_name">{{val.num}}</div> <div class="num_name {{val.num<=10?'gold': (val.num<max*0.5 ? 'good' : (num<max*0.83) ? 'normal': 'bad')}}" >{{val.num}}</div>
</div> </div>
{{/each}} {{/each}}
</div> </div>
@ -76,4 +76,4 @@
// } // }
} }
</script> </script>
</html> </html>