koishi-plugin-aka-ai-generator 0.6.11 → 0.6.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +22 -10
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1538,7 +1538,7 @@ function apply(ctx, config) {
|
|
|
1538
1538
|
充值剩余:${userData.remainingPurchasedCount}次`;
|
|
1539
1539
|
}
|
|
1540
1540
|
__name(buildStatsMessage, "buildStatsMessage");
|
|
1541
|
-
async function recordUserUsage(session, commandName, numImages = 1) {
|
|
1541
|
+
async function recordUserUsage(session, commandName, numImages = 1, sendStatsImmediately = true) {
|
|
1542
1542
|
const userId = session.userId;
|
|
1543
1543
|
const userName = session.username || session.userId || "未知用户";
|
|
1544
1544
|
if (!userId) return;
|
|
@@ -1556,11 +1556,23 @@ function apply(ctx, config) {
|
|
|
1556
1556
|
remainingPurchasedCount: userData.remainingPurchasedCount,
|
|
1557
1557
|
isAdmin: userManager.isAdmin(userId, config)
|
|
1558
1558
|
});
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1559
|
+
if (sendStatsImmediately) {
|
|
1560
|
+
try {
|
|
1561
|
+
const statsMessage = buildStatsMessage(userData, numImages, consumptionType, freeUsed, purchasedUsed, config);
|
|
1562
|
+
await session.send(statsMessage);
|
|
1563
|
+
} catch (error) {
|
|
1564
|
+
logger.warn("发送统计信息失败", { userId, error: sanitizeError(error) });
|
|
1565
|
+
}
|
|
1566
|
+
} else {
|
|
1567
|
+
setImmediate(async () => {
|
|
1568
|
+
try {
|
|
1569
|
+
const statsMessage = buildStatsMessage(userData, numImages, consumptionType, freeUsed, purchasedUsed, config);
|
|
1570
|
+
await session.send(statsMessage);
|
|
1571
|
+
logger.debug("统计信息已异步发送", { userId, commandName });
|
|
1572
|
+
} catch (error) {
|
|
1573
|
+
logger.warn("异步发送统计信息失败", { userId, error: sanitizeError(error) });
|
|
1574
|
+
}
|
|
1575
|
+
});
|
|
1564
1576
|
}
|
|
1565
1577
|
}
|
|
1566
1578
|
__name(recordUserUsage, "recordUserUsage");
|
|
@@ -1819,7 +1831,7 @@ ${infoParts.join("\n")}`;
|
|
|
1819
1831
|
creditDeducted = true;
|
|
1820
1832
|
logger.info("准备扣除积分", { userId, totalImages: total, currentIndex: index });
|
|
1821
1833
|
try {
|
|
1822
|
-
await recordUserUsage(session, styleName, total);
|
|
1834
|
+
await recordUserUsage(session, styleName, total, false);
|
|
1823
1835
|
logger.info("流式处理:第一张图片生成,积分已扣除", {
|
|
1824
1836
|
userId,
|
|
1825
1837
|
totalImages: total,
|
|
@@ -1872,7 +1884,7 @@ ${infoParts.join("\n")}`;
|
|
|
1872
1884
|
return "图像处理失败:未能生成图片";
|
|
1873
1885
|
}
|
|
1874
1886
|
if (!creditDeducted) {
|
|
1875
|
-
await recordUserUsage(session, styleName, images.length);
|
|
1887
|
+
await recordUserUsage(session, styleName, images.length, false);
|
|
1876
1888
|
logger.warn("流式处理:积分在最后扣除(异常情况)", { userId, imagesCount: images.length });
|
|
1877
1889
|
}
|
|
1878
1890
|
await session.send("图像处理完成!");
|
|
@@ -2053,7 +2065,7 @@ Prompt: ${prompt}`);
|
|
|
2053
2065
|
creditDeducted = true;
|
|
2054
2066
|
logger.info("准备扣除积分 (COMPOSE_IMAGE)", { userId, totalImages: total, currentIndex: index });
|
|
2055
2067
|
try {
|
|
2056
|
-
await recordUserUsage(session, COMMANDS.COMPOSE_IMAGE, total);
|
|
2068
|
+
await recordUserUsage(session, COMMANDS.COMPOSE_IMAGE, total, false);
|
|
2057
2069
|
logger.info("流式处理:第一张图片生成,积分已扣除 (COMPOSE_IMAGE)", {
|
|
2058
2070
|
userId,
|
|
2059
2071
|
totalImages: total,
|
|
@@ -2106,7 +2118,7 @@ Prompt: ${prompt}`);
|
|
|
2106
2118
|
return "图片合成失败:未能生成图片";
|
|
2107
2119
|
}
|
|
2108
2120
|
if (!creditDeducted) {
|
|
2109
|
-
await recordUserUsage(session, COMMANDS.COMPOSE_IMAGE, resultImages.length);
|
|
2121
|
+
await recordUserUsage(session, COMMANDS.COMPOSE_IMAGE, resultImages.length, false);
|
|
2110
2122
|
logger.warn("流式处理:积分在最后扣除(异常情况)", { userId, imagesCount: resultImages.length });
|
|
2111
2123
|
}
|
|
2112
2124
|
await session.send("图片合成完成!");
|