koishi-plugin-aka-ai-generator 0.6.13 → 0.6.15
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 +21 -7
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1056,8 +1056,12 @@ var UserManager = class {
|
|
|
1056
1056
|
}
|
|
1057
1057
|
// 批量更新用户数据 (用于充值)
|
|
1058
1058
|
async updateUsersBatch(updates) {
|
|
1059
|
+
await this.loadUsersData();
|
|
1059
1060
|
await this.dataLock.acquire(async () => {
|
|
1060
|
-
|
|
1061
|
+
if (!this.usersCache) {
|
|
1062
|
+
this.logger.error("updateUsersBatch: usersCache 为空,这不应该发生");
|
|
1063
|
+
this.usersCache = {};
|
|
1064
|
+
}
|
|
1061
1065
|
updates(this.usersCache);
|
|
1062
1066
|
await this.saveUsersDataInternal();
|
|
1063
1067
|
});
|
|
@@ -1158,20 +1162,26 @@ var UserManager = class {
|
|
|
1158
1162
|
return { ...rateLimitCheck };
|
|
1159
1163
|
}
|
|
1160
1164
|
this.updateRateLimit(userId);
|
|
1165
|
+
await this.loadUsersData();
|
|
1166
|
+
const userData = await this.getUserData(userId, userName);
|
|
1161
1167
|
return await this.dataLock.acquire(async () => {
|
|
1162
|
-
|
|
1168
|
+
if (!this.usersCache) {
|
|
1169
|
+
this.logger.error("checkAndReserveQuota: usersCache 为空,这不应该发生");
|
|
1170
|
+
this.usersCache = {};
|
|
1171
|
+
}
|
|
1172
|
+
const cachedUserData = this.usersCache[userId] || userData;
|
|
1163
1173
|
const today = (/* @__PURE__ */ new Date()).toDateString();
|
|
1164
|
-
const lastReset = new Date(
|
|
1165
|
-
let dailyCount =
|
|
1174
|
+
const lastReset = new Date(cachedUserData.lastDailyReset || cachedUserData.createdAt).toDateString();
|
|
1175
|
+
let dailyCount = cachedUserData.dailyUsageCount;
|
|
1166
1176
|
if (today !== lastReset) {
|
|
1167
1177
|
dailyCount = 0;
|
|
1168
1178
|
}
|
|
1169
1179
|
const remainingToday = Math.max(0, config.dailyFreeLimit - dailyCount);
|
|
1170
|
-
const totalAvailable = remainingToday +
|
|
1180
|
+
const totalAvailable = remainingToday + cachedUserData.remainingPurchasedCount;
|
|
1171
1181
|
if (totalAvailable < numImages) {
|
|
1172
1182
|
return {
|
|
1173
1183
|
allowed: false,
|
|
1174
|
-
message: `生成 ${numImages} 张图片需要 ${numImages} 次可用次数,但您的可用次数不足(今日免费剩余:${remainingToday}次,充值剩余:${
|
|
1184
|
+
message: `生成 ${numImages} 张图片需要 ${numImages} 次可用次数,但您的可用次数不足(今日免费剩余:${remainingToday}次,充值剩余:${cachedUserData.remainingPurchasedCount}次,共${totalAvailable}次)`
|
|
1175
1185
|
};
|
|
1176
1186
|
}
|
|
1177
1187
|
const reservationId = `${userId}_${Date.now()}_${Math.random()}`;
|
|
@@ -1180,8 +1190,12 @@ var UserManager = class {
|
|
|
1180
1190
|
}
|
|
1181
1191
|
// 扣减额度并记录使用
|
|
1182
1192
|
async consumeQuota(userId, userName, commandName, numImages, config) {
|
|
1193
|
+
await this.loadUsersData();
|
|
1183
1194
|
return await this.dataLock.acquire(async () => {
|
|
1184
|
-
|
|
1195
|
+
if (!this.usersCache) {
|
|
1196
|
+
this.logger.error("consumeQuota: usersCache 为空,这不应该发生");
|
|
1197
|
+
this.usersCache = {};
|
|
1198
|
+
}
|
|
1185
1199
|
let userData = this.usersCache[userId];
|
|
1186
1200
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1187
1201
|
const today = (/* @__PURE__ */ new Date()).toDateString();
|