@@ -5,6 +5,7 @@ import kuroApi from './kuroApi.js'
55import userConfig from './userConfig.js'
66import {
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