koishi-plugin-blacklist-online 0.1.2 → 0.1.4
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/core.js +10 -5
- package/lib/index.js +10 -10
- package/package.json +1 -1
package/lib/core.js
CHANGED
|
@@ -55,12 +55,17 @@ async function syncBlacklist(ctx, config) {
|
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
if (strategy === 'full_replace') {
|
|
58
|
-
logger.info(
|
|
58
|
+
logger.info(`执行全量同步,条数: ${data.length}`);
|
|
59
|
+
// 1. 先清空本地表,确保环境干净
|
|
59
60
|
await ctx.database.remove('blacklist_users', {});
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
// 2. 批量写入。由于我们定义了 primary: 'user_id',这里即便有重复也会直接覆盖
|
|
62
|
+
if (data.length > 0) {
|
|
63
|
+
// 分批处理,防止 SQLite 单次 SQL 语句过长
|
|
64
|
+
const batchSize = 100;
|
|
65
|
+
for (let i = 0; i < data.length; i += batchSize) {
|
|
66
|
+
const batch = data.slice(i, i + batchSize);
|
|
67
|
+
await ctx.database.upsert('blacklist_users', batch);
|
|
68
|
+
}
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
71
|
else if (strategy === 'incremental') {
|
package/lib/index.js
CHANGED
|
@@ -131,12 +131,12 @@ function apply(ctx, config) {
|
|
|
131
131
|
return '❌ 该用户在本地白名单中,无法拉黑。';
|
|
132
132
|
const requestId = (0, node_crypto_1.randomUUID)();
|
|
133
133
|
const payload = {
|
|
134
|
-
|
|
134
|
+
request_id: requestId,
|
|
135
135
|
type: 'ADD',
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
applicant_id: session.userId,
|
|
137
|
+
target_user_id: userId,
|
|
138
138
|
reason,
|
|
139
|
-
|
|
139
|
+
guild_id: session.guildId,
|
|
140
140
|
timestamp: Date.now()
|
|
141
141
|
};
|
|
142
142
|
try {
|
|
@@ -161,10 +161,10 @@ function apply(ctx, config) {
|
|
|
161
161
|
const userId = (0, core_1.parseUserId)(user);
|
|
162
162
|
const requestId = (0, node_crypto_1.randomUUID)();
|
|
163
163
|
const payload = {
|
|
164
|
-
|
|
164
|
+
request_id: requestId,
|
|
165
165
|
type: 'REMOVE',
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
applicant_id: session.userId,
|
|
167
|
+
target_user_id: userId,
|
|
168
168
|
reason,
|
|
169
169
|
timestamp: Date.now()
|
|
170
170
|
};
|
|
@@ -185,9 +185,9 @@ function apply(ctx, config) {
|
|
|
185
185
|
if (!uuid)
|
|
186
186
|
return '请输入要撤回的申请 UUID。';
|
|
187
187
|
const payload = {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
request_id: (0, node_crypto_1.randomUUID)(),
|
|
189
|
+
target_request_id: uuid,
|
|
190
|
+
applicant_id: session?.userId,
|
|
191
191
|
timestamp: Date.now()
|
|
192
192
|
};
|
|
193
193
|
try {
|