Separated listener by introducing create listener. Working State. Message loop prevention filters added to server

This commit is contained in:
Lyncoln
2026-10-17 03:42:46 -04:00
parent d260d3681e
commit c7628df30e
14 changed files with 84 additions and 51 deletions
Binary file not shown.
+50
View File
@@ -0,0 +1,50 @@
import json
from core.runtime.outputs import buildOutput
from core.execution.operation import buildOperation
def buildListener(listener, self):
if self.path.startswith(listener.acceptpath):
#Prints can used buildlog for listener runtime
print("Matrix transaction received")
content_length = int(self.headers["Content-Length"])
data = self.rfile.read(content_length)
request = json.loads(data)
outputs = {}
outputs = buildOutput(data, listener, outputs)
#if applyConditions(listener, outputs)
# continue
print(outputs)
for event in outputs[listener.recursive["source"]]:
print("DEBUG")
print(listener.recursive["source"])
if "state_key" in event:
continue
if event.get("sender") != "@lyncoln:loxthelion.com":
continue
if "com.loxthelion.rmass_message_id" in event.get("content", {}):
continue
if event.get("type") == "m.room.message":
# Process and forward to RMASS
outputs = buildOperation(listener.execute, outputs)
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", "2")
self.end_headers()
self.wfile.write(b"{}")
else:
self.send_error(404)
return outputs
+2 -33
View File
@@ -9,6 +9,7 @@ from core.runtime.resolver import resolveItem
from plugins.rmass.listeners import synapselistener
from plugins.rmass.operations import rmassmessagepush
from core.execution.operation import buildOperation
from core.server.createlistener import buildListener
port = int(os.environ.get("SERVER_PORT", 19001))
@@ -97,39 +98,7 @@ class RequestHandler(BaseHTTPRequestHandler):
def do_PUT(self):
print("PUT request received")
if self.path.startswith("/_matrix/app/v1/transactions/"):
print("Matrix transaction received")
outputs = {}
content_length = int(self.headers["Content-Length"])
data = self.rfile.read(content_length)
request = json.loads(data)
requestjson = json.dumps(request, indent=4)
#print (request)
#print(requestjson)
for event in request["events"]:
if "state_key" in event:
# Room state event
continue
if event.get("type") == "m.room.message":
# Process the message
print (event)
outputs = buildOutput(data, synapselistener, outputs)
#print (event)
outputs = buildOperation(rmassmessagepush, outputs)
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", "2")
self.end_headers()
self.wfile.write(b"{}")
else:
self.send_error(404)
outputs = buildListener(synapselistener, self)
def startServer():
server = HTTPServer(("0.0.0.0", port), RequestHandler)