Separated listener by introducing create listener. Working State. Message loop prevention filters added to server
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
+13
-6
@@ -9,15 +9,22 @@ def buildLog (action, outputs, response):
|
||||
f"{outputs[print_key]}",
|
||||
)
|
||||
|
||||
except: (KeyError, TypeError)
|
||||
except (KeyError, TypeError):
|
||||
pass
|
||||
|
||||
if action.showstatus is True and response.status_code in [200, 204]:
|
||||
if action.showstatus is True and response.ok:
|
||||
print(f"{action.name} successful")
|
||||
|
||||
elif action.showstatus is True and response.status_code not in [200, 204]:
|
||||
elif action.showstatus is True and not response.ok:
|
||||
print(f"{action.name} failed with status code {response.status_code}")
|
||||
|
||||
try:
|
||||
print(f"Response: {response.json()["error"]}")
|
||||
except KeyError:
|
||||
print(f"Response:", response.json())
|
||||
response_data = response.json()
|
||||
except ValueError:
|
||||
response_data = response.text
|
||||
|
||||
if isinstance(response_data, dict):
|
||||
print("Response:", response_data.get("error", response_data))
|
||||
else:
|
||||
print("Response:", response_data)
|
||||
return
|
||||
|
||||
@@ -2,7 +2,7 @@ import json
|
||||
|
||||
def buildOutput(response, action, outputs):
|
||||
if hasattr(action, "outputs"):
|
||||
if response != None:
|
||||
if response is not None:
|
||||
try:
|
||||
response_data = response.json()
|
||||
except AttributeError:
|
||||
@@ -20,13 +20,13 @@ def buildOutput(response, action, outputs):
|
||||
for output_name, response_key in action.outputs.items():
|
||||
if key == response_key:
|
||||
outputs[output_name] = value
|
||||
return outputs
|
||||
|
||||
|
||||
else:
|
||||
return outputs
|
||||
print("No response received"),
|
||||
|
||||
|
||||
|
||||
#return outputs
|
||||
return outputs
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ def recursiveSet(definition, outputs):
|
||||
for job in recursiveset:
|
||||
outputs, response = buildAction(job, outputs)
|
||||
|
||||
print("MESSAGE BODY DEBUG")
|
||||
print(resolved["messages"])
|
||||
#print("MESSAGE BODY DEBUG")
|
||||
#print(resolved["messages"])
|
||||
return outputs
|
||||
|
||||
from core.execution.action.action import buildAction
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user