church-website/src/utils/detectSpam.ts
2025-04-01 11:08:08 +02:00

21 lines
No EOL
680 B
TypeScript

import LanguageDetect from 'languagedetect'
/**
* This function determines whether a given message can be classified as spam.
*
* A message is classified as spam based on the following criteria:
* 1. The message contains a URL i.e., it includes `https://`.
* 2. The message is not written in the German language.
*
* Returns a boolean value indicating whether the message is spam (`true`) or not (`false`).
*/
export const isSpam = (message: string): boolean => {
if (message.includes('https://')) {
const lngDetector = new LanguageDetect();
const language = lngDetector.detect(message)[0][0];
return language !== 'german';
}
return false;
}