♻️ 重构成就表格,支持多存档

#126
This commit is contained in:
目棃
2024-09-20 15:57:02 +08:00
parent a8a667871a
commit 1dc5aa0ef8
28 changed files with 1198 additions and 1239 deletions

View File

@@ -1,12 +1,11 @@
/**
* @file plugins/Sqlite/modules/userGacha.ts
* @description 用户祈愿模块
* @since Beta v0.5.1
* @since Beta v0.6.0
*/
import { AppCharacterData, AppWeaponData } from "../../../data/index.js";
import TGSqlite from "../index.js";
import { importUIGFData } from "../sql/updateData.js";
type gachaItemTypeRes =
| ["角色", TGApp.App.Character.WikiBriefInfo]
@@ -27,6 +26,34 @@ function getGachaItemType(item_id: string): gachaItemTypeRes {
return ["未知", "未知"];
}
/**
* @description 获取导入 Sql
* @since Beta v.6.0
* @param {string} uid - UID
* @param {TGApp.Plugins.UIGF.GachaItem} gacha - UIGF数据
* @returns {string}
*/
function getInsertSql(uid: string, gacha: TGApp.Plugins.UIGF.GachaItem): string {
return `
INSERT INTO GachaRecords (uid, gachaType, itemId, count, time, name, type, rank, id, uigfType, updated)
VALUES ('${uid}', '${gacha.gacha_type}', '${gacha.item_id ?? null}', '${gacha.count ?? null}', '${gacha.time}',
'${gacha.name}', '${gacha.item_type ?? null}', '${gacha.rank_type ?? null}', '${gacha.id}',
'${gacha.uigf_gacha_type}', datetime('now', 'localtime'))
ON CONFLICT (id)
DO UPDATE
SET uid = '${uid}',
gachaType = '${gacha.gacha_type}',
uigfType = '${gacha.uigf_gacha_type}',
time = '${gacha.time}',
itemId = '${gacha.item_id ?? null}',
count = '${gacha.count ?? null}',
name = '${gacha.name}',
type = '${gacha.item_type ?? null}',
rank = '${gacha.rank_type ?? null}',
updated = datetime('now', 'localtime');
`;
}
/**
* @description 转换祈愿数据,防止多语言
* @since Beta v0.5.1
@@ -130,7 +157,7 @@ async function mergeUIGF(uid: string, data: TGApp.Plugins.UIGF.GachaItem[]): Pro
const db = await TGSqlite.getDB();
for (const gacha of data) {
const trans = transGacha(gacha);
const sql = importUIGFData(uid, trans);
const sql = getInsertSql(uid, trans);
await db.execute(sql);
}
}
@@ -145,7 +172,7 @@ async function mergeUIGF4(data: TGApp.Plugins.UIGF.GachaHk4e): Promise<void> {
const db = await TGSqlite.getDB();
for (const gacha of data.list) {
const trans = transGacha(gacha);
const sql = importUIGFData(data.uid.toString(), trans);
const sql = getInsertSql(data.uid.toString(), trans);
await db.execute(sql);
}
}