gbdetector
v1.1.2
Published
GbDetector is an advanced text analysis module designed to identify gambling-related content through sophisticated pattern matching and text processing techniques.
Downloads
26
Maintainers
Readme
🎰 GbDetector Documentation
📌 Overview
GbDetector is an advanced text analysis module designed to identify gambling-related content through pattern matching and sophisticated text processing. It is encapsulated in an Immediately Invoked Function Expression (IIFE) to prevent global namespace pollution, offering a clean API for text analysis.
🎯 Purpose
This module assists in detecting potential gambling-related content in text, making it useful for content moderation, compliance monitoring, and filtering systems. It leverages various detection mechanisms to identify both overt and obfuscated gambling-related text.
🌟 Key Features
- Text normalization and cleaning ✨
- Detection of obfuscated gambling terminology 🕵️♂️
- Pattern matching for gambling-related keywords 🎲
- Leet-speak and character substitution handling 🔤
- URL pattern detection 🌐
- Custom keyword list and blocklist support 📃
- Evasion technique detection 🧩
- Contextual indicator analysis 📖
- Contact info extraction 📞
- Multi-language support 🌍
- Fuzzy search detection 🔍
🧭 Architecture Flow Diagram
[INPUT TEXT] → [INITIAL PREPROCESSING]
↓
[GARBAGE/REPETITION CHECK] → [URL PATTERN CHECK]
↓
[TEXT NORMALIZATION] → [WORD RECONSTRUCTION]
↓
[NUMBER MERGING] → [BLOCKLIST CHECK]
↓
[PATTERN MATCHING] → [LEET-SPEAK CONVERSION]
↓
[KEYWORD MATCHING] → [CONFIDENCE SCORING]
↓
[OUTPUT RESULT]🧠 Detection Algorithm
Preprocessing:
- Convert newlines to spaces
- Normalize whitespace
- Add spaces around dots
Initial Checks:
- Detect excessive non-alphanumeric ("garbage") characters
- Identify abnormal repetition patterns
- Detect suspicious URL patterns
- Detect suspicious code or emoji sequences
Evasion Technique Analysis:
- Identify evasion methods
- Score based on detected techniques
Contextual Indicator Detection:
- Analyze text context for gambling cues
- Score based on found indicators
Contact Info Extraction:
- Identify and extract potential contact information
Text Normalization:
- Remove diacritics and standardize characters
- Reconstruct intentionally split words
- Merge numbers with preceding words
Language Pattern Detection:
- Apply language-specific pattern checks
- Score based on matches
Domain Matching:
- Check domains in text against blocklist
- Consider domain format variations
Multi-pass Pattern Matching:
- Apply standard and custom regex patterns
- Detect with varying strictness levels
- Convert leet-speak with adjustable digit ignore
- Perform fuzzy matching for obfuscated terms
Supporting Keyword Analysis:
- Detect supporting keywords post-pattern match
- Add bonus based on keyword match count
Content Length & Complexity Analysis:
- Count metrics like word/character totals, average word length
- Identify spammy gambling content characteristics
Final Evaluation:
- Normalize checkpoint scores by sensitivity factor
- Determine confidence level: none, low, medium, high
- Generate a detailed analysis report if requested
🧩 Core Functions
detect(text = "", options = {})
Main function for detecting gambling patterns in text.
Parameters:
text(string): The text to be analyzedoptions(object): Configuration optionskeywords: Pattern terms to detect (e.g., site names)supportKeywords: Supporting keyword listdomains: List of domains to detectallowlist: Whitelisted termssensitivityLevel: Detection sensitivity (1–5, default 3)includeAnalysis: Include detailed analysis in resultsdetectRepetition,detectUrlPatterns,detectEvasionTechniques,detectContextualIndicators: Boolean toggles for specific detection typesextractContactInfo: Whether to extract contact infolanguage: Language selection ('en', 'id', 'all')debug: Show debug info
Returns: An object with detection results:
isGambling(boolean): Whether gambling content is detectedconfidence(string): "none", "low", "medium", or "high"checkpoint(number): Numerical detection scoredetails(string): Human-readable explanationcomment(string): Original analyzed textanalysis(object, optional): Detailed analysis info
🧹 Text Processing
cleanText(text)– Normalize and clean textcleanWeirdPatterns(text)– Remove odd spacing and punctuationreconstructSeparatedWords(text)– Reconstruct deliberately split wordsmergeTextWithTrailingNumbers(text)– Merge numbers trailing words
🧠 Detection Logic
isMostlyAsciiGarbage(text, threshold = 0.45)– Detect non-alphanumeric spamhasAbnormalRepetition(text)– Detect character/pattern repetitionhasSuspiciousUrlPatterns(text)– Detect obfuscated URLshasSuspiciousCodeSequences(text)– Detect suspicious symbols/emojiconvertCommentFixed(comment, ignoreLastDigits = 0)– Convert symbols to charactersfuzzySearch(keywords, text)– Perform fuzzy keyword match
🔬 Advanced Analysis
analyzeEvasionTechniques(text)detectContextualGamblingIndicators(text)extractContactInfos(text)detectLanguageSpecificPatterns(text, language)
📐 Pattern Matching
createPatternRegex(terms, loose = false)– Create RegExp patternTinyPatternRegex(terms)– Create focused RegExp pattern
🧮 Mathematical Formulas
🎯 Confidence Threshold Calculation
sensitivityFactor = Math.max(1, Math.min(5, sensitivityLevel)) / 3
confidenceThresholds = {
low: Math.max(0.45, 0.5 * sensitivityFactor),
medium: Math.max(0.9, 0.8 * sensitivityFactor),
high: Math.max(1.2, 2.5 * sensitivityFactor)
}🧠 Keyword Bonus Calculation
keywordBonus = Math.min(1.5, 0.03 * (keywordMatchCount/2) + 0.7)🧹 Garbage Character Ratio
garbageRatio = numberOfGarbageCharacters / totalTextLength
isGarbage = garbageRatio >= threshold (default 0.45)💡 Usage Example
const examples = [
"sl0t88 maxwin guaranteed win!",
"J4ckp0t Zeus99 trusted - sign up now!",
"c a s i n o online with credit & e-wallet deposit",
"best online gambling site slot gacor maxwin today",
"Get rich quick with winning bets at my-gambling-site.com",
"This is a normal sentence with no gambling content.",
"Z.e.u.s g.a.c.o.r m.a.x.w.i.n",
"j*u*d*i o*n*l*i*n*e biggest site"
];
const customConfig = {
keywords: ["win", "maxwin", "deposit", "withdraw", "gacor"],
supportKeywords: ["jp", "jackpot", "slot", "judi", "casino"],
domains: ["scamsite.com", "badword"],
allowlist: ["normal", "common"],
sensitivityLevel: 3,
includeAnalysis: true,
detectRepetition: true,
detectUrlPatterns: true,
detectEvasionTechniques: true,
detectContextualIndicators: true,
extractContactInfo: true,
language: 'all',
debug: true
};
console.log("=== TESTING EXAMPLES ===");
examples.forEach((example, index) => {
console.log(`\nExample ${index + 1}: "${example}"`);
// run detection logic here
});🃏 Default Keywords
GbDetector comes with a comprehensive set of default keywords for various gambling-related terms in both English and Indonesian:
🔑 Primary Keywords:
[
"slot", "casino", "jack", "zeus", "scatter", "toto", "judol", "jodol",
"poker", "roulette", "betting", "gamble", "joker"
]🛠️ Supporting Keywords:
- English gambling terms:
wdp,wd,win,happy,joyful,rich,trustworthy,lucky,trust, etc. - Indonesian gambling terms:
menang,senang,gacor,gembira,kaya,pasti dapat,bangga,panen, etc.
📄 License
MIT License © 2025 Ramsyan-Tungga
✅ Conclusion
The GbDetector module offers a powerful solution for identifying gambling-related content in text, even when obfuscated. By combining various detection techniques and offering extensive configuration options, the module achieves high accuracy while minimizing false positives. Its modular design ensures easy integration into different systems requiring content moderation or filtering capabilities.
