Skip to content

Commit de38519

Browse files
committed
feat: UIGF的抽卡数据的导出
1 parent 20eec84 commit de38519

File tree

5 files changed

+72
-5
lines changed

5 files changed

+72
-5
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ git -C ./plugins/Yunzai-Kuro-Plugin/ pull
8484
### 查询相关
8585

8686
- [x] 库街区角色墙信息及 UID 切换 `#战双卡片` `#鸣潮卡片2` (鸣潮卡片样式仍在施工中)
87-
- [x] 鸣潮抽卡记录 `#鸣潮抽卡帮助` `鸣潮角色记录` `鸣潮常驻武器记录` `#鸣潮更新抽卡` (记录网页样式仍在施工中)
87+
- [x] 鸣潮抽卡记录 `#鸣潮抽卡帮助` `鸣潮角色记录` `鸣潮常驻武器记录` `#鸣潮更新抽卡` `#鸣潮导出抽卡`([UIGF](https://uigf.org/))
8888

8989
### 小工具
9090

@@ -106,8 +106,9 @@ git -C ./plugins/Yunzai-Kuro-Plugin/ pull
106106

107107
- [x] 通过链接上传抽卡记录
108108
- [x] 抽卡记录分析的展示
109-
- [ ] 从本地上传抽卡记录
110-
- [ ] [UIGF](https://uigf.org/) 格式的抽卡记录的导入与导出
109+
- [ ] ~~从本地上传抽卡记录~~库洛已加鉴权, 白写了
110+
- [x] [UIGF](https://uigf.org/) 格式的抽卡记录的导出
111+
- [ ] ~~[UIGF](https://uigf.org/) 格式的抽卡记录的导入~~我的协议不支持, 不会写
111112

112113
- [ ] 鸣潮 / 战双体力查询, 通知
113114

apps/mcGacha.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import puppeteer from '../../../lib/puppeteer/puppeteer.js'
55
import mcGachaCard from '../model/mcGachaCard.js'
66
import kuroLogger from '../components/logger.js'
77
import userConfig from '../model/userConfig.js'
8+
import fs from 'fs'
89

910
export class mcGacha extends plugin {
1011
constructor() {
@@ -46,6 +47,10 @@ export class mcGacha extends plugin {
4647
reg: '^#?鸣潮更新(抽卡|唤取)+(记录)?$',
4748
fnc: 'mcGachaDataUpdate',
4849
},
50+
{
51+
reg: '^#?鸣潮导出(抽卡|唤取)+(记录)?$',
52+
fnc: 'mcGachaDataExport',
53+
},
4954
],
5055
})
5156
}
@@ -154,7 +159,7 @@ export class mcGacha extends plugin {
154159
}
155160

156161
async mcGachaHelpLocalGet(e) {
157-
// TODO: 该方法疑似失效
162+
// 该方法已经失效
158163
e.reply(
159164
'该方法已失效~ \n(没错, 小丑开发者写了一下午, 都基本写完了, 才发现库洛把这玩意修了)'
160165
)
@@ -237,4 +242,17 @@ export class mcGacha extends plugin {
237242
}
238243
}
239244
}
245+
246+
async mcGachaDataExport(e) {
247+
let gacha = new mcGachaData(e)
248+
let gachaExportRet = await gacha.export()
249+
if (typeof gachaExportRet === 'string') {
250+
await e.reply(`导出失败: \n${gachaExportRet}`)
251+
return true
252+
} else {
253+
let msg = '以上是你的 UIGF 鸣潮抽卡记录, 你可以导入其他支持 UIGF 的工具中使用~'
254+
await e.reply(msg)
255+
return true
256+
}
257+
}
240258
}

data/system/pluginConstants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export const _CfgPath = `${process // 绝对目录
3131
.cwd()
3232
.replace(/\\/g, '/')}/plugins/${pluginName}/config`
3333
export const mcGachaDataPath = dataPath + '/gachaData/mc'
34+
export const _McGachaDataPath = `${process // 绝对目录
35+
.cwd()
36+
.replace(/\\/g, '/')}/plugins/${pluginName}/data/gachaData/mc`
3437

3538
// 其它信息
3639
export const pluginThemeColor = chalk.rgb(57, 197, 187)

data/system/yaml/help.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@
3838
- icon: mingchao
3939
title: "#鸣潮更新抽卡"
4040
desc: 上传链接后更新鸣潮抽卡记录
41+
- icon: mingchao
42+
title: "#鸣潮导出抽卡"
43+
desc: 以UIGF导出获取到的抽卡记录

model/mcGachaData.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import kuroApi from './kuroApi.js'
55
import userConfig from './userConfig.js'
66
import {
77
mcGachaDataPath,
8+
_McGachaDataPath,
89
pluginName,
910
pluginVer,
1011
} from '../data/system/pluginConstants.js'
@@ -42,7 +43,7 @@ export default class mcGachaData {
4243
// 先检查本地是否既没有抽卡记录也没有抽卡链接, 如果没有就提示获取抽卡记录
4344
if (!(await this.exist(this.e.user_id, gameUid)) && !gachaLink) {
4445
await this.e.reply(
45-
`QQ ${this.e.user_id} 的游戏 uid ${gameUid} 暂未获取抽卡记录\n请发送 #鸣潮抽卡记录帮助 以获取记录`
46+
`QQ ${this.e.user_id}${gameUid ? ` 的游戏 uid ${gameUid}` : ''} 暂未获取过抽卡记录\n请发送 #鸣潮抽卡记录帮助 以获取帮助信息`
4647
)
4748
return false
4849
}
@@ -405,4 +406,45 @@ export default class mcGachaData {
405406
return '提取抽卡记录失败: ' + error.message
406407
}
407408
}
409+
410+
/** 以 UIGF 格式发送抽卡记录
411+
* @returns {null|string} 保存成功返回 null, 失败返回 str 原因
412+
*/
413+
async export() {
414+
// 检查用户是否有抽卡记录
415+
let user = new userConfig()
416+
let gameUid = (await user.getCurGameUidLocal(this.e.user_id, 3))?.gameUid
417+
if (!gameUid) {
418+
return `QQ ${this.e.user_id}${gameUid ? ` 的游戏 uid ${gameUid}` : ''} 暂未获取过抽卡记录\n请发送 #鸣潮抽卡记录帮助 以获取帮助信息`
419+
}
420+
let path = `${mcGachaDataPath}/${this.e.user_id}-${gameUid}.json`
421+
if (!fs.existsSync(path)) {
422+
return `QQ ${this.e.user_id} 的游戏 uid ${gameUid} 本地不存在抽卡记录\n请发送 #鸣潮更新抽卡 以获取`
423+
}
424+
// 复制一份抽卡记录到临时文件
425+
let time = new Date().toISOString().replace(/[-:]/g, '').replace(/\..+/, '').replace('T', '')
426+
let tempPath = `WW_${_McGachaDataPath}/${gameUid}-${time}.json`
427+
try {
428+
fs.copyFileSync(path, tempPath)
429+
if (this.e.isGroup) {
430+
let ret = await this.e.group.sendFile(tempPath)
431+
fs.unlinkSync(tempPath)
432+
if(ret !== null) {
433+
return `文件发送失败, 可能是协议不支持`
434+
}
435+
return null;
436+
} else if (this.e.isPrivate) {
437+
let ret = await this.e.friend.sendFile(tempPath)
438+
fs.unlinkSync(tempPath)
439+
if(ret !== null) {
440+
return `文件发送失败, 可能是协议不支持`
441+
}
442+
return null;
443+
} else {
444+
return `不支持的消息来源, 请尝试好友私聊或群聊使用`
445+
}
446+
} catch (error) {
447+
return `抽卡记录文件复制失败: ${JSON.stringify(error)}`
448+
}
449+
}
408450
}

0 commit comments

Comments
 (0)