-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ac7d84b
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,9 @@ | ||
``` | ||
spam_checker: | ||
- module: limiter.Limiter | ||
config: | ||
limit: 750 | ||
protected_rooms: | ||
- "!foobarbaz:matrix.org" | ||
- "!barbazquz:matrix.org" | ||
``` |
This file contains 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 @@ | ||
from .limiter import Limiter |
This file contains 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,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 |
This file contains 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,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=[], | ||
) |