church-website/src/utils/detectSpam.ts
2025-10-16 14:11:36 +02:00

31 lines
No EOL
975 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.
* 3. The message contains the domain name dreikoenige.berlin
* 4. The message contains the dollar sign
*
* Returns a boolean value indicating whether the message is spam (`true`) or not (`false`).
*/
export const isSpam = (message: string): boolean => {
if (message.includes('https://') || message.includes('http://') || message.includes('$')) {
const lngDetector = new LanguageDetect();
const language = lngDetector.detect(message)[0][0];
return language !== 'german';
}
if (message.includes('dreikoenige.berlin')) {
return true;
}
if (message.split(" ").length < 5) {
return true
}
return false;
}