-
Notifications
You must be signed in to change notification settings - Fork 6
Add automated spam filter for questions with logging according to weights #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Bhavishya-Chaturvedi
wants to merge
9
commits into
Spoken-tutorial:master
Choose a base branch
from
Bhavishya-Chaturvedi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eb6f00d
Spam_questions
Bhavishya-Chaturvedi 853308d
Modified/Corrected
Bhavishya-Chaturvedi 1473d91
Delete website/migrations directory
Bhavishya-Chaturvedi ec1e8ee
Resolved logging
Bhavishya-Chaturvedi 494abda
migrations deleted
Bhavishya-Chaturvedi 86e1a35
Updated .env.example settings.py helpers.py
Bhavishya-Chaturvedi 0db431f
migrations/logging
Bhavishya-Chaturvedi b22dfff
Delete question & user button
Bhavishya-Chaturvedi 23c42b6
Spam tab
Bhavishya-Chaturvedi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| # Script to seed the database with predefined spam rules | ||
| import os | ||
| import django | ||
|
|
||
| os.environ.setdefault("DJANGO_SETTINGS_MODULE", "forums.settings") | ||
| django.setup() | ||
|
|
||
| from django.db.models import Q | ||
| from website.models import SpamRule | ||
|
|
||
|
|
||
|
|
||
| def seed_spam_rules(): | ||
| rules = { | ||
| # Certification/Exam dump patterns | ||
| "Certification/Exam Spam": { | ||
| "score": 30, | ||
| "type": SpamRule.KEYWORD, | ||
| "patterns": [ | ||
| r"exam\s+dumps?", r"braindumps?", r"practice\s+test", | ||
| r"certification\s+exam", r"test\s+preparation", | ||
| r"exam\s+questions?", r"study\s+guides?", | ||
| r"pdf\s+\+\s+testing\s+engine", r"testing\s+engine", | ||
| r"exam\s+prep", r"mock\s+exam", r"real\s+exam", | ||
| r"dumps\s+pdf", r"braindump" | ||
| ], | ||
| }, | ||
|
|
||
| # Promotional spam | ||
| "Promotional Spam": { | ||
| "score": 25, | ||
| "type": SpamRule.KEYWORD, | ||
| "patterns": [ | ||
| r"click\s+here", r"join\s+now", r"limited\s+time", | ||
| r"discount", r"coupon\s+code", r"20%\s+off", | ||
| r"free\s+download", r"get\s+certified", | ||
| r"unlock\s+your\s+career", r"master\s+the", | ||
| r"boost\s+your\s+career", r"cert20", | ||
| r"at\s+checkout", r"special\s+offer", | ||
| ], | ||
| }, | ||
|
|
||
| # Suspicious domains | ||
| "Suspicious Domain": { | ||
| "score": 35, | ||
| "type": SpamRule.DOMAIN, | ||
| "patterns": [ | ||
| r"dumpscafe\.com", r"certsout\.com", r"mycertshub\.com", | ||
| r"vmexam\.com", r"kissnutra\.com", r"dumps.*\.com", | ||
| r"cert.*\.com", r"exam.*\.com", | ||
| ], | ||
| }, | ||
|
|
||
| # Generic business language | ||
| "Business/Career Spam": { | ||
| "score": 15, | ||
| "type": SpamRule.KEYWORD, | ||
| "patterns": [ | ||
| r"attests\s+to\s+your\s+proficiency", | ||
| r"esteemed\s+(?:accreditation|certification|credential)", | ||
| r"valuable\s+asset\s+to\s+companies", | ||
| r"demonstrates\s+your\s+ability", | ||
| r"comprehensive\s+study\s+(?:tools|materials)", | ||
| r"interactive\s+practice\s+tests", | ||
| r"real\s+exam\s+questions", | ||
| r"actual\s+exam\s+questions", | ||
| r"validated\s+by\s+.*certification", | ||
| r"urgently\s+need\s+experts", | ||
| ], | ||
| }, | ||
|
|
||
| # Gaming content | ||
| "Gaming Spam": { | ||
| "score": 20, | ||
| "type": SpamRule.KEYWORD, | ||
| "patterns": [ | ||
| r"spacebar\s+clicker", r"clicker\s+game", | ||
| r"addictive\s+game", r"upgrades\s+available", | ||
| r"instant\s+rewards", | ||
| ], | ||
| }, | ||
|
|
||
| # Health/Supplement spam | ||
| "Health Spam": { | ||
| "score": 22, | ||
| "type": SpamRule.KEYWORD, | ||
| "patterns": [ | ||
| r"vitalit[äa]t", r"nahrungserg[äa]nzungsmittel", | ||
| r"libido", r"fruchtbarkeit", r"energie", | ||
| r"hormonelle\s+balance", r"perforan", | ||
| ], | ||
| }, | ||
| } | ||
|
|
||
| inserted, skipped = 0, 0 | ||
| for note, config in rules.items(): | ||
| for pattern in config["patterns"]: | ||
| exists = SpamRule.objects.filter( | ||
| Q(pattern=pattern) & Q(type=config["type"]) | ||
| ).exists() | ||
| if not exists: | ||
| SpamRule.objects.create( | ||
| type=config["type"], | ||
| pattern=pattern, | ||
| score=config["score"], | ||
| notes=note, | ||
| ) | ||
| inserted += 1 | ||
| else: | ||
| skipped += 1 | ||
|
|
||
| print(f"✅ Inserted {inserted} new rules, skipped {skipped} existing ones.") | ||
|
|
||
|
|
||
| # Run it | ||
| seed_spam_rules() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.