2023-03-04 14:30:13 +08:00
|
|
|
import plugin from '../../../lib/plugins/plugin.js'
|
|
|
|
import fs from 'node:fs'
|
|
|
|
import GachaLog from '../model/gachaLog.js'
|
|
|
|
import ExportLog from '../model/exportLog.js'
|
|
|
|
import LogCount from '../model/logCount.js'
|
|
|
|
|
|
|
|
const _path = process.cwd() + '/plugins/genshin'
|
|
|
|
|
|
|
|
export class gcLog extends plugin {
|
2023-10-25 17:32:57 +08:00
|
|
|
constructor () {
|
2023-03-04 14:30:13 +08:00
|
|
|
super({
|
|
|
|
name: '抽卡记录',
|
|
|
|
dsc: '抽卡记录数据统计',
|
|
|
|
event: 'message',
|
|
|
|
priority: 300,
|
|
|
|
rule: [
|
|
|
|
{
|
|
|
|
reg: '(.*)authkey=(.*)',
|
|
|
|
fnc: 'logUrl'
|
|
|
|
},
|
|
|
|
{
|
2023-10-25 17:32:57 +08:00
|
|
|
reg: '^#txt日志文件导入记录$',
|
2023-03-04 14:30:13 +08:00
|
|
|
fnc: 'logFile'
|
|
|
|
},
|
|
|
|
{
|
2023-10-25 17:32:57 +08:00
|
|
|
reg: '^#json文件导入记录$',
|
2023-03-04 14:30:13 +08:00
|
|
|
fnc: 'logJson'
|
|
|
|
},
|
|
|
|
{
|
2023-10-09 02:46:03 +08:00
|
|
|
reg: '^#*(原神|星铁)?(全部)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥|全部)池*(记录|祈愿|分析)$',
|
2023-03-04 14:30:13 +08:00
|
|
|
fnc: 'getLog'
|
|
|
|
},
|
|
|
|
{
|
2023-12-09 23:12:53 +08:00
|
|
|
reg: '^#*(原神|星铁)?导出记录(json)?$',
|
2023-03-04 14:30:13 +08:00
|
|
|
fnc: 'exportLog'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
reg: '^#*(记录帮助|抽卡帮助)$',
|
|
|
|
fnc: 'help'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
reg: '^#*(安卓|苹果|电脑|pc|ios)帮助$',
|
|
|
|
fnc: 'helpPort'
|
|
|
|
},
|
|
|
|
{
|
2023-05-07 03:32:08 +08:00
|
|
|
reg: '^#*(原神|星铁)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥)池*统计$',
|
2023-03-04 14:30:13 +08:00
|
|
|
fnc: 'logCount'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2023-09-06 03:00:17 +08:00
|
|
|
this.androidUrl = 'https://docs.qq.com/doc/DUWpYaXlvSklmVXlX'
|
2023-03-04 14:30:13 +08:00
|
|
|
}
|
|
|
|
|
2023-10-25 17:32:57 +08:00
|
|
|
async init () {
|
|
|
|
let file = ['./data/gachaJson', './data/srJson', './temp/html/StarRail', './temp/uigf']
|
2023-08-18 10:19:48 +08:00
|
|
|
for (let i of file) {
|
2023-05-03 22:09:39 +08:00
|
|
|
if (!fs.existsSync(i)) {
|
|
|
|
fs.mkdirSync(i)
|
|
|
|
}
|
2023-03-04 14:30:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-25 17:32:57 +08:00
|
|
|
accept () {
|
2023-03-04 14:30:13 +08:00
|
|
|
if (this.e.file && this.e.isPrivate) {
|
|
|
|
let name = this.e.file?.name
|
|
|
|
if (name.includes('txt')) {
|
|
|
|
this.e.msg = '#txt日志文件导入记录'
|
|
|
|
if (name.includes('output')) return true
|
|
|
|
}
|
|
|
|
if (/(.*)[1-9][0-9]{8}(.*).json/ig.test(name)) {
|
|
|
|
this.e.msg = '#json文件导入记录'
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.e.msg && /^#*(角色|武器)统计$/g.test(this.e.msg)) {
|
|
|
|
this.e.msg = this.e.msg.replace('统计', '池统计')
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 抽卡记录链接 */
|
2023-10-25 17:32:57 +08:00
|
|
|
async logUrl () {
|
2023-03-04 14:30:13 +08:00
|
|
|
if (!this.e.isPrivate) {
|
|
|
|
this.e.reply('请私聊发送链接', false, { at: true })
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
let data = await new GachaLog(this.e).logUrl()
|
|
|
|
if (!data) return
|
2023-08-18 10:19:48 +08:00
|
|
|
|
2023-11-08 03:03:36 +08:00
|
|
|
await this.renderImg('genshin', `html/gacha/gacha-log`, data)
|
2023-03-04 14:30:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 发送output_log.txt日志文件 */
|
2023-10-25 17:32:57 +08:00
|
|
|
async logFile () {
|
2023-03-04 14:30:13 +08:00
|
|
|
if (!this.e.isPrivate) {
|
|
|
|
await this.e.reply('请私聊发送日志文件', false, { at: true })
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.e.file || !this.e.file.name.includes('txt')) {
|
|
|
|
await this.e.reply('请发送日志文件')
|
|
|
|
} else {
|
|
|
|
await this.e.reply('3.0版本后,日志文件已不能获取抽取记录链接\n请用安卓方式获取')
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
let data = await new GachaLog(this.e).logFile()
|
|
|
|
if (!data) return false
|
|
|
|
|
|
|
|
if (typeof data != 'object') return
|
2023-08-18 10:19:48 +08:00
|
|
|
|
2023-11-08 03:03:36 +08:00
|
|
|
await this.renderImg('genshin', `html/gacha/gacha-log`, data)
|
2023-03-04 14:30:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** #抽卡记录 */
|
2023-10-25 17:32:57 +08:00
|
|
|
async getLog () {
|
2023-08-22 02:26:19 +08:00
|
|
|
this.e.isAll = !!(this.e.msg.includes('全部'))
|
2023-03-04 14:30:13 +08:00
|
|
|
let data = await new GachaLog(this.e).getLogData()
|
|
|
|
if (!data) return
|
2023-11-08 03:03:36 +08:00
|
|
|
let name = `html/gacha/gacha-log`
|
2023-08-21 03:01:22 +08:00
|
|
|
if (this.e.isAll) {
|
2023-11-08 03:03:36 +08:00
|
|
|
name = `html/gacha/gacha-all-log`
|
2023-08-21 03:01:22 +08:00
|
|
|
}
|
2023-11-08 03:03:36 +08:00
|
|
|
await this.renderImg('genshin', name, data)
|
2023-03-04 14:30:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 导出记录 */
|
2023-10-25 17:32:57 +08:00
|
|
|
async exportLog () {
|
2023-03-04 14:30:13 +08:00
|
|
|
if (this.e.isGroup) {
|
|
|
|
await this.reply('请私聊导出', false, { at: true })
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let exportLog = new ExportLog(this.e)
|
2023-12-09 23:12:53 +08:00
|
|
|
return await exportLog.exportJson()
|
2023-03-04 14:30:13 +08:00
|
|
|
}
|
|
|
|
|
2023-10-25 17:32:57 +08:00
|
|
|
async logJson () {
|
2023-03-04 14:30:13 +08:00
|
|
|
if (!this.e.isPrivate) {
|
2023-10-25 17:32:57 +08:00
|
|
|
await this.e.reply('请私聊发送Json文件', false, { at: true })
|
2023-03-04 14:30:13 +08:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.e.file) {
|
2023-10-25 17:32:57 +08:00
|
|
|
await this.e.reply('请发送Json文件')
|
|
|
|
return true
|
2023-10-13 02:52:05 +08:00
|
|
|
}
|
2023-10-25 17:32:57 +08:00
|
|
|
|
|
|
|
await new ExportLog(this.e).logJson()
|
2023-03-04 14:30:13 +08:00
|
|
|
}
|
|
|
|
|
2023-10-25 17:32:57 +08:00
|
|
|
async help () {
|
2023-09-06 03:00:17 +08:00
|
|
|
await this.e.reply(segment.image(`file://${_path}/resources/logHelp/记录帮助.png`))
|
2023-03-04 14:30:13 +08:00
|
|
|
}
|
|
|
|
|
2023-10-25 17:32:57 +08:00
|
|
|
async helpPort () {
|
2023-03-04 14:30:13 +08:00
|
|
|
let msg = this.e.msg.replace(/#|帮助/g, '')
|
|
|
|
|
|
|
|
if (['电脑', 'pc'].includes(msg)) {
|
2023-09-06 03:00:17 +08:00
|
|
|
await this.e.reply(segment.image(`file://${_path}/resources/logHelp/记录帮助-电脑.png`))
|
2023-03-04 14:30:13 +08:00
|
|
|
} else if (['安卓'].includes(msg)) {
|
|
|
|
await this.e.reply(`安卓抽卡记录获取教程:${this.androidUrl}`)
|
|
|
|
} else if (['苹果', 'ios'].includes(msg)) {
|
2023-09-06 03:00:17 +08:00
|
|
|
await this.e.reply(segment.image(`file://${_path}/resources/logHelp/记录帮助-苹果.png`))
|
2023-03-04 14:30:13 +08:00
|
|
|
}
|
|
|
|
}
|
2023-08-18 10:19:48 +08:00
|
|
|
|
2023-10-25 17:32:57 +08:00
|
|
|
async logCount () {
|
2023-03-04 14:30:13 +08:00
|
|
|
let data = await new LogCount(this.e).count()
|
|
|
|
if (!data) return
|
2023-11-08 03:03:36 +08:00
|
|
|
this.renderImg('genshin', `html/gacha/log-count`, data)
|
2023-03-04 14:30:13 +08:00
|
|
|
}
|
|
|
|
}
|