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

Update endpoints/antibot.js

Browse files
Files changed (1) hide show
  1. endpoints/antibot.js +54 -60
endpoints/antibot.js CHANGED
@@ -174,12 +174,21 @@ function evaluateSimpleMath(expression) {
174
 
175
  function parseSoalText(text) {
176
  console.log(`πŸ“ DEBUG parseSoalText: Input text: "${text}"`);
 
 
 
177
  const delimiters = /[.,:;\\/\s]+/;
178
- let parts = text.split(delimiters).filter(part => part.trim() !== '');
 
 
 
179
  if (parts.length === 1) {
180
- parts = text.split(/\s+/).filter(part => part.trim() !== '');
 
 
181
  }
182
- console.log(`πŸ“ DEBUG parseSoalText: Parsed parts:`, parts);
 
183
  return parts;
184
  }
185
 
@@ -246,16 +255,27 @@ async function antibot(data) {
246
  console.log('πŸ” DEBUG: Starting matching process...');
247
  const result = [];
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}"`);
255
  let foundId = null;
256
 
257
  for (const bot of botResults) {
258
- if (!usedIds.has(bot.id) && bot.value && bot.value.trim() !== '' &&
259
  isValueMatch(bot.value, targetSoal)) {
260
  foundId = bot.id;
261
  usedIds.add(bot.id);
@@ -274,70 +294,43 @@ async function antibot(data) {
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++) {
281
- if (!result[i].id) {
282
- const targetSoal = soalArray[i];
283
- const normalizedSoal = normalizeText(targetSoal);
284
-
285
- for (const bot of botResults) {
286
- if (!usedIds.has(bot.id) && bot.normalized && bot.normalized.trim() !== '') {
287
- if (bot.normalized === normalizedSoal) {
288
- result[i].id = bot.id;
289
- result[i].matchType = 'normalized';
290
- usedIds.add(bot.id);
291
- matchedCount++;
292
- console.log(`βœ… DEBUG: Soal "${targetSoal}" normalized match with bot ${bot.id}`);
293
- break;
294
- }
295
- }
296
- }
297
- }
298
- }
299
- }
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
 
343
  console.log('πŸŽ‰ DEBUG: Process completed successfully');
@@ -358,7 +351,8 @@ async function antibot(data) {
358
  soal: r.soal
359
  })),
360
  totalMatches: matchedCount,
361
- totalResults: result.length
 
362
  }
363
  }
364
  };
 
174
 
175
  function parseSoalText(text) {
176
  console.log(`πŸ“ DEBUG parseSoalText: Input text: "${text}"`);
177
+
178
+ const ignoreWords = ['hi', 'how', 'are', 'you', 'hello', 'hey'];
179
+
180
  const delimiters = /[.,:;\\/\s]+/;
181
+ let parts = text.split(delimiters)
182
+ .filter(part => part.trim() !== '')
183
+ .filter(part => !ignoreWords.includes(part.toLowerCase()));
184
+
185
  if (parts.length === 1) {
186
+ parts = text.split(/\s+/)
187
+ .filter(part => part.trim() !== '')
188
+ .filter(part => !ignoreWords.includes(part.toLowerCase()));
189
  }
190
+
191
+ console.log(`πŸ“ DEBUG parseSoalText: Filtered parts:`, parts);
192
  return parts;
193
  }
194
 
 
255
  console.log('πŸ” DEBUG: Starting matching process...');
256
  const result = [];
257
  const usedIds = new Set();
 
258
 
259
+ const botAnswerCounts = {};
260
+ botResults.forEach(bot => {
261
+ if (bot.value && bot.value.trim() !== '') {
262
+ const answers = bot.value.split(/[\s,]+/).filter(a => a.trim() !== '');
263
+ botAnswerCounts[bot.id] = answers.length;
264
+ console.log(`πŸ”’ DEBUG Bot ${bot.id}: ${answers.length} jawaban - [${answers.join(', ')}]`);
265
+ } else {
266
+ botAnswerCounts[bot.id] = 0;
267
+ console.log(`πŸ”’ DEBUG Bot ${bot.id}: 0 jawaban`);
268
+ }
269
+ });
270
+
271
+ let matchedCount = 0;
272
  for (let i = 0; i < soalArray.length; i++) {
273
  const targetSoal = soalArray[i];
274
  console.log(`🎯 DEBUG: Matching soal "${targetSoal}"`);
275
  let foundId = null;
276
 
277
  for (const bot of botResults) {
278
+ if (!usedIds.has(bot.id) && botAnswerCounts[bot.id] >= 2 && bot.value && bot.value.trim() !== '' &&
279
  isValueMatch(bot.value, targetSoal)) {
280
  foundId = bot.id;
281
  usedIds.add(bot.id);
 
294
 
295
  console.log(`πŸ“Š DEBUG: Initial matches: ${matchedCount}/${soalArray.length}`);
296
 
297
+ const qualifiedBots = botResults.filter(bot => botAnswerCounts[bot.id] >= 2 && !usedIds.has(bot.id));
298
+ console.log(`βž• DEBUG: Qualified bots to add: ${qualifiedBots.length}`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
 
300
+ for (const bot of qualifiedBots) {
301
+ result.push({
302
+ id: bot.id,
303
+ soal: '',
304
+ matchType: 'qualified'
305
+ });
306
+ usedIds.add(bot.id);
307
+ console.log(`βž• DEBUG: Added qualified bot ${bot.id} to result`);
308
  }
309
 
310
+ const invalidBots = botResults.filter(bot => botAnswerCounts[bot.id] === 1 && !usedIds.has(bot.id));
311
+ console.log(`❌ DEBUG: Invalid bots (1 jawaban): ${invalidBots.length}`);
 
312
 
313
+ for (const bot of invalidBots) {
314
  result.push({
315
  id: bot.id,
316
  soal: '',
317
+ matchType: 'invalid'
318
  });
319
  usedIds.add(bot.id);
320
+ console.log(`❌ DEBUG: Added invalid bot ${bot.id} to result`);
321
  }
322
 
323
+ const noAnswerBots = botResults.filter(bot => botAnswerCounts[bot.id] === 0 && !usedIds.has(bot.id));
324
+ console.log(`❌ DEBUG: No answer bots: ${noAnswerBots.length}`);
325
+
326
+ for (const bot of noAnswerBots) {
327
+ result.push({
328
+ id: bot.id,
329
+ soal: '',
330
+ matchType: 'invalid'
331
+ });
332
+ usedIds.add(bot.id);
333
+ console.log(`❌ DEBUG: Added no-answer bot ${bot.id} to result`);
334
  }
335
 
336
  console.log('πŸŽ‰ DEBUG: Process completed successfully');
 
351
  soal: r.soal
352
  })),
353
  totalMatches: matchedCount,
354
+ totalResults: result.length,
355
+ answerCounts: botAnswerCounts
356
  }
357
  }
358
  };