create initial redlight_server_module.py script
This commit is contained in:
parent
4e1dc12038
commit
bc43794e40
@ -1,27 +1,27 @@
|
|||||||
import logging
|
import logging
|
||||||
from synapse.module_api import ModuleApi
|
|
||||||
from twisted.web.http import OK, NO_CONTENT
|
|
||||||
import json
|
import json
|
||||||
|
from synapse.module_api import ModuleApi
|
||||||
from twisted.web import http
|
from twisted.web import http
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.internet.defer import inlineCallbacks
|
from twisted.internet.defer import inlineCallbacks
|
||||||
from twisted.web.server import NOT_DONE_YET
|
from twisted.web.server import NOT_DONE_YET
|
||||||
|
from twisted.web.http import OK, NO_CONTENT
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class AbuseLookupModule:
|
class RedlightServerModule:
|
||||||
def __init__(self, config: dict, api: ModuleApi):
|
def __init__(self, config: dict, api: ModuleApi):
|
||||||
self._api = api
|
self._api = api
|
||||||
|
|
||||||
# Register the abuse_lookup endpoint
|
# Register the abuse_lookup endpoint
|
||||||
api.register_web_resource(
|
api.register_web_resource(
|
||||||
"/_matrix/loj/v1/abuse_lookup",
|
"/_matrix/loj/v1/abuse_lookup",
|
||||||
AbuseLookupResource(self)
|
RedlightServerResource(self)
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info("AbuseLookupModule initialized.")
|
|
||||||
|
|
||||||
class AbuseLookupResource:
|
logger.info("RedlightServerModule initialized.")
|
||||||
|
|
||||||
|
class RedlightServerResource:
|
||||||
|
|
||||||
isLeaf = True
|
isLeaf = True
|
||||||
|
|
||||||
@ -55,14 +55,14 @@ class AbuseLookupResource:
|
|||||||
# Extract body from the request
|
# Extract body from the request
|
||||||
body = yield request.content.read()
|
body = yield request.content.read()
|
||||||
content = body.decode("utf-8")
|
content = body.decode("utf-8")
|
||||||
|
|
||||||
# Log the request to Synapse's log
|
# Log the request to Synapse's log
|
||||||
logger.info(f"Received abuse lookup request: {content}")
|
logger.info(f"Received abuse lookup request: {content}")
|
||||||
|
|
||||||
# Extract room_id from the content
|
# Extract room_id from the content
|
||||||
data = json.loads(content)
|
data = json.loads(content)
|
||||||
room_id = data["room_id"]
|
room_id = data["room_id"]
|
||||||
|
|
||||||
# TODO: Check the room_id against your list/database
|
# TODO: Check the room_id against your list/database
|
||||||
is_abuse = room_id == "!OEedGOAXDBahPyWMSQ:example.com"
|
is_abuse = room_id == "!OEedGOAXDBahPyWMSQ:example.com"
|
||||||
|
|
||||||
@ -97,5 +97,5 @@ class AbuseLookupResource:
|
|||||||
def parse_config(config: dict) -> dict:
|
def parse_config(config: dict) -> dict:
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def create_module(api: ModuleApi, config: dict) -> AbuseLookupModule:
|
def create_module(api: ModuleApi, config: dict) -> RedlightServerModule:
|
||||||
return AbuseLookupModule(config, api)
|
return RedlightServerModule(config, api)
|
Loading…
Reference in New Issue
Block a user