Skip to content

Commit

Permalink
Base structure for an antispam module
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Oct 25, 2019
1 parent 354caa9 commit cc0ab17
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,43 @@ nano config/development.yaml
node lib/index.js
```

## Synapse Antispam Module

First, install the module to your Synapse python environment:
```
pip install -e git+https://github.com/matrix-org/mjolnir.git#egg=mjolnir&subdirectory=synapse_antispam
```

*Note*: Where your python environment is depends on your installation method. Visit
[#synapse:matrix.org](https://matrix.to/#/#synapse:matrix.org) if you're not sure.

Then add the following to your `homeserver.yaml`:
```yaml
spam_checker:
module: mjolnir.AntiSpam
config:
# Prevent servers/users in the ban lists from inviting users on this
# server to rooms. Default true.
block_invites: true
# Flag messages sent by servers/users in the ban lists as spam. Currently
# this means that spammy messages will appear as empty to users. Default
# false.
block_messages: false
# The room IDs of the ban lists to honour. Unlike other parts of Mjolnir,
# this list cannot be room aliases or permalinks. This server is expected
# to already be joined to the room - Mjolnir will not automatically join
# these rooms.
ban_lists:
- "!roomid:example.org"
```
Be sure to change the configuration to match your setup. Your server is expected to
already be participating in the ban lists - if it is not, you will need to have a user
on your homeserver join. The antispam module will not join the rooms for you.
If you change the configuration, you will need to restart Synapse. You'll also need
to restart Synapse to install the plugin.
## Development
TODO. It's a TypeScript project with a linter.
1 change: 1 addition & 0 deletions synapse_antispam/mjolnir/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .antispam import AntiSpam
24 changes: 24 additions & 0 deletions synapse_antispam/mjolnir/antispam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class AntiSpam(object):
def __init__(self, config):
self._block_invites = config.get("block_invites", True)
self._block_messages = config.get("block_messages", False)
self._list_room_ids = config.get("ban_lists", [])

def check_event_for_spam(self, event):
return False # not spam

def user_may_invite(self, inviter_user_id, invitee_user_id, room_id):
return True # allowed

def user_may_create_room(self, user_id):
return True # allowed

def user_may_create_room_alias(self, user_id, room_alias):
return True # allowed

def user_may_publish_room(self, user_id, room_id):
return True # allowed

@staticmethod
def parse_config(config):
return config # no parsing needed
11 changes: 11 additions & 0 deletions synapse_antispam/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from setuptools import setup, find_packages

setup(
name="mjolnir",
version="0.0.1",
packages=find_packages(),
description="Mjolnir Antispam",
include_package_data=True,
zip_safe=True,
install_requires=[],
)

0 comments on commit cc0ab17

Please sign in to comment.