Update endpoints/antibot.js
Browse files- endpoints/antibot.js +43 -34
endpoints/antibot.js
CHANGED
|
@@ -248,6 +248,7 @@ async function antibot(data) {
|
|
| 248 |
const usedIds = new Set();
|
| 249 |
let matchedCount = 0;
|
| 250 |
|
|
|
|
| 251 |
for (let i = 0; i < soalArray.length; i++) {
|
| 252 |
const targetSoal = soalArray[i];
|
| 253 |
console.log(`π― DEBUG: Matching soal "${targetSoal}"`);
|
|
@@ -273,6 +274,7 @@ async function antibot(data) {
|
|
| 273 |
|
| 274 |
console.log(`π DEBUG: Initial matches: ${matchedCount}/${soalArray.length}`);
|
| 275 |
|
|
|
|
| 276 |
if (matchedCount < soalArray.length) {
|
| 277 |
console.log('π DEBUG: Trying normalized matching...');
|
| 278 |
for (let i = 0; i < result.length; i++) {
|
|
@@ -298,41 +300,43 @@ async function antibot(data) {
|
|
| 298 |
|
| 299 |
console.log(`π DEBUG: After normalized: ${matchedCount}/${soalArray.length}`);
|
| 300 |
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
}
|
| 313 |
-
}
|
| 314 |
-
}
|
| 315 |
-
}
|
| 316 |
-
} else if (matchedCount === 1) {
|
| 317 |
-
console.log('β οΈ DEBUG: Only 1 match found, marking others as invalid');
|
| 318 |
-
for (let i = 0; i < result.length; i++) {
|
| 319 |
-
if (!result[i].id) {
|
| 320 |
-
result[i].id = 'invalid';
|
| 321 |
-
result[i].matchType = 'invalid';
|
| 322 |
-
}
|
| 323 |
-
}
|
| 324 |
-
} else {
|
| 325 |
-
console.log('β DEBUG: No matches found, all invalid');
|
| 326 |
-
for (let i = 0; i < result.length; i++) {
|
| 327 |
-
result[i].id = 'invalid';
|
| 328 |
-
result[i].matchType = 'invalid';
|
| 329 |
}
|
| 330 |
}
|
| 331 |
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
}
|
| 337 |
}
|
| 338 |
|
|
@@ -348,8 +352,13 @@ async function antibot(data) {
|
|
| 348 |
result: result.map(r => ({ id: r.id })),
|
| 349 |
debug: {
|
| 350 |
parsedSoal: soalArray,
|
| 351 |
-
matches: result.map(r => ({
|
| 352 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
}
|
| 354 |
}
|
| 355 |
};
|
|
|
|
| 248 |
const usedIds = new Set();
|
| 249 |
let matchedCount = 0;
|
| 250 |
|
| 251 |
+
// Step 1: Exact matching dengan soal
|
| 252 |
for (let i = 0; i < soalArray.length; i++) {
|
| 253 |
const targetSoal = soalArray[i];
|
| 254 |
console.log(`π― DEBUG: Matching soal "${targetSoal}"`);
|
|
|
|
| 274 |
|
| 275 |
console.log(`π DEBUG: Initial matches: ${matchedCount}/${soalArray.length}`);
|
| 276 |
|
| 277 |
+
// Step 2: Jika masih ada soal yang belum dapat match, coba normalized matching
|
| 278 |
if (matchedCount < soalArray.length) {
|
| 279 |
console.log('π DEBUG: Trying normalized matching...');
|
| 280 |
for (let i = 0; i < result.length; i++) {
|
|
|
|
| 300 |
|
| 301 |
console.log(`π DEBUG: After normalized: ${matchedCount}/${soalArray.length}`);
|
| 302 |
|
| 303 |
+
// Step 3: Jika masih ada bot yang belum digunakan, assign ke soal yang belum ada jawaban
|
| 304 |
+
const unusedBots = botResults.filter(bot => !usedIds.has(bot.id) && bot.value && bot.value.trim() !== '');
|
| 305 |
+
console.log(`π DEBUG: Unused bots: ${unusedBots.length}`);
|
| 306 |
+
|
| 307 |
+
for (let i = 0; i < result.length; i++) {
|
| 308 |
+
if (!result[i].id && unusedBots.length > 0) {
|
| 309 |
+
const bot = unusedBots.shift();
|
| 310 |
+
result[i].id = bot.id;
|
| 311 |
+
result[i].matchType = 'fallback';
|
| 312 |
+
usedIds.add(bot.id);
|
| 313 |
+
console.log(`π DEBUG: Soal ${i+1} fallback to bot ${bot.id}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
}
|
| 315 |
}
|
| 316 |
|
| 317 |
+
// Step 4: Jika masih ada bot yang belum digunakan, buat result tambahan
|
| 318 |
+
const remainingBots = botResults.filter(bot => !usedIds.has(bot.id) && bot.value && bot.value.trim() !== '');
|
| 319 |
+
console.log(`β DEBUG: Remaining bots to add: ${remainingBots.length}`);
|
| 320 |
+
|
| 321 |
+
for (const bot of remainingBots) {
|
| 322 |
+
result.push({
|
| 323 |
+
id: bot.id,
|
| 324 |
+
soal: '',
|
| 325 |
+
matchType: 'extra'
|
| 326 |
+
});
|
| 327 |
+
usedIds.add(bot.id);
|
| 328 |
+
console.log(`β DEBUG: Added extra bot ${bot.id} to result`);
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
// Step 5: Handle kasus dimana tidak ada match sama sekali
|
| 332 |
+
if (result.length === 0) {
|
| 333 |
+
console.log('β DEBUG: No matches found, all invalid');
|
| 334 |
+
for (let i = 0; i < soalArray.length; i++) {
|
| 335 |
+
result.push({
|
| 336 |
+
id: 'invalid',
|
| 337 |
+
soal: soalArray[i],
|
| 338 |
+
matchType: 'invalid'
|
| 339 |
+
});
|
| 340 |
}
|
| 341 |
}
|
| 342 |
|
|
|
|
| 352 |
result: result.map(r => ({ id: r.id })),
|
| 353 |
debug: {
|
| 354 |
parsedSoal: soalArray,
|
| 355 |
+
matches: result.map(r => ({
|
| 356 |
+
id: r.id,
|
| 357 |
+
matchType: r.matchType,
|
| 358 |
+
soal: r.soal
|
| 359 |
+
})),
|
| 360 |
+
totalMatches: matchedCount,
|
| 361 |
+
totalResults: result.length
|
| 362 |
}
|
| 363 |
}
|
| 364 |
};
|