优化 允许在群聊操作抽卡记录

This commit is contained in:
🌌 2024-01-05 14:46:23 +08:00
parent b659655dca
commit c1ff63b7a8
3 changed files with 215 additions and 264 deletions

View File

@ -1,55 +1,51 @@
import plugin from '../../../lib/plugins/plugin.js' import plugin from "../../../lib/plugins/plugin.js"
import fs from 'node:fs' import fs from "node:fs"
import GachaLog from '../model/gachaLog.js' import GachaLog from "../model/gachaLog.js"
import ExportLog from '../model/exportLog.js' import ExportLog from "../model/exportLog.js"
import LogCount from '../model/logCount.js' import LogCount from "../model/logCount.js"
const _path = process.cwd() + '/plugins/genshin' const _path = process.cwd() + "/plugins/genshin"
export class gcLog extends plugin { export class gcLog extends plugin {
constructor() { constructor() {
super({ super({
name: '抽卡记录', name: "抽卡记录",
dsc: '抽卡记录数据统计', dsc: "抽卡记录数据统计",
event: 'message', event: "message",
priority: 300, priority: 300,
rule: [ rule: [
{ {
reg: '(.*)authkey=(.*)', reg: "(.*)authkey=(.*)",
fnc: 'logUrl' fnc: "logUrl"
}, },
{ {
reg: '^#txt日志文件导入记录$', reg: "^#json文件导入记录$",
fnc: 'logFile' fnc: "logJson"
}, },
{ {
reg: '^#json文件导入记录$', reg: "^#?(原神|星铁)?(全部)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥|全部)池*(记录|祈愿|分析)$",
fnc: 'logJson' fnc: "getLog"
}, },
{ {
reg: '^#*(原神|星铁)?(全部)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥|全部)池*(记录|祈愿|分析)$', reg: "^#?(原神|星铁)?(强制)?导出记录(json)?$",
fnc: 'getLog' fnc: "exportLog"
}, },
{ {
reg: '^#*(原神|星铁)?导出记录(json)?$', reg: "^#?(记录帮助|抽卡帮助)$",
fnc: 'exportLog' fnc: "help"
}, },
{ {
reg: '^#*(记录帮助|抽卡帮助)$', reg: "^#?(安卓|苹果|电脑|pc|ios)帮助$",
fnc: 'help' fnc: "helpPort"
}, },
{ {
reg: '^#*(安卓|苹果|电脑|pc|ios)帮助$', reg: "^#?(原神|星铁)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥)池*统计$",
fnc: 'helpPort' fnc: "logCount"
},
{
reg: '^#*(原神|星铁)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥)池*统计$',
fnc: 'logCount'
} }
] ]
}) })
this.androidUrl = 'https://docs.qq.com/doc/DUWpYaXlvSklmVXlX' this.androidUrl = "https://docs.qq.com/doc/DUWpYaXlvSklmVXlX"
Object.defineProperty(this, "button", { get() { Object.defineProperty(this, "button", { get() {
this.prefix = this.e?.isSr ? "*" : "#" this.prefix = this.e?.isSr ? "*" : "#"
return segment.button([ return segment.button([
@ -66,7 +62,7 @@ export class gcLog extends plugin {
} }
async init() { async init() {
let file = ['./data/gachaJson', './data/srJson', './temp/html/StarRail', './temp/uigf'] let file = ["./data/gachaJson", "./data/srJson", "./temp/html/StarRail", "./temp/uigf"]
for (let i of file) { for (let i of file) {
if (!fs.existsSync(i)) { if (!fs.existsSync(i)) {
fs.mkdirSync(i) fs.mkdirSync(i)
@ -75,112 +71,78 @@ export class gcLog extends plugin {
} }
accept() { accept() {
if (this.e.file && this.e.isPrivate) { if (this.e.file) {
let name = this.e.file?.name 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)) { if (/(.*)[1-9][0-9]{8}(.*).json/ig.test(name)) {
this.e.msg = '#json文件导入记录' this.e.msg = "#json文件导入记录"
return true return true
} }
} }
if (this.e.msg && /^#*(角色|武器)统计$/g.test(this.e.msg)) { if (this.e.msg && /^#?(角色|武器)统计$/g.test(this.e.msg)) {
this.e.msg = this.e.msg.replace('统计', '池统计') this.e.msg = this.e.msg.replace("统计", "池统计")
return true return true
} }
} }
/** 抽卡记录链接 */ /** 抽卡记录链接 */
async logUrl() { async logUrl() {
if (!this.e.isPrivate) {
this.e.reply('请私聊发送链接', false, { at: true })
return true
}
let data = await new GachaLog(this.e).logUrl() let data = await new GachaLog(this.e).logUrl()
if (!data) return if (!data) return
await this.renderImg('genshin', `html/gacha/gacha-log`, data) await this.renderImg("genshin", `html/gacha/gacha-log`, data)
}
/** 发送output_log.txt日志文件 */ if (this.e.isGroup)
async logFile() { this.e.reply("已收到链接,请撤回", false, { at: true })
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
this.reply([await this.renderImg('genshin', `html/gacha/gacha-log`, data, { retType: "base64" }), this.button])
} }
/** #抽卡记录 */ /** #抽卡记录 */
async getLog() { async getLog() {
this.e.isAll = !!(this.e.msg.includes('全部')) this.e.isAll = !!(this.e.msg.includes("全部"))
let data = await new GachaLog(this.e).getLogData() let data = await new GachaLog(this.e).getLogData()
if (!data) return if (!data) return
let name = `html/gacha/gacha-log` let name = `html/gacha/gacha-log`
if (this.e.isAll) { if (this.e.isAll) {
name = `html/gacha/gacha-all-log` name = `html/gacha/gacha-all-log`
} }
this.reply([await this.renderImg('genshin', name, data, { retType: "base64" }), this.button]) this.reply([await this.renderImg("genshin", name, data, { retType: "base64" }), this.button])
} }
/** 导出记录 */ /** 导出记录 */
async exportLog() { exportLog() {
if (this.e.isGroup) { if (this.e.isGroup && !this.e.msg.includes("强制")) {
await this.reply('请私聊导出', false, { at: true }) return this.reply("建议私聊导出,若你确认要在此导出,请发送【#强制导出记录】", false, { at: true })
return
} }
let exportLog = new ExportLog(this.e) return new ExportLog(this.e).exportJson()
return await exportLog.exportJson()
} }
async logJson() { async logJson() {
if (!this.e.isPrivate) { if (!this.e.file)
await this.e.reply('请私聊发送Json文件', false, { at: true }) return this.e.reply("请发送Json文件")
return true
}
if (!this.e.file) {
await this.e.reply('请发送Json文件')
return true
}
await new ExportLog(this.e).logJson() await new ExportLog(this.e).logJson()
if (this.e.isGroup)
this.e.reply("已收到文件,请撤回", false, { at: true })
} }
async help() { help() {
await this.e.reply([segment.image(`file://${_path}/resources/logHelp/记录帮助.png`), segment.button([ this.e.reply([segment.image(`file://${_path}/resources/logHelp/记录帮助.png`), segment.button([
{ text: "电脑", callback: "#电脑帮助" }, { text: "电脑", callback: "#电脑帮助" },
{ text: "安卓", callback: "#安卓帮助" }, { text: "安卓", callback: "#安卓帮助" },
{ text: "苹果", callback: "#苹果帮助" }, { text: "苹果", callback: "#苹果帮助" },
])]) ])])
} }
async helpPort() { helpPort() {
let msg = this.e.msg.replace(/#|帮助/g, '') let msg = this.e.msg.replace(/#|帮助/g, "")
if (['电脑', 'pc'].includes(msg)) { if (["电脑", "pc"].includes(msg)) {
await this.e.reply(segment.image(`file://${_path}/resources/logHelp/记录帮助-电脑.png`)) this.e.reply(segment.image(`file://${_path}/resources/logHelp/记录帮助-电脑.png`))
} else if (['安卓'].includes(msg)) { } else if (["安卓"].includes(msg)) {
await this.e.reply(`安卓抽卡记录获取教程:${this.androidUrl}`) this.e.reply(`安卓抽卡记录获取教程:${this.androidUrl}`)
} else if (['苹果', 'ios'].includes(msg)) { } else if (["苹果", "ios"].includes(msg)) {
await this.e.reply(segment.image(`file://${_path}/resources/logHelp/记录帮助-苹果.png`)) this.e.reply(segment.image(`file://${_path}/resources/logHelp/记录帮助-苹果.png`))
} }
} }
@ -188,6 +150,6 @@ export class gcLog extends plugin {
let data = await new LogCount(this.e).count() let data = await new LogCount(this.e).count()
if (!data) return if (!data) return
this.reply([await this.renderImg('genshin', `html/gacha/log-count`, data, { retType: "base64" }), this.button]) this.reply([await this.renderImg("genshin", `html/gacha/log-count`, data, { retType: "base64" }), this.button])
} }
} }

View File

@ -91,9 +91,11 @@ export default class ExportLog extends base {
this.e.reply(`导出成功:${this.uid}.json${list.length}\n请接收文件`) this.e.reply(`导出成功:${this.uid}.json${list.length}\n请接收文件`)
await this.e.friend.sendFile(saveFile).catch((err) => { if (this.e.group?.sendFile)
logger.error(`${this.e.logFnc} 发送文件失败 ${JSON.stringify(err)}`) await this.e.group.sendFile(saveFile)
}) else if (this.e.friend?.sendFile)
await this.e.friend.sendFile(saveFile)
else this.e.reply('导出失败:暂不支持发送文件')
/** 删除文件 */ /** 删除文件 */
fs.unlink(saveFile, () => { }) fs.unlink(saveFile, () => { })

View File

@ -1,16 +1,16 @@
import base from './base.js' import base from "./base.js"
import fetch from 'node-fetch' import fetch from "node-fetch"
import lodash from 'lodash' import lodash from "lodash"
import fs from 'node:fs' import fs from "node:fs"
import common from '../../../lib/common/common.js' import common from "../../../lib/common/common.js"
import gsCfg from './gsCfg.js' import gsCfg from "./gsCfg.js"
import GachaData from './gachaData.js' import GachaData from "./gachaData.js"
import { Character, Weapon } from '../../miao-plugin/models/index.js' import { Character, Weapon } from "../../miao-plugin/models/index.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"
if (!e.isSr && e.msg) e.isSr = /\/(common|hkrpg)\//.test(e.msg) if (!e.isSr && e.msg) e.isSr = /\/(common|hkrpg)\//.test(e.msg)
@ -20,38 +20,38 @@ export default class GachaLog extends base {
this.path = this.e.isSr ? `./data/srJson/${this.e.user_id}/` : `./data/gachaJson/${this.e.user_id}/` this.path = this.e.isSr ? `./data/srJson/${this.e.user_id}/` : `./data/gachaJson/${this.e.user_id}/`
const gsPool = [ const gsPool = [
{ type: 301, typeName: '角色' }, { type: 301, typeName: "角色" },
{ type: 302, typeName: '武器' }, { type: 302, typeName: "武器" },
{ type: 200, typeName: '常驻' } { type: 200, typeName: "常驻" }
] ]
const srPool = [ const srPool = [
{ type: 11, typeName: '角色' }, { type: 11, typeName: "角色" },
{ type: 12, typeName: '光锥' }, { type: 12, typeName: "光锥" },
{ type: 1, typeName: '常驻' }, { type: 1, typeName: "常驻" },
{ type: 2, typeName: '新手' } { type: 2, typeName: "新手" }
] ]
this.pool = e.isSr ? srPool : gsPool this.pool = e.isSr ? srPool : gsPool
} }
static getIcon (name, type = 'role', game = '') { static getIcon(name, type = "role", game = "") {
if (type === 'role' || type === '角色') { if (type === "role" || type === "角色") {
let char = Character.get(name, game) let char = Character.get(name, game)
if (!char) { if (!char) {
console.log('not-found-char', name, game) console.log("not-found-char", name, game)
} }
return char?.imgs?.face || '' return char?.imgs?.face || ""
} else if (type === 'weapon' || type === '武器' || type === '光锥') { } else if (type === "weapon" || type === "武器" || type === "光锥") {
let weapon = Weapon.get(name, game) let weapon = Weapon.get(name, game)
if (!weapon) { if (!weapon) {
console.log('not-found-weapon',`[${name}]`, game) console.log("not-found-weapon",`[${name}]`, game)
} }
return weapon?.imgs?.icon || '' return weapon?.imgs?.icon || ""
} }
} }
async logUrl () { async logUrl() {
let url = this.e.msg let url = this.e.msg
/** 处理url */ /** 处理url */
@ -60,11 +60,11 @@ export default class GachaLog extends base {
if (!await this.checkUrl(param)) return if (!await this.checkUrl(param)) return
this.e.reply('链接发送成功,数据获取中... 请耐心等待') this.e.reply("链接发送成功,数据获取中……")
/** 制作合并消息 */ /** 制作合并消息 */
let MakeMsg = [] let MakeMsg = []
let tmpMsg = '' let tmpMsg = ""
/** 按卡池更新记录 */ /** 按卡池更新记录 */
for (let i in this.pool) { for (let i in this.pool) {
this.type = this.pool[i].type this.type = this.pool[i].type
@ -76,7 +76,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${this?.e?.isSr ? '*' : '#'}导出记录】导出记录数据`) 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
@ -89,24 +89,11 @@ export default class GachaLog extends base {
return data return data
} }
async logFile () { dealUrl(url) {
let url = await this.downFile()
if (!url) {
if (this.e?.file?.name.includes('output')) {
await this.e.reply('请先游戏里打开抽卡记录页面,再发送文件')
return true
}
return false
}
this.e.msg = url
return this.logUrl()
}
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]
if (url.includes('index.html?')) url = url.split('index.html?')[1] if (url.includes("index.html?")) url = url.split("index.html?")[1]
// 处理参数 // 处理参数
let arr = new URLSearchParams(url).entries() let arr = new URLSearchParams(url).entries()
@ -117,17 +104,17 @@ export default class GachaLog extends base {
} }
if (!params.authkey) { if (!params.authkey) {
this.e.reply('链接复制错误') this.e.reply("链接复制错误")
return false return false
} }
// 去除#/,#/log // 去除#/,#/log
params.authkey = params.authkey.replace(/#\/|#\/log/g, '') params.authkey = params.authkey.replace(/#\/|#\/log/g, "")
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`
@ -137,12 +124,12 @@ export default class GachaLog extends base {
let ret = await common.downFile(fileUrl, textPath) let ret = await common.downFile(fileUrl, textPath)
if (!ret) { if (!ret) {
this.e.reply('下载日志文件错误') this.e.reply("下载日志文件错误")
return false return false
} }
// 读取txt文件 // 读取txt文件
let txt = fs.readFileSync(textPath, 'utf-8') let txt = fs.readFileSync(textPath, "utf-8")
let url = txt.match(/auth_appid=webview_gacha(.*)hk4e_cn/) let url = txt.match(/auth_appid=webview_gacha(.*)hk4e_cn/)
@ -157,25 +144,25 @@ 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,
authkey: param.authkey, authkey: param.authkey,
region: this.e.isSr ? 'prod_gf_cn' : 'cn_gf01' region: this.e.isSr ? "prod_gf_cn" : "cn_gf01"
}) })
if (!res?.data?.region) { if (!res?.data?.region) {
res = await this.logApi({ res = await this.logApi({
size: 6, size: 6,
authkey: param.authkey, authkey: param.authkey,
region: this.e.isSr ? 'prod_official_usa' : 'os_usa' region: this.e.isSr ? "prod_official_usa" : "os_usa"
}) })
} }
if (res?.data?.region) { if (res?.data?.region) {
param.region = res?.data?.region param.region = res?.data?.region
} else { } else {
await this.e.reply('链接复制错误或已失效') await this.e.reply("链接复制错误或已失效")
return false return false
} }
} }
@ -187,28 +174,28 @@ export default class GachaLog extends base {
}) })
if (res.retcode == -109) { if (res.retcode == -109) {
await this.e.reply('2.3版本后,反馈的链接已无法查询!请用安卓方式获取链接') await this.e.reply("2.3版本后,反馈的链接已无法查询!请用安卓方式获取链接")
return false return false
} }
if (res.retcode == -101) { if (res.retcode == -101) {
await this.e.reply('该链接已失效,请重新进入游戏,重新复制链接') await this.e.reply("该链接已失效,请重新进入游戏,重新复制链接")
return false return false
} }
if (res.retcode == 400) { if (res.retcode == 400) {
await this.e.reply('获取数据错误') await this.e.reply("获取数据错误")
return false return false
} }
if (res.retcode == -100) { if (res.retcode == -100) {
if (this.e.msg.length == 1000) { if (this.e.msg.length == 1000) {
await this.e.reply('输入法限制,链接复制不完整,请更换输入法复制完整链接') await this.e.reply("输入法限制,链接复制不完整,请更换输入法复制完整链接")
return false return false
} }
await this.e.reply('链接不完整,请长按全选复制全部内容(可能输入法复制限制),或者复制的不是历史记录页面链接') await this.e.reply("链接不完整,请长按全选复制全部内容(可能输入法复制限制),或者复制的不是历史记录页面链接")
return false return false
} }
if (res.retcode != 0) { if (res.retcode != 0) {
await this.e.reply('链接复制错误') await this.e.reply("链接复制错误")
return false return false
} }
@ -221,22 +208,22 @@ export default class GachaLog extends base {
return true return true
} else { } else {
await this.e.reply('暂无数据,请等待记录后再查询') await this.e.reply("暂无数据,请等待记录后再查询")
return false return false
} }
} }
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?"
/** 国际服 */ /** 国际服 */
if (!['cn_gf01', 'cn_qd01'].includes(param.region)) { if (!["cn_gf01", "cn_qd01"].includes(param.region)) {
logUrl = 'https://hk4e-api-os.mihoyo.com/event/gacha_info/api/getGachaLog?' logUrl = "https://hk4e-api-os.mihoyo.com/event/gacha_info/api/getGachaLog?"
} }
let logParam = new URLSearchParams({ let logParam = new URLSearchParams({
authkey_ver: 1, authkey_ver: 1,
lang: 'zh-cn', // 只支持简体中文 lang: "zh-cn", // 只支持简体中文
gacha_type: 301, gacha_type: 301,
page: 1, page: 1,
size: 20, size: 20,
@ -244,17 +231,17 @@ export default class GachaLog extends base {
...param ...param
}).toString() }).toString()
if (this.e.isSr) { if (this.e.isSr) {
logUrl = 'https://api-takumi.mihoyo.com/common/gacha_record/api/getGachaLog?' logUrl = "https://api-takumi.mihoyo.com/common/gacha_record/api/getGachaLog?"
if (!['prod_gf_cn', 'prod_qd_cn'].includes(param.region)) { if (!["prod_gf_cn", "prod_qd_cn"].includes(param.region)) {
logUrl = 'https://api-os-takumi.mihoyo.com/common/gacha_record/api/getGachaLog?' logUrl = "https://api-os-takumi.mihoyo.com/common/gacha_record/api/getGachaLog?"
} }
logParam = new URLSearchParams({ logParam = new URLSearchParams({
authkey_ver: 1, authkey_ver: 1,
lang: 'zh-cn', // 只支持简体中文 lang: "zh-cn", // 只支持简体中文
gacha_type: 11, gacha_type: 11,
page: 1, page: 1,
size: 20, size: 20,
game_biz: 'hkrpg_cn', game_biz: "hkrpg_cn",
end_id: 0, end_id: 0,
...param ...param
}).toString() }).toString()
@ -269,7 +256,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
@ -279,7 +266,7 @@ export default class GachaLog extends base {
/** key过期或者没有数据 */ /** key过期或者没有数据 */
if (res.retcode !== 0 || !res?.data?.list || res.data.list.length <= 0) { if (res.retcode !== 0 || !res?.data?.list || res.data.list.length <= 0) {
logger.debug(`${this.e.logFnc} ${res.message || 'error'}`) logger.debug(`${this.e.logFnc} ${res.message || "error"}`)
return false return false
} }
@ -312,7 +299,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,
@ -359,13 +346,13 @@ export default class GachaLog extends base {
} }
// 读取本地json // 读取本地json
readJson () { readJson() {
let logJson = [] let logJson = []
let ids = new Map() 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)) {
// 获取本地数据 进行数据合并 // 获取本地数据 进行数据合并
logJson = JSON.parse(fs.readFileSync(file, 'utf8')) logJson = JSON.parse(fs.readFileSync(file, "utf8"))
for (let val of logJson) { for (let val of logJson) {
if (val.id) { if (val.id) {
ids.set(String(val.id), val.id) ids.set(String(val.id), val.id)
@ -376,7 +363,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)
} }
@ -387,16 +374,16 @@ 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}/`
fs.writeFileSync(`${file}${this.type}.json`, JSON.stringify(data, '', '\t')) fs.writeFileSync(`${file}${this.type}.json`, JSON.stringify(data, "", "\t"))
} }
/** #抽卡记录 */ /** #抽卡记录 */
async getLogData () { async getLogData() {
/** 判断uid */ /** 判断uid */
await this.getUid() await this.getUid()
if (!this.uid) { if (!this.uid) {
@ -409,9 +396,9 @@ 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 = []
let fiveMaxNum = 0 let fiveMaxNum = 0
const originalMsg = this.e.msg const originalMsg = this.e.msg
@ -425,11 +412,11 @@ export default class GachaLog extends base {
if (fiveMaxNum <= data.fiveLog.length) { if (fiveMaxNum <= data.fiveLog.length) {
fiveMaxNum = data.fiveLog.length fiveMaxNum = data.fiveLog.length
} }
data.max = i === '武器' || i === '光锥' ? 80 : 90 data.max = i === "武器" || i === "光锥" ? 80 : 90
logData.push(data) logData.push(data)
} }
if (logData.length === 0) { if (logData.length === 0) {
this.e.reply(`暂无抽卡记录\n${this.e?.isSr ? '*' : '#'}记录帮助,查看配置说明`, false, { at: true }) this.e.reply(`暂无抽卡记录\n${this.e?.isSr ? "*" : "#"}记录帮助,查看配置说明`, false, { at: true })
return true return true
} }
for (let i of logData) { for (let i of logData) {
@ -446,7 +433,7 @@ export default class GachaLog extends base {
return data return data
} }
async getGcLogData () { async getGcLogData() {
/** 卡池 */ /** 卡池 */
const { type, typeName } = this.getPool() const { type, typeName } = this.getPool()
/** 更新记录 */ /** 更新记录 */
@ -460,33 +447,33 @@ 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, "")
let type = this.e.isSr ? 11 : 301 let type = this.e.isSr ? 11 : 301
let typeName = '角色' let typeName = "角色"
switch (msg) { switch (msg) {
case 'up': case "up":
case '抽卡': case "抽卡":
case '角色': case "角色":
case '抽奖': case "抽奖":
type = this.e.isSr ? 11 : 301 type = this.e.isSr ? 11 : 301
typeName = '角色' typeName = "角色"
break break
case '常驻': case "常驻":
type = this.e.isSr ? 1 : 200 type = this.e.isSr ? 1 : 200
typeName = '常驻' typeName = "常驻"
break break
case '武器': case "武器":
type = this.e.isSr ? 12 : 302 type = this.e.isSr ? 12 : 302
typeName = this.e.isSr ? '光锥' : '武器' typeName = this.e.isSr ? "光锥" : "武器"
break break
case '光锥': case "光锥":
type = 12 type = 12
typeName = '光锥' typeName = "光锥"
break break
case '新手': case "新手":
type = this.e.isSr ? 2 : 100 type = this.e.isSr ? 2 : 100
typeName = '新手' typeName = "新手"
break break
} }
this.type = type this.type = type
@ -494,16 +481,16 @@ export default class GachaLog extends base {
return { type, typeName } return { type, typeName }
} }
async getUid () { async getUid() {
if (!fs.existsSync(this.path)) { if (!fs.existsSync(this.path)) {
this.e.reply(`暂无抽卡记录\n${this.e?.isSr ? '*' : '#'}记录帮助,查看配置说明`, 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${this.e?.isSr ? '*' : '#'}记录帮助,查看配置说明`, false, { at: true }) this.e.reply(`暂无抽卡记录\n${this.e?.isSr ? "*" : "#"}记录帮助,查看配置说明`, false, { at: true })
return false return false
} }
@ -545,7 +532,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
} }
@ -577,7 +564,7 @@ export default class GachaLog extends base {
} else { } else {
fourLog[val.name] = 1 fourLog[val.name] = 1
} }
if (val.item_type == '武器' || val.item_type == '光锥') { if (val.item_type == "武器" || val.item_type == "光锥") {
weaponFourNum++ weaponFourNum++
} }
} }
@ -593,7 +580,7 @@ export default class GachaLog extends base {
fiveLogNum = 0 fiveLogNum = 0
let isUp = false let isUp = false
// 歪了多少个 // 歪了多少个
if (val.item_type == '角色') { if (val.item_type == "角色") {
if (this.checkIsUp()) { if (this.checkIsUp()) {
isUp = true isUp = true
} else { } else {
@ -619,7 +606,7 @@ export default class GachaLog extends base {
// 删除未知五星 // 删除未知五星
for (let i in fiveLog) { for (let i in fiveLog) {
if (fiveLog[i].name == '未知') { if (fiveLog[i].name == "未知") {
allNum = allNum - fiveLog[i].num allNum = allNum - fiveLog[i].num
fiveLog.splice(i, 1) fiveLog.splice(i, 1)
fiveNum-- fiveNum--
@ -652,7 +639,7 @@ export default class GachaLog extends base {
}) })
if (four.length <= 0) { if (four.length <= 0) {
four.push({ name: '无', num: 0 }) four.push({ name: "无", num: 0 })
} }
let fiveAvg = 0 let fiveAvg = 0
@ -677,7 +664,7 @@ export default class GachaLog extends base {
let upYs = isvalidNum * 160 let upYs = isvalidNum * 160
if (upYs >= 10000) { if (upYs >= 10000) {
upYs = (upYs / 10000).toFixed(2) + 'w' upYs = (upYs / 10000).toFixed(2) + "w"
} else { } else {
upYs = upYs.toFixed(0) upYs = upYs.toFixed(0)
} }
@ -712,22 +699,22 @@ export default class GachaLog extends base {
} }
} }
checkIsUp () { checkIsUp() {
if (['莫娜', '七七', '迪卢克', '琴', '姬子', '杰帕德', '彦卿', '白露', '瓦尔特', '克拉拉', '布洛妮娅'].includes(this.role.name)) { if (["莫娜", "七七", "迪卢克", "琴", "姬子", "杰帕德", "彦卿", "白露", "瓦尔特", "克拉拉", "布洛妮娅"].includes(this.role.name)) {
return false return false
} }
let role5join = { let role5join = {
刻晴: { 刻晴: {
start: '2021-02-17 18:00:00', start: "2021-02-17 18:00:00",
end: '2021-03-02 15:59:59' end: "2021-03-02 15:59:59"
}, },
提纳里: { 提纳里: {
start: '2022-08-24 06:00:00', start: "2022-08-24 06:00:00",
end: '2022-09-09 17:59:59' end: "2022-09-09 17:59:59"
}, },
迪希雅: { 迪希雅: {
start: '2023-03-01 06:00:00', start: "2023-03-01 06:00:00",
end: '2023-03-21 17:59:59' end: "2023-03-21 17:59:59"
} }
} }
if (lodash.keys(role5join).includes(this.role.name)) { if (lodash.keys(role5join).includes(this.role.name)) {
@ -745,65 +732,65 @@ export default class GachaLog extends base {
} }
/** 渲染数据 */ /** 渲染数据 */
randData (data) { randData(data) {
const type = data.type || this.type const type = data.type || this.type
const typeName = data.typeName || this.typeName const typeName = data.typeName || this.typeName
const max = type === 12 || type === 302 ? 80 : 90 const max = type === 12 || type === 302 ? 80 : 90
let line = [] let line = []
let weapon = this.e.isSr ? '光锥' : '武器' let weapon = this.e.isSr ? "光锥" : "武器"
if ([301, 11].includes(type)) { if ([301, 11].includes(type)) {
line = [[ line = [[
{ lable: '未出五星', num: data.noFiveNum, unit: '抽' }, { lable: "未出五星", num: data.noFiveNum, unit: "抽" },
{ lable: '五星', num: data.fiveNum, unit: '个' }, { lable: "五星", num: data.fiveNum, unit: "个" },
{ lable: '五星平均', num: data.fiveAvg, unit: '抽', color: data.fiveColor }, { lable: "五星平均", num: data.fiveAvg, unit: "抽", color: data.fiveColor },
{ lable: '小保底不歪', num: data.noWaiRate + '%', unit: '' } { lable: "小保底不歪", num: data.noWaiRate + "%", unit: "" }
], [ ], [
{ lable: '未出四星', num: data.noFourNum, unit: '抽' }, { lable: "未出四星", num: data.noFourNum, unit: "抽" },
{ lable: '五星常驻', num: data.wai, unit: '个' }, { lable: "五星常驻", num: data.wai, unit: "个" },
{ lable: 'UP平均', num: data.isvalidNum, unit: '抽' }, { lable: "UP平均", num: data.isvalidNum, unit: "抽" },
{ lable: `UP花费${this?.e?.isSr ? '星琼' : '原石'}`, num: data.upYs, unit: '' } { lable: `UP花费${this?.e?.isSr ? "星琼" : "原石"}`, num: data.upYs, unit: "" }
]] ]]
} }
// 常驻池 // 常驻池
if ([200, 1].includes(type)) { if ([200, 1].includes(type)) {
line = [[ line = [[
{ lable: '未出五星', num: data.noFiveNum, unit: '抽' }, { lable: "未出五星", num: data.noFiveNum, unit: "抽" },
{ lable: '五星', num: data.fiveNum, unit: '个' }, { lable: "五星", num: data.fiveNum, unit: "个" },
{ lable: '五星平均', num: data.fiveAvg, unit: '抽', color: data.fiveColor }, { lable: "五星平均", num: data.fiveAvg, unit: "抽", color: data.fiveColor },
{ lable: `五星${weapon}`, num: data.weaponNum, unit: '个' } { lable: `五星${weapon}`, num: data.weaponNum, unit: "个" }
], [ ], [
{ lable: '未出四星', num: data.noFourNum, unit: '抽' }, { lable: "未出四星", num: data.noFourNum, unit: "抽" },
{ lable: '四星', num: data.fourNum, unit: '个' }, { lable: "四星", num: data.fourNum, unit: "个" },
{ lable: '四星平均', num: data.fourAvg, unit: '抽' }, { lable: "四星平均", num: data.fourAvg, unit: "抽" },
{ lable: '四星最多', num: data.maxFour.num, unit: data.maxFour.name } { lable: "四星最多", num: data.maxFour.num, unit: data.maxFour.name }
]] ]]
} }
// 武器池 // 武器池
if ([302, 12].includes(type)) { if ([302, 12].includes(type)) {
line = [[ line = [[
{ lable: '未出五星', num: data.noFiveNum, unit: '抽' }, { lable: "未出五星", num: data.noFiveNum, unit: "抽" },
{ lable: '五星', num: data.fiveNum, unit: '个' }, { lable: "五星", num: data.fiveNum, unit: "个" },
{ lable: '五星平均', num: data.fiveAvg, unit: '抽', color: data.fiveColor }, { lable: "五星平均", num: data.fiveAvg, unit: "抽", color: data.fiveColor },
{ lable: `四星${weapon}`, num: data.weaponFourNum, unit: '个' } { lable: `四星${weapon}`, num: data.weaponFourNum, unit: "个" }
], [ ], [
{ lable: '未出四星', num: data.noFourNum, unit: '抽' }, { lable: "未出四星", num: data.noFourNum, unit: "抽" },
{ lable: '四星', num: data.fourNum, unit: '个' }, { lable: "四星", num: data.fourNum, unit: "个" },
{ lable: '四星平均', num: data.fourAvg, unit: '抽' }, { lable: "四星平均", num: data.fourAvg, unit: "抽" },
{ lable: '四星最多', num: data.maxFour.num, unit: data.maxFour.name } { lable: "四星最多", num: data.maxFour.num, unit: data.maxFour.name }
]] ]]
} }
// 新手池 // 新手池
if ([100, 2].includes(type)) { if ([100, 2].includes(type)) {
line = [[ line = [[
{ lable: '未出五星', num: data.noFiveNum, unit: '抽' }, { lable: "未出五星", num: data.noFiveNum, unit: "抽" },
{ lable: '五星', num: data.fiveNum, unit: '个' }, { lable: "五星", num: data.fiveNum, unit: "个" },
{ lable: '五星平均', num: data.fiveAvg, unit: '抽', color: data.fiveColor }, { lable: "五星平均", num: data.fiveAvg, unit: "抽", color: data.fiveColor },
{ lable: `五星${weapon}`, num: data.weaponNum, unit: '个' } { lable: `五星${weapon}`, num: data.weaponNum, unit: "个" }
], [ ], [
{ lable: '未出四星', num: data.noFourNum, unit: '抽' }, { lable: "未出四星", num: data.noFourNum, unit: "抽" },
{ lable: '四星', num: data.fourNum, unit: '个' }, { lable: "四星", num: data.fourNum, unit: "个" },
{ lable: '四星平均', num: data.fourAvg, unit: '抽' }, { lable: "四星平均", num: data.fourAvg, unit: "抽" },
{ lable: '四星最多', num: data.maxFour.num, unit: data.maxFour.name } { lable: "四星最多", num: data.maxFour.num, unit: data.maxFour.name }
]] ]]
} }
let hasMore = false let hasMore = false
@ -828,23 +815,23 @@ export default class GachaLog extends base {
} }
} }
getServer () { getServer() {
let uid = this.uid let uid = this.uid
switch (String(uid)[0]) { switch (String(uid)[0]) {
case '1': case "1":
case '2': case "2":
return this.e.isSr ? 'prod_gf_cn' : 'cn_gf01' // 官服 return this.e.isSr ? "prod_gf_cn" : "cn_gf01" // 官服
case '5': case "5":
return this.e.isSr ? 'prod_qd_cn' : 'cn_qd01' // B服 return this.e.isSr ? "prod_qd_cn" : "cn_qd01" // B服
case '6': case "6":
return this.e.isSr ? 'prod_official_usa' : 'os_usa' // 美服 return this.e.isSr ? "prod_official_usa" : "os_usa" // 美服
case '7': case "7":
return this.e.isSr ? 'prod_official_euro' : 'os_euro' // 欧服 return this.e.isSr ? "prod_official_euro" : "os_euro" // 欧服
case '8': case "8":
return this.e.isSr ? 'prod_official_asia' : 'os_asia' // 亚服 return this.e.isSr ? "prod_official_asia" : "os_asia" // 亚服
case '9': case "9":
return this.e.isSr ? 'prod_official_cht' : 'os_cht' // 港澳台服 return this.e.isSr ? "prod_official_cht" : "os_cht" // 港澳台服
} }
return 'cn_gf01' return "cn_gf01"
} }
} }