Fourstore commited on
Commit
6393baf
Β·
verified Β·
1 Parent(s): 9b7a20c

Update endpoints/antibot.js

Browse files
Files changed (1) hide show
  1. 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
- if (matchedCount >= 2) {
302
- console.log('πŸ”„ DEBUG: Using fallback matching...');
303
- for (let i = 0; i < result.length; i++) {
304
- if (!result[i].id) {
305
- for (const bot of botResults) {
306
- if (!usedIds.has(bot.id) && bot.value && bot.value.trim() !== '') {
307
- result[i].id = bot.id;
308
- result[i].matchType = 'fallback';
309
- usedIds.add(bot.id);
310
- console.log(`πŸ”„ DEBUG: Soal ${i+1} fallback to bot ${bot.id}`);
311
- break;
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
- for (let i = 0; i < result.length; i++) {
333
- if (!result[i].id) {
334
- result[i].id = 'invalid';
335
- result[i].matchType = 'invalid';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 => ({ id: r.id, matchType: r.matchType, soal: r.soal })),
352
- totalMatches: matchedCount
 
 
 
 
 
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
  };