diff --git a/kibicara-frontend/src/app/dashboard/board/hoodsettings/hoodsettings.component.html b/kibicara-frontend/src/app/dashboard/board/hoodsettings/hoodsettings.component.html index 2e05e90..45d4a8d 100644 --- a/kibicara-frontend/src/app/dashboard/board/hoodsettings/hoodsettings.component.html +++ b/kibicara-frontend/src/app/dashboard/board/hoodsettings/hoodsettings.component.html @@ -20,6 +20,51 @@ if the remaining message is legitimate. For example insults or spam words like "blockchain".

+

+ Example: + For example say you want all messages to be distributed except + messages with insult/spam words "fuck", "asshat", "blockchain" then + you can add these words to the Badwords like so: + image + Note the dot in the Triggers section. It means that every message is + being relayed except those in badwords. If you would remove it, no + message would be relayed at all, so only change the Trigger section if + you are sure what you do. +

+

+ Now if a user sends a message including "asshat" the message will + not be distributed. For example: +

+
+ + xyz is an asshat! + This message will + not be distributed. + + + xyz is an verybigAsshat! + This message will + not be distributed. + + + xyz is nice! + This message will be distributed. + +
+

+ For experts only: We use python re module with + re.search(pattern, string, flags=re.IGNORECASE) for + both Triggers and Badwords. View + Documentation. +

diff --git a/kibicara-frontend/src/app/dashboard/board/hoodsettings/hoodsettings.component.scss b/kibicara-frontend/src/app/dashboard/board/hoodsettings/hoodsettings.component.scss index 50e0136..abc1b05 100644 --- a/kibicara-frontend/src/app/dashboard/board/hoodsettings/hoodsettings.component.scss +++ b/kibicara-frontend/src/app/dashboard/board/hoodsettings/hoodsettings.component.scss @@ -22,3 +22,16 @@ margin-top: 2px; margin-left: 10px; } + +.image { + width: 80%; + margin-left: 10%; + margin-right: 10%; +} + +.example-container { + margin: 5%; + display: grid; + grid-template-columns: 1fr 1fr 1fr; + gap: 10px; +} diff --git a/kibicara-frontend/src/assets/badwords.png b/kibicara-frontend/src/assets/badwords.png new file mode 100644 index 0000000..9bdb2ee Binary files /dev/null and b/kibicara-frontend/src/assets/badwords.png differ diff --git a/kibicara/platformapi.py b/kibicara/platformapi.py index 77cedb3..7ceb2f9 100644 --- a/kibicara/platformapi.py +++ b/kibicara/platformapi.py @@ -9,7 +9,7 @@ from asyncio import create_task, Queue from enum import auto, Enum from kibicara.model import BadWord, Trigger from logging import getLogger -from re import match +from re import search, IGNORECASE logger = getLogger(__name__) @@ -147,11 +147,11 @@ class Censor: async def __is_appropriate(self, message): for badword in await BadWord.objects.filter(hood=self.hood).all(): - if match(badword.pattern, message.text): + if search(badword.pattern, message.text, IGNORECASE): logger.debug('Matched bad word - dropped message: %s' % message.text) return False for trigger in await Trigger.objects.filter(hood=self.hood).all(): - if match(trigger.pattern, message.text): + if search(trigger.pattern, message.text, IGNORECASE): logger.debug('Matched trigger - passed message: %s' % message.text) return True logger.debug('Did not match any trigger - dropped message: %s' % message.text) diff --git a/kibicara/webapi/hoods/__init__.py b/kibicara/webapi/hoods/__init__.py index a606a46..95bed10 100644 --- a/kibicara/webapi/hoods/__init__.py +++ b/kibicara/webapi/hoods/__init__.py @@ -72,6 +72,10 @@ async def hood_create(values: BodyHood, response: Response, admin=Depends(get_ad hood = await Hood.objects.create(**values.__dict__) await AdminHoodRelation.objects.create(admin=admin.id, hood=hood.id) spawner.start(hood) + + # Initialize Triggers to match all + await Trigger.objects.create(hood=hood, pattern='.') + response.headers['Location'] = '%d' % hood.id return hood except IntegrityError: diff --git a/tests/test_api_email_happy_path.py b/tests/test_api_email_happy_path.py index 24456b5..25fe3e1 100644 --- a/tests/test_api_email_happy_path.py +++ b/tests/test_api_email_happy_path.py @@ -22,14 +22,15 @@ def test_email_subscribe_unsubscribe(client, hood_id, receive_email): r'(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', body, )[0] + start = len('token=') response = client.post( '/api/hoods/%d/email/subscribe/confirm/%s' - % (hood_id, urlparse(confirm_url).query[len('token=') :]) + % (hood_id, urlparse(confirm_url).query[start:]) ) assert response.status_code == status.HTTP_201_CREATED response = client.post( '/api/hoods/%d/email/subscribe/confirm/%s' - % (hood_id, urlparse(confirm_url).query[len('token=') :]) + % (hood_id, urlparse(confirm_url).query[start:]) ) assert response.status_code == status.HTTP_409_CONFLICT token = to_token(email=mail['to'], hood=hood_id)