Fourstore commited on
Commit
1a0010f
Β·
verified Β·
1 Parent(s): d4eff7e

Update endpoints/antibot.js

Browse files
Files changed (1) hide show
  1. endpoints/antibot.js +36 -3
endpoints/antibot.js CHANGED
@@ -265,6 +265,7 @@ async function antibot(data) {
265
  console.log('πŸ” DEBUG: Starting matching process...');
266
  const result = [];
267
  const usedIds = new Set();
 
268
 
269
  for (let i = 0; i < soalArray.length; i++) {
270
  const targetSoal = soalArray[i];
@@ -276,18 +277,49 @@ async function antibot(data) {
276
  isValueMatch(bot.value, targetSoal)) {
277
  foundId = bot.id;
278
  usedIds.add(bot.id);
 
279
  console.log(`βœ… DEBUG: Soal "${targetSoal}" matched with bot ${bot.id}`);
280
  break;
281
  }
282
  }
283
 
284
  result.push({
285
- id: foundId || 'invalid',
286
  soal: targetSoal,
287
- matchType: foundId ? 'exact' : 'invalid'
288
  });
289
  }
290
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  console.log('πŸŽ‰ DEBUG: Process completed successfully');
292
  console.log('πŸ“‹ DEBUG Final Result:', result);
293
 
@@ -305,7 +337,8 @@ async function antibot(data) {
305
  matchType: r.matchType,
306
  soal: r.soal
307
  })),
308
- totalResults: result.length
 
309
  }
310
  }
311
  };
 
265
  console.log('πŸ” DEBUG: Starting matching process...');
266
  const result = [];
267
  const usedIds = new Set();
268
+ let successfulMatches = 0;
269
 
270
  for (let i = 0; i < soalArray.length; i++) {
271
  const targetSoal = soalArray[i];
 
277
  isValueMatch(bot.value, targetSoal)) {
278
  foundId = bot.id;
279
  usedIds.add(bot.id);
280
+ successfulMatches++;
281
  console.log(`βœ… DEBUG: Soal "${targetSoal}" matched with bot ${bot.id}`);
282
  break;
283
  }
284
  }
285
 
286
  result.push({
287
+ id: foundId,
288
  soal: targetSoal,
289
+ matchType: foundId ? 'exact' : 'none'
290
  });
291
  }
292
 
293
+ console.log(`πŸ“Š DEBUG: Successful matches: ${successfulMatches}`);
294
+
295
+ if (successfulMatches >= 2) {
296
+ console.log('βœ… DEBUG: Minimal 2 match terpenuhi, mengisi slot kosong');
297
+ const unusedBots = botResults.filter(bot => !usedIds.has(bot.id) && bot.value && bot.value.trim() !== '');
298
+
299
+ for (let i = 0; i < result.length; i++) {
300
+ if (!result[i].id && unusedBots.length > 0) {
301
+ const bot = unusedBots.shift();
302
+ result[i].id = bot.id;
303
+ result[i].matchType = 'fallback';
304
+ usedIds.add(bot.id);
305
+ console.log(`πŸ”„ DEBUG: Slot ${i} diisi dengan bot ${bot.id}`);
306
+ }
307
+ }
308
+
309
+ for (let i = 0; i < result.length; i++) {
310
+ if (!result[i].id) {
311
+ result[i].id = 'invalid';
312
+ result[i].matchType = 'invalid';
313
+ }
314
+ }
315
+ } else {
316
+ console.log('❌ DEBUG: Kurang dari 2 match, semua invalid');
317
+ for (let i = 0; i < result.length; i++) {
318
+ result[i].id = 'invalid';
319
+ result[i].matchType = 'invalid';
320
+ }
321
+ }
322
+
323
  console.log('πŸŽ‰ DEBUG: Process completed successfully');
324
  console.log('πŸ“‹ DEBUG Final Result:', result);
325
 
 
337
  matchType: r.matchType,
338
  soal: r.soal
339
  })),
340
+ totalResults: result.length,
341
+ successfulMatches: successfulMatches
342
  }
343
  }
344
  };