From c1ff63b7a8d4a5d8a8462b2ab05d05776bcb004f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=8C?= Date: Fri, 5 Jan 2024 14:46:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E5=9C=A8=E7=BE=A4=E8=81=8A=E6=93=8D=E4=BD=9C=E6=8A=BD=E5=8D=A1?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/apps/gcLog.js | 148 +++++-------- plugins/genshin/model/exportLog.js | 8 +- plugins/genshin/model/gachaLog.js | 323 ++++++++++++++--------------- 3 files changed, 215 insertions(+), 264 deletions(-) diff --git a/plugins/genshin/apps/gcLog.js b/plugins/genshin/apps/gcLog.js index 23d5048..e427ef3 100644 --- a/plugins/genshin/apps/gcLog.js +++ b/plugins/genshin/apps/gcLog.js @@ -1,55 +1,51 @@ -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' +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' +const _path = process.cwd() + "/plugins/genshin" export class gcLog extends plugin { constructor() { super({ - name: '抽卡记录', - dsc: '抽卡记录数据统计', - event: 'message', + name: "抽卡记录", + dsc: "抽卡记录数据统计", + event: "message", priority: 300, rule: [ { - reg: '(.*)authkey=(.*)', - fnc: 'logUrl' + reg: "(.*)authkey=(.*)", + fnc: "logUrl" }, { - reg: '^#txt日志文件导入记录$', - fnc: 'logFile' + reg: "^#json文件导入记录$", + fnc: "logJson" }, { - reg: '^#json文件导入记录$', - fnc: 'logJson' + reg: "^#?(原神|星铁)?(全部)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥|全部)池*(记录|祈愿|分析)$", + fnc: "getLog" }, { - reg: '^#*(原神|星铁)?(全部)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥|全部)池*(记录|祈愿|分析)$', - fnc: 'getLog' + reg: "^#?(原神|星铁)?(强制)?导出记录(json)?$", + fnc: "exportLog" }, { - reg: '^#*(原神|星铁)?导出记录(json)?$', - fnc: 'exportLog' + reg: "^#?(记录帮助|抽卡帮助)$", + fnc: "help" }, { - reg: '^#*(记录帮助|抽卡帮助)$', - fnc: 'help' + reg: "^#?(安卓|苹果|电脑|pc|ios)帮助$", + fnc: "helpPort" }, { - reg: '^#*(安卓|苹果|电脑|pc|ios)帮助$', - fnc: 'helpPort' - }, - { - reg: '^#*(原神|星铁)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥)池*统计$', - 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() { this.prefix = this.e?.isSr ? "*" : "#" return segment.button([ @@ -66,7 +62,7 @@ export class gcLog extends plugin { } 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) { if (!fs.existsSync(i)) { fs.mkdirSync(i) @@ -75,112 +71,78 @@ export class gcLog extends plugin { } accept() { - if (this.e.file && this.e.isPrivate) { + if (this.e.file) { 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文件导入记录' + this.e.msg = "#json文件导入记录" return true } } - if (this.e.msg && /^#*(角色|武器)统计$/g.test(this.e.msg)) { - this.e.msg = this.e.msg.replace('统计', '池统计') + if (this.e.msg && /^#?(角色|武器)统计$/g.test(this.e.msg)) { + this.e.msg = this.e.msg.replace("统计", "池统计") return true } } /** 抽卡记录链接 */ async logUrl() { - if (!this.e.isPrivate) { - this.e.reply('请私聊发送链接', false, { at: true }) - return true - } - let data = await new GachaLog(this.e).logUrl() if (!data) return - await this.renderImg('genshin', `html/gacha/gacha-log`, data) - } + await this.renderImg("genshin", `html/gacha/gacha-log`, data) - /** 发送output_log.txt日志文件 */ - async logFile() { - 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]) + if (this.e.isGroup) + this.e.reply("已收到链接,请撤回", false, { at: true }) } /** #抽卡记录 */ async getLog() { - this.e.isAll = !!(this.e.msg.includes('全部')) + this.e.isAll = !!(this.e.msg.includes("全部")) let data = await new GachaLog(this.e).getLogData() if (!data) return let name = `html/gacha/gacha-log` if (this.e.isAll) { 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() { - if (this.e.isGroup) { - await this.reply('请私聊导出', false, { at: true }) - return + exportLog() { + if (this.e.isGroup && !this.e.msg.includes("强制")) { + return this.reply("建议私聊导出,若你确认要在此导出,请发送【#强制导出记录】", false, { at: true }) } - let exportLog = new ExportLog(this.e) - return await exportLog.exportJson() + return new ExportLog(this.e).exportJson() } async logJson() { - if (!this.e.isPrivate) { - await this.e.reply('请私聊发送Json文件', false, { at: true }) - return true - } - - if (!this.e.file) { - await this.e.reply('请发送Json文件') - return true - } + if (!this.e.file) + return this.e.reply("请发送Json文件") await new ExportLog(this.e).logJson() + + if (this.e.isGroup) + this.e.reply("已收到文件,请撤回", false, { at: true }) } - async help() { - await this.e.reply([segment.image(`file://${_path}/resources/logHelp/记录帮助.png`), segment.button([ + help() { + this.e.reply([segment.image(`file://${_path}/resources/logHelp/记录帮助.png`), segment.button([ { text: "电脑", callback: "#电脑帮助" }, { text: "安卓", callback: "#安卓帮助" }, { text: "苹果", callback: "#苹果帮助" }, ])]) } - async helpPort() { - let msg = this.e.msg.replace(/#|帮助/g, '') + helpPort() { + let msg = this.e.msg.replace(/#|帮助/g, "") - if (['电脑', 'pc'].includes(msg)) { - await this.e.reply(segment.image(`file://${_path}/resources/logHelp/记录帮助-电脑.png`)) - } else if (['安卓'].includes(msg)) { - await this.e.reply(`安卓抽卡记录获取教程:${this.androidUrl}`) - } else if (['苹果', 'ios'].includes(msg)) { - await this.e.reply(segment.image(`file://${_path}/resources/logHelp/记录帮助-苹果.png`)) + if (["电脑", "pc"].includes(msg)) { + this.e.reply(segment.image(`file://${_path}/resources/logHelp/记录帮助-电脑.png`)) + } else if (["安卓"].includes(msg)) { + this.e.reply(`安卓抽卡记录获取教程:${this.androidUrl}`) + } else if (["苹果", "ios"].includes(msg)) { + 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() 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]) } -} +} \ No newline at end of file diff --git a/plugins/genshin/model/exportLog.js b/plugins/genshin/model/exportLog.js index 9bfef28..db047d6 100644 --- a/plugins/genshin/model/exportLog.js +++ b/plugins/genshin/model/exportLog.js @@ -91,9 +91,11 @@ export default class ExportLog extends base { this.e.reply(`导出成功:${this.uid}.json,共${list.length}条 \n请接收文件`) - await this.e.friend.sendFile(saveFile).catch((err) => { - logger.error(`${this.e.logFnc} 发送文件失败 ${JSON.stringify(err)}`) - }) + if (this.e.group?.sendFile) + 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, () => { }) diff --git a/plugins/genshin/model/gachaLog.js b/plugins/genshin/model/gachaLog.js index 1e13fed..e1a3049 100644 --- a/plugins/genshin/model/gachaLog.js +++ b/plugins/genshin/model/gachaLog.js @@ -1,16 +1,16 @@ -import base from './base.js' -import fetch from 'node-fetch' -import lodash from 'lodash' -import fs from 'node:fs' -import common from '../../../lib/common/common.js' -import gsCfg from './gsCfg.js' -import GachaData from './gachaData.js' -import { Character, Weapon } from '../../miao-plugin/models/index.js' +import base from "./base.js" +import fetch from "node-fetch" +import lodash from "lodash" +import fs from "node:fs" +import common from "../../../lib/common/common.js" +import gsCfg from "./gsCfg.js" +import GachaData from "./gachaData.js" +import { Character, Weapon } from "../../miao-plugin/models/index.js" export default class GachaLog extends base { - constructor (e) { + constructor(e) { super(e) - this.model = 'gachaLog' + this.model = "gachaLog" 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}/` const gsPool = [ - { type: 301, typeName: '角色' }, - { type: 302, typeName: '武器' }, - { type: 200, typeName: '常驻' } + { type: 301, typeName: "角色" }, + { type: 302, typeName: "武器" }, + { type: 200, typeName: "常驻" } ] const srPool = [ - { type: 11, typeName: '角色' }, - { type: 12, typeName: '光锥' }, - { type: 1, typeName: '常驻' }, - { type: 2, typeName: '新手' } + { type: 11, typeName: "角色" }, + { type: 12, typeName: "光锥" }, + { type: 1, typeName: "常驻" }, + { type: 2, typeName: "新手" } ] this.pool = e.isSr ? srPool : gsPool } - static getIcon (name, type = 'role', game = '') { - if (type === 'role' || type === '角色') { + static getIcon(name, type = "role", game = "") { + if (type === "role" || type === "角色") { let char = Character.get(name, game) if (!char) { - console.log('not-found-char', name, game) + console.log("not-found-char", name, game) } - return char?.imgs?.face || '' - } else if (type === 'weapon' || type === '武器' || type === '光锥') { + return char?.imgs?.face || "" + } else if (type === "weapon" || type === "武器" || type === "光锥") { let weapon = Weapon.get(name, game) 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 /** 处理url */ @@ -60,11 +60,11 @@ export default class GachaLog extends base { if (!await this.checkUrl(param)) return - this.e.reply('链接发送成功,数据获取中... 请耐心等待') + this.e.reply("链接发送成功,数据获取中……") /** 制作合并消息 */ let MakeMsg = [] - let tmpMsg = '' + let tmpMsg = "" /** 按卡池更新记录 */ for (let i in this.pool) { this.type = this.pool[i].type @@ -76,7 +76,7 @@ export default class GachaLog extends base { if (i <= 1) await common.sleep(500) } 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) this.isLogUrl = true @@ -89,24 +89,11 @@ export default class GachaLog extends base { return data } - async logFile () { - 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) { + dealUrl(url) { // timestamp=1641338980〈=zh-cn 修复链接有奇怪符号 - url = url.replace(/〈=/g, '&') - if (url.includes('getGachaLog?')) url = url.split('getGachaLog?')[1] - if (url.includes('index.html?')) url = url.split('index.html?')[1] + url = url.replace(/〈=/g, "&") + if (url.includes("getGachaLog?")) url = url.split("getGachaLog?")[1] + if (url.includes("index.html?")) url = url.split("index.html?")[1] // 处理参数 let arr = new URLSearchParams(url).entries() @@ -117,17 +104,17 @@ export default class GachaLog extends base { } if (!params.authkey) { - this.e.reply('链接复制错误') + this.e.reply("链接复制错误") return false } // 去除#/,#/log - params.authkey = params.authkey.replace(/#\/|#\/log/g, '') + params.authkey = params.authkey.replace(/#\/|#\/log/g, "") return params } - async downFile () { + async downFile() { this.creatFile() let textPath = `${this.path}output_log.txt` @@ -137,12 +124,12 @@ export default class GachaLog extends base { let ret = await common.downFile(fileUrl, textPath) if (!ret) { - this.e.reply('下载日志文件错误') + this.e.reply("下载日志文件错误") return false } // 读取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/) @@ -157,25 +144,25 @@ export default class GachaLog extends base { return url[0] } - async checkUrl (param) { + async checkUrl(param) { if (!param.region) { let res = await this.logApi({ size: 6, 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) { res = await this.logApi({ size: 6, 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) { param.region = res?.data?.region } else { - await this.e.reply('链接复制错误或已失效') + await this.e.reply("链接复制错误或已失效") return false } } @@ -187,28 +174,28 @@ export default class GachaLog extends base { }) if (res.retcode == -109) { - await this.e.reply('2.3版本后,反馈的链接已无法查询!请用安卓方式获取链接') + await this.e.reply("2.3版本后,反馈的链接已无法查询!请用安卓方式获取链接") return false } if (res.retcode == -101) { - await this.e.reply('该链接已失效,请重新进入游戏,重新复制链接') + await this.e.reply("该链接已失效,请重新进入游戏,重新复制链接") return false } if (res.retcode == 400) { - await this.e.reply('获取数据错误') + await this.e.reply("获取数据错误") return false } if (res.retcode == -100) { if (this.e.msg.length == 1000) { - await this.e.reply('输入法限制,链接复制不完整,请更换输入法复制完整链接') + await this.e.reply("输入法限制,链接复制不完整,请更换输入法复制完整链接") return false } - await this.e.reply('链接不完整,请长按全选复制全部内容(可能输入法复制限制),或者复制的不是历史记录页面链接') + await this.e.reply("链接不完整,请长按全选复制全部内容(可能输入法复制限制),或者复制的不是历史记录页面链接") return false } if (res.retcode != 0) { - await this.e.reply('链接复制错误') + await this.e.reply("链接复制错误") return false } @@ -221,22 +208,22 @@ export default class GachaLog extends base { return true } else { - await this.e.reply('暂无数据,请等待记录后再查询') + await this.e.reply("暂无数据,请等待记录后再查询") 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)) { - logUrl = 'https://hk4e-api-os.mihoyo.com/event/gacha_info/api/getGachaLog?' + if (!["cn_gf01", "cn_qd01"].includes(param.region)) { + logUrl = "https://hk4e-api-os.mihoyo.com/event/gacha_info/api/getGachaLog?" } let logParam = new URLSearchParams({ authkey_ver: 1, - lang: 'zh-cn', // 只支持简体中文 + lang: "zh-cn", // 只支持简体中文 gacha_type: 301, page: 1, size: 20, @@ -244,17 +231,17 @@ export default class GachaLog extends base { ...param }).toString() if (this.e.isSr) { - logUrl = 'https://api-takumi.mihoyo.com/common/gacha_record/api/getGachaLog?' - 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-takumi.mihoyo.com/common/gacha_record/api/getGachaLog?" + if (!["prod_gf_cn", "prod_qd_cn"].includes(param.region)) { + logUrl = "https://api-os-takumi.mihoyo.com/common/gacha_record/api/getGachaLog?" } logParam = new URLSearchParams({ authkey_ver: 1, - lang: 'zh-cn', // 只支持简体中文 + lang: "zh-cn", // 只支持简体中文 gacha_type: 11, page: 1, size: 20, - game_biz: 'hkrpg_cn', + game_biz: "hkrpg_cn", end_id: 0, ...param }).toString() @@ -269,7 +256,7 @@ export default class GachaLog extends base { } /** 更新抽卡记录 */ - async updateLog () { + async updateLog() { /** 获取authkey */ let authkey = await redis.get(`${this.urlKey}${this.uid}`) if (!authkey) return false @@ -279,7 +266,7 @@ export default class GachaLog extends base { /** key过期,或者没有数据 */ 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 } @@ -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({ gacha_type: this.type, page, @@ -359,13 +346,13 @@ export default class GachaLog extends base { } // 读取本地json - readJson () { + readJson() { let logJson = [] let ids = new Map() let file = `${this.path}/${this.uid}/${this.type}.json` if (fs.existsSync(file)) { // 获取本地数据 进行数据合并 - logJson = JSON.parse(fs.readFileSync(file, 'utf8')) + logJson = JSON.parse(fs.readFileSync(file, "utf8")) for (let val of logJson) { if (val.id) { ids.set(String(val.id), val.id) @@ -376,7 +363,7 @@ export default class GachaLog extends base { return { list: logJson, ids } } - creatFile () { + creatFile() { if (!fs.existsSync(this.path)) { fs.mkdirSync(this.path) } @@ -387,16 +374,16 @@ export default class GachaLog extends base { } } - writeJson (data) { + writeJson(data) { this.creatFile() 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 */ await this.getUid() if (!this.uid) { @@ -409,9 +396,9 @@ export default class GachaLog extends base { } } - async getAllGcLogData () { - this.model = 'gachaAllLog' - const poolList = ['角色', this.e?.isSr ? '光锥' : '武器', '常驻'] + async getAllGcLogData() { + this.model = "gachaAllLog" + const poolList = ["角色", this.e?.isSr ? "光锥" : "武器", "常驻"] const logData = [] let fiveMaxNum = 0 const originalMsg = this.e.msg @@ -425,11 +412,11 @@ export default class GachaLog extends base { if (fiveMaxNum <= data.fiveLog.length) { fiveMaxNum = data.fiveLog.length } - data.max = i === '武器' || i === '光锥' ? 80 : 90 + data.max = i === "武器" || i === "光锥" ? 80 : 90 logData.push(data) } 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 } for (let i of logData) { @@ -446,7 +433,7 @@ export default class GachaLog extends base { return data } - async getGcLogData () { + async getGcLogData() { /** 卡池 */ const { type, typeName } = this.getPool() /** 更新记录 */ @@ -460,33 +447,33 @@ export default class GachaLog extends base { return data } - getPool () { - let msg = this.e.msg.replace(/#|抽卡|记录|祈愿|分析|池|原神|星铁|崩坏星穹铁道|铁道/g, '') + getPool() { + let msg = this.e.msg.replace(/#|抽卡|记录|祈愿|分析|池|原神|星铁|崩坏星穹铁道|铁道/g, "") let type = this.e.isSr ? 11 : 301 - let typeName = '角色' + let typeName = "角色" switch (msg) { - case 'up': - case '抽卡': - case '角色': - case '抽奖': + case "up": + case "抽卡": + case "角色": + case "抽奖": type = this.e.isSr ? 11 : 301 - typeName = '角色' + typeName = "角色" break - case '常驻': + case "常驻": type = this.e.isSr ? 1 : 200 - typeName = '常驻' + typeName = "常驻" break - case '武器': + case "武器": type = this.e.isSr ? 12 : 302 - typeName = this.e.isSr ? '光锥' : '武器' + typeName = this.e.isSr ? "光锥" : "武器" break - case '光锥': + case "光锥": type = 12 - typeName = '光锥' + typeName = "光锥" break - case '新手': + case "新手": type = this.e.isSr ? 2 : 100 - typeName = '新手' + typeName = "新手" break } this.type = type @@ -494,16 +481,16 @@ export default class GachaLog extends base { return { type, typeName } } - async getUid () { + async getUid() { 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 } let logs = fs.readdirSync(this.path) 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 } @@ -545,7 +532,7 @@ export default class GachaLog extends base { } /** 统计计算记录 */ - analyse () { + analyse() { if (lodash.isEmpty(this.all)) { this.all = this.readJson().list } @@ -577,7 +564,7 @@ export default class GachaLog extends base { } else { fourLog[val.name] = 1 } - if (val.item_type == '武器' || val.item_type == '光锥') { + if (val.item_type == "武器" || val.item_type == "光锥") { weaponFourNum++ } } @@ -593,7 +580,7 @@ export default class GachaLog extends base { fiveLogNum = 0 let isUp = false // 歪了多少个 - if (val.item_type == '角色') { + if (val.item_type == "角色") { if (this.checkIsUp()) { isUp = true } else { @@ -619,7 +606,7 @@ export default class GachaLog extends base { // 删除未知五星 for (let i in fiveLog) { - if (fiveLog[i].name == '未知') { + if (fiveLog[i].name == "未知") { allNum = allNum - fiveLog[i].num fiveLog.splice(i, 1) fiveNum-- @@ -652,7 +639,7 @@ export default class GachaLog extends base { }) if (four.length <= 0) { - four.push({ name: '无', num: 0 }) + four.push({ name: "无", num: 0 }) } let fiveAvg = 0 @@ -677,7 +664,7 @@ export default class GachaLog extends base { let upYs = isvalidNum * 160 if (upYs >= 10000) { - upYs = (upYs / 10000).toFixed(2) + 'w' + upYs = (upYs / 10000).toFixed(2) + "w" } else { upYs = upYs.toFixed(0) } @@ -712,22 +699,22 @@ export default class GachaLog extends base { } } - checkIsUp () { - if (['莫娜', '七七', '迪卢克', '琴', '姬子', '杰帕德', '彦卿', '白露', '瓦尔特', '克拉拉', '布洛妮娅'].includes(this.role.name)) { + checkIsUp() { + if (["莫娜", "七七", "迪卢克", "琴", "姬子", "杰帕德", "彦卿", "白露", "瓦尔特", "克拉拉", "布洛妮娅"].includes(this.role.name)) { return false } let role5join = { 刻晴: { - start: '2021-02-17 18:00:00', - end: '2021-03-02 15:59:59' + start: "2021-02-17 18:00:00", + end: "2021-03-02 15:59:59" }, 提纳里: { - start: '2022-08-24 06:00:00', - end: '2022-09-09 17:59:59' + start: "2022-08-24 06:00:00", + end: "2022-09-09 17:59:59" }, 迪希雅: { - start: '2023-03-01 06:00:00', - end: '2023-03-21 17:59:59' + start: "2023-03-01 06:00:00", + end: "2023-03-21 17:59:59" } } 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 typeName = data.typeName || this.typeName const max = type === 12 || type === 302 ? 80 : 90 let line = [] - let weapon = this.e.isSr ? '光锥' : '武器' + let weapon = this.e.isSr ? "光锥" : "武器" if ([301, 11].includes(type)) { line = [[ - { lable: '未出五星', num: data.noFiveNum, unit: '抽' }, - { lable: '五星', num: data.fiveNum, unit: '个' }, - { lable: '五星平均', num: data.fiveAvg, unit: '抽', color: data.fiveColor }, - { lable: '小保底不歪', num: data.noWaiRate + '%', unit: '' } + { lable: "未出五星", num: data.noFiveNum, unit: "抽" }, + { lable: "五星", num: data.fiveNum, unit: "个" }, + { lable: "五星平均", num: data.fiveAvg, unit: "抽", color: data.fiveColor }, + { lable: "小保底不歪", num: data.noWaiRate + "%", unit: "" } ], [ - { lable: '未出四星', num: data.noFourNum, unit: '抽' }, - { lable: '五星常驻', num: data.wai, unit: '个' }, - { lable: 'UP平均', num: data.isvalidNum, unit: '抽' }, - { lable: `UP花费${this?.e?.isSr ? '星琼' : '原石'}`, num: data.upYs, unit: '' } + { lable: "未出四星", num: data.noFourNum, unit: "抽" }, + { lable: "五星常驻", num: data.wai, unit: "个" }, + { lable: "UP平均", num: data.isvalidNum, unit: "抽" }, + { lable: `UP花费${this?.e?.isSr ? "星琼" : "原石"}`, num: data.upYs, unit: "" } ]] } // 常驻池 if ([200, 1].includes(type)) { line = [[ - { lable: '未出五星', num: data.noFiveNum, unit: '抽' }, - { lable: '五星', num: data.fiveNum, unit: '个' }, - { lable: '五星平均', num: data.fiveAvg, unit: '抽', color: data.fiveColor }, - { lable: `五星${weapon}`, num: data.weaponNum, unit: '个' } + { lable: "未出五星", num: data.noFiveNum, unit: "抽" }, + { lable: "五星", num: data.fiveNum, unit: "个" }, + { lable: "五星平均", num: data.fiveAvg, unit: "抽", color: data.fiveColor }, + { lable: `五星${weapon}`, num: data.weaponNum, unit: "个" } ], [ - { lable: '未出四星', num: data.noFourNum, unit: '抽' }, - { lable: '四星', num: data.fourNum, unit: '个' }, - { lable: '四星平均', num: data.fourAvg, unit: '抽' }, - { lable: '四星最多', num: data.maxFour.num, unit: data.maxFour.name } + { lable: "未出四星", num: data.noFourNum, unit: "抽" }, + { lable: "四星", num: data.fourNum, unit: "个" }, + { lable: "四星平均", num: data.fourAvg, unit: "抽" }, + { lable: "四星最多", num: data.maxFour.num, unit: data.maxFour.name } ]] } // 武器池 if ([302, 12].includes(type)) { line = [[ - { lable: '未出五星', num: data.noFiveNum, unit: '抽' }, - { lable: '五星', num: data.fiveNum, unit: '个' }, - { lable: '五星平均', num: data.fiveAvg, unit: '抽', color: data.fiveColor }, - { lable: `四星${weapon}`, num: data.weaponFourNum, unit: '个' } + { lable: "未出五星", num: data.noFiveNum, unit: "抽" }, + { lable: "五星", num: data.fiveNum, unit: "个" }, + { lable: "五星平均", num: data.fiveAvg, unit: "抽", color: data.fiveColor }, + { lable: `四星${weapon}`, num: data.weaponFourNum, unit: "个" } ], [ - { lable: '未出四星', num: data.noFourNum, unit: '抽' }, - { lable: '四星', num: data.fourNum, unit: '个' }, - { lable: '四星平均', num: data.fourAvg, unit: '抽' }, - { lable: '四星最多', num: data.maxFour.num, unit: data.maxFour.name } + { lable: "未出四星", num: data.noFourNum, unit: "抽" }, + { lable: "四星", num: data.fourNum, unit: "个" }, + { lable: "四星平均", num: data.fourAvg, unit: "抽" }, + { lable: "四星最多", num: data.maxFour.num, unit: data.maxFour.name } ]] } // 新手池 if ([100, 2].includes(type)) { line = [[ - { lable: '未出五星', num: data.noFiveNum, unit: '抽' }, - { lable: '五星', num: data.fiveNum, unit: '个' }, - { lable: '五星平均', num: data.fiveAvg, unit: '抽', color: data.fiveColor }, - { lable: `五星${weapon}`, num: data.weaponNum, unit: '个' } + { lable: "未出五星", num: data.noFiveNum, unit: "抽" }, + { lable: "五星", num: data.fiveNum, unit: "个" }, + { lable: "五星平均", num: data.fiveAvg, unit: "抽", color: data.fiveColor }, + { lable: `五星${weapon}`, num: data.weaponNum, unit: "个" } ], [ - { lable: '未出四星', num: data.noFourNum, unit: '抽' }, - { lable: '四星', num: data.fourNum, unit: '个' }, - { lable: '四星平均', num: data.fourAvg, unit: '抽' }, - { lable: '四星最多', num: data.maxFour.num, unit: data.maxFour.name } + { lable: "未出四星", num: data.noFourNum, unit: "抽" }, + { lable: "四星", num: data.fourNum, unit: "个" }, + { lable: "四星平均", num: data.fourAvg, unit: "抽" }, + { lable: "四星最多", num: data.maxFour.num, unit: data.maxFour.name } ]] } let hasMore = false @@ -828,23 +815,23 @@ export default class GachaLog extends base { } } - getServer () { + getServer() { let uid = this.uid switch (String(uid)[0]) { - case '1': - case '2': - return this.e.isSr ? 'prod_gf_cn' : 'cn_gf01' // 官服 - case '5': - return this.e.isSr ? 'prod_qd_cn' : 'cn_qd01' // B服 - case '6': - return this.e.isSr ? 'prod_official_usa' : 'os_usa' // 美服 - case '7': - return this.e.isSr ? 'prod_official_euro' : 'os_euro' // 欧服 - case '8': - return this.e.isSr ? 'prod_official_asia' : 'os_asia' // 亚服 - case '9': - return this.e.isSr ? 'prod_official_cht' : 'os_cht' // 港澳台服 + case "1": + case "2": + return this.e.isSr ? "prod_gf_cn" : "cn_gf01" // 官服 + case "5": + return this.e.isSr ? "prod_qd_cn" : "cn_qd01" // B服 + case "6": + return this.e.isSr ? "prod_official_usa" : "os_usa" // 美服 + case "7": + return this.e.isSr ? "prod_official_euro" : "os_euro" // 欧服 + case "8": + return this.e.isSr ? "prod_official_asia" : "os_asia" // 亚服 + case "9": + return this.e.isSr ? "prod_official_cht" : "os_cht" // 港澳台服 } - return 'cn_gf01' + return "cn_gf01" } }