Fix: Verbesserte Erkennung von umformulierten Nachrichten - nur inhaltliche Änderungen werden erkannt
This commit is contained in:
@@ -65,18 +65,33 @@ Message: "${message}"`;
|
|||||||
// e.g., "(This message is a friendly, positive comment expressing appreciation. No rewriting is necessary.)"
|
// e.g., "(This message is a friendly, positive comment expressing appreciation. No rewriting is necessary.)"
|
||||||
rewrittenMessage = rewrittenMessage.replace(/\s*\([^)]*\)\s*/g, '').trim();
|
rewrittenMessage = rewrittenMessage.replace(/\s*\([^)]*\)\s*/g, '').trim();
|
||||||
|
|
||||||
// Compare with original message (case-insensitive and ignoring extra whitespace)
|
// Remove surrounding quotes if present (AI sometimes adds quotes)
|
||||||
|
// Handle both single and double quotes, and multiple layers of quotes
|
||||||
|
rewrittenMessage = rewrittenMessage.replace(/^["']+|["']+$/g, '').trim();
|
||||||
|
|
||||||
|
// Normalize both messages for comparison (remove extra whitespace, normalize quotes, case-insensitive)
|
||||||
|
const normalizeForComparison = (text: string): string => {
|
||||||
|
return text
|
||||||
|
.trim()
|
||||||
|
.replace(/["']/g, '') // Remove all quotes for comparison
|
||||||
|
.replace(/\s+/g, ' ') // Normalize whitespace
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[.,!?;:]\s*$/, ''); // Remove trailing punctuation for comparison
|
||||||
|
};
|
||||||
|
|
||||||
const originalTrimmed = message.trim();
|
const originalTrimmed = message.trim();
|
||||||
const rewrittenTrimmed = rewrittenMessage.trim();
|
const rewrittenTrimmed = rewrittenMessage.trim();
|
||||||
|
const originalNormalized = normalizeForComparison(originalTrimmed);
|
||||||
|
const rewrittenNormalized = normalizeForComparison(rewrittenTrimmed);
|
||||||
|
|
||||||
// Check if message was actually changed (normalize for comparison)
|
// Check if message was actually changed (content-wise, not just formatting)
|
||||||
const wasChanged = rewrittenTrimmed.toLowerCase() !== originalTrimmed.toLowerCase() &&
|
// Only consider it changed if the normalized content is different
|
||||||
rewrittenTrimmed !== originalTrimmed;
|
const wasChanged = originalNormalized !== rewrittenNormalized;
|
||||||
|
|
||||||
if (wasChanged) {
|
if (wasChanged) {
|
||||||
rewrittenMessage = rewrittenTrimmed + " (autocorrected by Polite-Bot)";
|
rewrittenMessage = rewrittenTrimmed + " (autocorrected by Polite-Bot)";
|
||||||
} else {
|
} else {
|
||||||
// Return original message if not changed
|
// Return original message if not changed (without suffix)
|
||||||
rewrittenMessage = originalTrimmed;
|
rewrittenMessage = originalTrimmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -348,7 +348,12 @@ export default function Game({ dailyPuzzle, genre = null, isSpecial = false, max
|
|||||||
// The API adds "(autocorrected by Polite-Bot)" suffix only if message was changed
|
// The API adds "(autocorrected by Polite-Bot)" suffix only if message was changed
|
||||||
const wasChanged = finalMessage.includes('(autocorrected by Polite-Bot)');
|
const wasChanged = finalMessage.includes('(autocorrected by Polite-Bot)');
|
||||||
if (wasChanged) {
|
if (wasChanged) {
|
||||||
setRewrittenMessage(finalMessage);
|
// Remove the suffix for display
|
||||||
|
const displayMessage = finalMessage.replace(/\s*\(autocorrected by Polite-Bot\)\s*/g, '').trim();
|
||||||
|
setRewrittenMessage(displayMessage);
|
||||||
|
} else {
|
||||||
|
// Ensure rewrittenMessage is not set if message wasn't changed
|
||||||
|
setRewrittenMessage(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user