Update endpoints/antibot.js
Browse files- endpoints/antibot.js +47 -33
endpoints/antibot.js
CHANGED
|
@@ -43,6 +43,8 @@ function isValueMatch(value, targetSoal) {
|
|
| 43 |
'five': '5', 'six': '6', 'seven': '7', 'eight': '8', 'nine': '9', 'ten': '10',
|
| 44 |
'I': '1', 'II': '2', 'III': '3', 'IV': '4', 'V': '5',
|
| 45 |
'VI': '6', 'VII': '7', 'VIII': '8', 'IX': '9', 'X': '10',
|
|
|
|
|
|
|
| 46 |
'slx': '6', 's1x': '6', 'six': '6',
|
| 47 |
'f0ur': '4', 'f0r': '4', 'fuor': '4',
|
| 48 |
'f1ve': '5', 'fiv': '5', 'f1v': '5',
|
|
@@ -267,57 +269,69 @@ async function antibot(data) {
|
|
| 267 |
const usedIds = new Set();
|
| 268 |
let successfulMatches = 0;
|
| 269 |
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
| 283 |
}
|
| 284 |
}
|
| 285 |
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
}
|
| 292 |
|
| 293 |
console.log(`π DEBUG: Successful matches: ${successfulMatches}`);
|
| 294 |
|
|
|
|
| 295 |
if (successfulMatches >= 2) {
|
| 296 |
-
console.log('β
DEBUG: Minimal 2 match terpenuhi, mengisi
|
| 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 &&
|
| 301 |
-
const bot =
|
| 302 |
result[i].id = bot.id;
|
|
|
|
| 303 |
result[i].matchType = 'fallback';
|
| 304 |
-
|
| 305 |
-
console.log(`π DEBUG: Slot ${i} diisi dengan bot ${bot.id}`);
|
| 306 |
}
|
| 307 |
}
|
|
|
|
| 308 |
|
| 309 |
-
|
| 310 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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');
|
|
|
|
| 43 |
'five': '5', 'six': '6', 'seven': '7', 'eight': '8', 'nine': '9', 'ten': '10',
|
| 44 |
'I': '1', 'II': '2', 'III': '3', 'IV': '4', 'V': '5',
|
| 45 |
'VI': '6', 'VII': '7', 'VIII': '8', 'IX': '9', 'X': '10',
|
| 46 |
+
'i': '1', 'ii': '2', 'iii': '3', 'iv': '4', 'v': '5',
|
| 47 |
+
'vi': '6', 'vii': '7', 'viii': '8', 'ix': '9', 'x': '10',
|
| 48 |
'slx': '6', 's1x': '6', 'six': '6',
|
| 49 |
'f0ur': '4', 'f0r': '4', 'fuor': '4',
|
| 50 |
'f1ve': '5', 'fiv': '5', 'f1v': '5',
|
|
|
|
| 269 |
const usedIds = new Set();
|
| 270 |
let successfulMatches = 0;
|
| 271 |
|
| 272 |
+
// Step 1: Match setiap bot dengan soal yang tersedia
|
| 273 |
+
const availableSoal = [...soalArray];
|
| 274 |
+
|
| 275 |
+
for (const bot of botResults) {
|
| 276 |
+
let matchedSoal = null;
|
| 277 |
+
let matchIndex = -1;
|
| 278 |
+
|
| 279 |
+
if (bot.value && bot.value.trim() !== '') {
|
| 280 |
+
for (let i = 0; i < availableSoal.length; i++) {
|
| 281 |
+
if (isValueMatch(bot.value, availableSoal[i])) {
|
| 282 |
+
matchedSoal = availableSoal[i];
|
| 283 |
+
matchIndex = i;
|
| 284 |
+
successfulMatches++;
|
| 285 |
+
console.log(`β
DEBUG: Bot ${bot.id} matched with soal "${matchedSoal}"`);
|
| 286 |
+
break;
|
| 287 |
+
}
|
| 288 |
}
|
| 289 |
}
|
| 290 |
|
| 291 |
+
if (matchedSoal) {
|
| 292 |
+
result.push({
|
| 293 |
+
id: bot.id,
|
| 294 |
+
soal: matchedSoal,
|
| 295 |
+
matchType: 'exact'
|
| 296 |
+
});
|
| 297 |
+
availableSoal.splice(matchIndex, 1);
|
| 298 |
+
usedIds.add(bot.id);
|
| 299 |
+
} else {
|
| 300 |
+
result.push({
|
| 301 |
+
id: null,
|
| 302 |
+
soal: '',
|
| 303 |
+
matchType: 'none'
|
| 304 |
+
});
|
| 305 |
+
}
|
| 306 |
}
|
| 307 |
|
| 308 |
console.log(`π DEBUG: Successful matches: ${successfulMatches}`);
|
| 309 |
|
| 310 |
+
// Step 2: Jika minimal 2 match, isi bot yang belum match dengan soal tersisa
|
| 311 |
if (successfulMatches >= 2) {
|
| 312 |
+
console.log('β
DEBUG: Minimal 2 match terpenuhi, mengisi bot yang belum match');
|
|
|
|
|
|
|
| 313 |
for (let i = 0; i < result.length; i++) {
|
| 314 |
+
if (!result[i].id && availableSoal.length > 0) {
|
| 315 |
+
const bot = botResults[i];
|
| 316 |
result[i].id = bot.id;
|
| 317 |
+
result[i].soal = availableSoal.shift();
|
| 318 |
result[i].matchType = 'fallback';
|
| 319 |
+
console.log(`π DEBUG: Bot ${bot.id} diisi dengan soal tersisa`);
|
|
|
|
| 320 |
}
|
| 321 |
}
|
| 322 |
+
}
|
| 323 |
|
| 324 |
+
// Step 3: Handle remaining cases
|
| 325 |
+
for (let i = 0; i < result.length; i++) {
|
| 326 |
+
if (!result[i].id) {
|
| 327 |
+
if (successfulMatches >= 2) {
|
| 328 |
+
result[i].id = botResults[i].id;
|
| 329 |
+
result[i].matchType = 'qualified';
|
| 330 |
+
} else {
|
| 331 |
result[i].id = 'invalid';
|
| 332 |
result[i].matchType = 'invalid';
|
| 333 |
}
|
| 334 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
}
|
| 336 |
|
| 337 |
console.log('π DEBUG: Process completed successfully');
|