Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jesopo committed Feb 4, 2022
0 parents commit ac7d84b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```
spam_checker:
- module: limiter.Limiter
config:
limit: 750
protected_rooms:
- "!foobarbaz:matrix.org"
- "!barbazquz:matrix.org"
```
1 change: 1 addition & 0 deletions limiter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .limiter import Limiter
48 changes: 48 additions & 0 deletions limiter/limiter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
# Copyright 2019 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

class Limiter(object):
def __init__(self, config, api):
self.api = api
self.limit = config.get("limit", 1000)
self.protected_rooms = config.get("protected_rooms", [])

# --- spam checker interface below here ---

def check_event_for_spam(self, event):
body = event.get("content", {}).get("body", "")
room_id = event.get("room_id", "")
if room_id in self.protected_rooms and len(body) > self.limit:
return True # It's over the limit
return False # not spam (as far as we're concerned)

def user_may_invite(self, inviter_user_id, invitee_user_id, room_id):
return True # allowed (as far as we're concerned)

def check_username_for_spam(self, user_profile):
return True

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 setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from setuptools import setup, find_packages

setup(
name="limiter",
version="0.0.1",
packages=find_packages(),
description="Limiter",
include_package_data=True,
zip_safe=True,
install_requires=[],
)

0 comments on commit ac7d84b

Please sign in to comment.