Update endpoints/antibot.js
Browse files- endpoints/antibot.js +23 -39
endpoints/antibot.js
CHANGED
|
@@ -175,20 +175,30 @@ function evaluateSimpleMath(expression) {
|
|
| 175 |
function parseSoalText(text) {
|
| 176 |
console.log(`π DEBUG parseSoalText: Input text: "${text}"`);
|
| 177 |
|
| 178 |
-
const ignoreWords = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 ===
|
| 186 |
parts = text.split(/\s+/)
|
| 187 |
.filter(part => part.trim() !== '')
|
| 188 |
.filter(part => !ignoreWords.includes(part.toLowerCase()));
|
| 189 |
}
|
| 190 |
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
return parts;
|
| 193 |
}
|
| 194 |
|
|
@@ -255,27 +265,15 @@ async function antibot(data) {
|
|
| 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) &&
|
| 279 |
isValueMatch(bot.value, targetSoal)) {
|
| 280 |
foundId = bot.id;
|
| 281 |
usedIds.add(bot.id);
|
|
@@ -294,35 +292,22 @@ async function antibot(data) {
|
|
| 294 |
|
| 295 |
console.log(`π DEBUG: Initial matches: ${matchedCount}/${soalArray.length}`);
|
| 296 |
|
| 297 |
-
const
|
| 298 |
-
console.log(`β DEBUG:
|
| 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 |
-
|
| 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: '
|
| 318 |
});
|
| 319 |
usedIds.add(bot.id);
|
| 320 |
-
console.log(`
|
| 321 |
}
|
| 322 |
|
| 323 |
-
const noAnswerBots = botResults.filter(bot =>
|
| 324 |
console.log(`β DEBUG: No answer bots: ${noAnswerBots.length}`);
|
| 325 |
-
|
| 326 |
for (const bot of noAnswerBots) {
|
| 327 |
result.push({
|
| 328 |
id: bot.id,
|
|
@@ -351,8 +336,7 @@ async function antibot(data) {
|
|
| 351 |
soal: r.soal
|
| 352 |
})),
|
| 353 |
totalMatches: matchedCount,
|
| 354 |
-
totalResults: result.length
|
| 355 |
-
answerCounts: botAnswerCounts
|
| 356 |
}
|
| 357 |
}
|
| 358 |
};
|
|
|
|
| 175 |
function parseSoalText(text) {
|
| 176 |
console.log(`π DEBUG parseSoalText: Input text: "${text}"`);
|
| 177 |
|
| 178 |
+
const ignoreWords = [
|
| 179 |
+
'hi', 'how', 'are', 'you', 'hello', 'hey',
|
| 180 |
+
'tentu', 'berikut', 'adalah', 'teks', 'dari', 'gambar',
|
| 181 |
+
'dipisahkan', 'sesuai', 'permintaan', 'anda', 'hanya',
|
| 182 |
+
'berikan', 'jangan', 'tambahkan', 'kata', 'apapun', 'seperti',
|
| 183 |
+
'atau', 'penjelasan', 'lain', 'saja'
|
| 184 |
+
];
|
| 185 |
|
| 186 |
const delimiters = /[.,:;\\/\s]+/;
|
| 187 |
let parts = text.split(delimiters)
|
| 188 |
.filter(part => part.trim() !== '')
|
| 189 |
.filter(part => !ignoreWords.includes(part.toLowerCase()));
|
| 190 |
|
| 191 |
+
if (parts.length === 0) {
|
| 192 |
parts = text.split(/\s+/)
|
| 193 |
.filter(part => part.trim() !== '')
|
| 194 |
.filter(part => !ignoreWords.includes(part.toLowerCase()));
|
| 195 |
}
|
| 196 |
|
| 197 |
+
parts = parts.filter(part => part.length <= 3 || !isNaN(part));
|
| 198 |
+
|
| 199 |
+
parts = parts.slice(0, 3);
|
| 200 |
+
|
| 201 |
+
console.log(`π DEBUG parseSoalText: Filtered parts (max 3):`, parts);
|
| 202 |
return parts;
|
| 203 |
}
|
| 204 |
|
|
|
|
| 265 |
console.log('π DEBUG: Starting matching process...');
|
| 266 |
const result = [];
|
| 267 |
const usedIds = new Set();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
let matchedCount = 0;
|
| 269 |
+
|
| 270 |
for (let i = 0; i < soalArray.length; i++) {
|
| 271 |
const targetSoal = soalArray[i];
|
| 272 |
console.log(`π― DEBUG: Matching soal "${targetSoal}"`);
|
| 273 |
let foundId = null;
|
| 274 |
|
| 275 |
for (const bot of botResults) {
|
| 276 |
+
if (!usedIds.has(bot.id) && bot.value && bot.value.trim() !== '' &&
|
| 277 |
isValueMatch(bot.value, targetSoal)) {
|
| 278 |
foundId = bot.id;
|
| 279 |
usedIds.add(bot.id);
|
|
|
|
| 292 |
|
| 293 |
console.log(`π DEBUG: Initial matches: ${matchedCount}/${soalArray.length}`);
|
| 294 |
|
| 295 |
+
const unmatchedBots = botResults.filter(bot => !usedIds.has(bot.id) && bot.value && bot.value.trim() !== '');
|
| 296 |
+
console.log(`β DEBUG: Unmatched bots with answers: ${unmatchedBots.length}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
+
for (const bot of unmatchedBots) {
|
|
|
|
|
|
|
|
|
|
| 299 |
result.push({
|
| 300 |
id: bot.id,
|
| 301 |
soal: '',
|
| 302 |
+
matchType: 'unmatched'
|
| 303 |
});
|
| 304 |
usedIds.add(bot.id);
|
| 305 |
+
console.log(`β DEBUG: Added unmatched bot ${bot.id} to result`);
|
| 306 |
}
|
| 307 |
|
| 308 |
+
const noAnswerBots = botResults.filter(bot => !usedIds.has(bot.id));
|
| 309 |
console.log(`β DEBUG: No answer bots: ${noAnswerBots.length}`);
|
| 310 |
+
|
| 311 |
for (const bot of noAnswerBots) {
|
| 312 |
result.push({
|
| 313 |
id: bot.id,
|
|
|
|
| 336 |
soal: r.soal
|
| 337 |
})),
|
| 338 |
totalMatches: matchedCount,
|
| 339 |
+
totalResults: result.length
|
|
|
|
| 340 |
}
|
| 341 |
}
|
| 342 |
};
|