From c7628df30ef1c640b7216f71397744e112d14910 Mon Sep 17 00:00:00 2001 From: Lyncoln Date: Sat, 17 Oct 2026 03:42:46 -0400 Subject: [PATCH] Separated listener by introducing create listener. Working State. Message loop prevention filters added to server --- core/runtime/__pycache__/logs.cpython-314.pyc | Bin 1403 -> 1542 bytes .../__pycache__/outputs.cpython-314.pyc | Bin 1143 -> 1199 bytes .../__pycache__/recursive.cpython-314.pyc | Bin 1414 -> 1414 bytes core/runtime/logs.py | 19 ++++--- core/runtime/outputs.py | 8 +-- core/runtime/recursive.py | 4 +- .../createlistener.cpython-314.pyc | Bin 0 -> 2114 bytes .../server/__pycache__/server.cpython-314.pyc | Bin 4796 -> 3683 bytes core/server/createlistener.py | 50 ++++++++++++++++++ core/server/server.py | 35 +----------- .../synapselistener.cpython-314.pyc | Bin 275 -> 494 bytes plugins/rmass/listeners/synapselistener.py | 17 ++++-- savedata/rmmanager.db | Bin 16384 -> 16384 bytes savedata/tokens.json | 2 +- 14 files changed, 84 insertions(+), 51 deletions(-) create mode 100644 core/server/__pycache__/createlistener.cpython-314.pyc create mode 100644 core/server/createlistener.py diff --git a/core/runtime/__pycache__/logs.cpython-314.pyc b/core/runtime/__pycache__/logs.cpython-314.pyc index dba84d428f9dd2bfb4f5ad92a5c1c96ef1358dc9..b632788a7ff294174f782f197229246c35e2f099 100644 GIT binary patch delta 797 zcmZ8f&ubGw6n>N4&HhNTZemT+{2;N_mLwL6*kX+Ilu`wwC6pi}QbKnLsqJpr-HI2f zAV?7pi7OaUv*sK;~@%h{T2nA7&hLbeq$2xh&E&tMT`Hzm0K82 zA)oO9bs0YpPZk{GC+bU~g*mDe?o0qEP^E~yKj-M|{?3m9M4)6H;g9910yU0nM=kFx zPn2y#sxl_ZQg(%^8}ErU7sZM7a@v_kWEa7(UL!ybkNJS%TXb-f4mPq)I=*y$xwu?hD(*0zn*T|- z9!#3tLba(*?lnpw#hFUa@;NwCSUky9^oPjk<% zE#}$`xc#-+R}(E)@{23E=O=?o>3~5s$5a68+i@;*n?_)I+M9LtBCV6(ujHzrwA|2gB_MY P=o|2DGK^em99Mn=cL=z| delta 675 zcmYjPOK1~O6uoagnNKp~SjC1(W5$+Dh-T5&Mx8{mG2&k|h>Av}m=IIiOqppl2qj&K zD@mAw5d|YI)Ro&Tg?8bhi=;^j#^AoYNU|uFf^Qms7v6dA9_~5!-N$?C+Tq1xqQC== z^V=IUyF^Jm%R6vJ;?;Xtx>rRZ>p7Ci1gBYH6hW*tkGv>pb1dc%K?b&Nn8`H z?`Tv?GPa!^2^y0JN)@?~aD?OmXQK-yi770#!v_g=Y;P&}oMZzrIpHMr4Az7>ep1JTcs zX5fmoODP3{YO`+x?z3l;Xg@K$)YZ__pYmEyZJ=6{-AJk5%BCJd|MSe%8`uo$PwHP#=WAlJqb z#vsvVX7x-amd#}hd;X8m!wAMOhBkY8PERe)renqkPVKK?3K+U1Lg*Waed-``8XnC2 E0+>0S9RL6T diff --git a/core/runtime/__pycache__/outputs.cpython-314.pyc b/core/runtime/__pycache__/outputs.cpython-314.pyc index 44e2c61e2360a0479fc049ec1dc3a989d0098f5c..d4124be06fcab78cbe3ced5146239dcd6ee9702f 100644 GIT binary patch delta 285 zcmey)v7VDxn~#@^0SIpMT+Ygy$m`E|V`8id=SBtw8HO;1)P)--*fA-Axm$>C8XEL`cvoi=Q ze^6oI5pMAN!pXoZbU{etGLPm(9<2`?V8I_>bSE>jC z6|n)0D*~CjlHoIuWGIpV61O;Pa`RJ4b5iY!WPn_dFN%4A#0O?ZM#kF=++SFv8HJ0a Gfg%7l(L@gb delta 227 zcmZ3_`JIDTn~#@^0SHe1yp)wYk=LK`#Kc$?{*??2G7Mo1L5vpV3=Am?Hg?%Da)mJ| zGk|aqsJzauc!^!{2Dk8pk}KTOlP5E`iV84@NO$;sU;|Shbs0F6ethAWY|Wx* zI$OZWmf?`CqO&6NVFgAYsmWBt1~jb*WcEsi&p?u)NE}Gq;;_lhPbtkwwJVaIJds6= ML!42%ND3$c08cGC*8l(j diff --git a/core/runtime/__pycache__/recursive.cpython-314.pyc b/core/runtime/__pycache__/recursive.cpython-314.pyc index 6b4456f6175d3678f486af2ae9821978dc3fb70b..980851dd83bc1c940376dea9e6e81772bef65044 100644 GIT binary patch delta 22 ccmZqUZsX?F=HumJ0D@%a3}05K2*a3}05i7*HUIzs diff --git a/core/runtime/logs.py b/core/runtime/logs.py index 5d19255..b234093 100644 --- a/core/runtime/logs.py +++ b/core/runtime/logs.py @@ -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 diff --git a/core/runtime/outputs.py b/core/runtime/outputs.py index 418eea1..3719817 100644 --- a/core/runtime/outputs.py +++ b/core/runtime/outputs.py @@ -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 diff --git a/core/runtime/recursive.py b/core/runtime/recursive.py index e9a8eb1..2a72888 100644 --- a/core/runtime/recursive.py +++ b/core/runtime/recursive.py @@ -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 diff --git a/core/server/__pycache__/createlistener.cpython-314.pyc b/core/server/__pycache__/createlistener.cpython-314.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4ad6ddc857fea3f447471b6265788126d340e4ee GIT binary patch literal 2114 zcmah~+i%lW7(Y(z*tst$8!c!|W8J9Qb&Q>_V=CN`F)r3 zo!jYXUkKp#*Xzw2zcK*)Njh%xIm+{CtZad6K%^FdNu+O)y5uu`38MQK{g-HyP5_ZU z3`|C(CP9+4;%>Cl)gh8hMN{)`2tp6w&yT<7-{Aii$Wj@C zzSJ^=@lwlz4E+*>yJ@O}op6R0DEVsu;vmPmT(QeZfLzc;aa_A3ZoeZ%YI@W|T;IA6 zvm+kvY8l?uJel=%t^B!u7th38&67t#*5BpQ0??V}D#8q|T z=*-eR0D|BM*_R2A;cC|&yD<`kan!{+O{sO6>a&XVSBGwX~zyKBipMlNooz zdk_$#J=rmnB*SFSu%n8+$GVDH$^OdNhmwhuTN5UdR71*>GdqD`9x5A9u0$_tstHx| z%raEh%ylbZXeE?~7W3Z1yB~jG1r1X&;p(Tbj7Ojxg z@>;Qyz`s-vhKiD5tQMhRNNaFaku5ggiDl7dS%;NqF@-d2;xH-^HS;*!=gfx_7Ev}##xZn_3v;hm(t*BF!)k0?hXjw8Pi$(Be z2^u(a&AxVV=5PZqlR*yh@#7PuS+l~rR)m5qZ78yUibYAqg+@YNLr^dv+8{cfsEL=T z6EdZjtv>tqUUm?468pn%1~6{onr?x8HvDb*t8$wiYp`RrOYOMOhzo6YrpeB{2!LR; z9zEUSrk{<(YnOk>eV?nJn%^Bi*Bm)tjqdRSJC*Iq&h72nwJ)1|s!BhJ4c$L=_f+k2 zGj^=X?#B*Q*=Mown*3m`8GEzJz6fD|)wMg(y}@{UTxg6754qj(x%S|EeQ>_I@GSD$ zcPH+wJi+2*J2usbP5pRvH9cuCu^{Mo4d>T(^Ecsx#ot$eV=N`S)9KCp#{bw8uojW)N zf_-gnw84$mW?NihkBhXq;RZKcJ5o=cYjNkhKz$_n05gOx(Bek1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e_@AH(JV+vb z_`g3zE&PKVBlI1Ay-5c2{v&_{999G6kC-R4%CXB6Y`}qYD2zHIrC%q!j*w5}HFki- zj9{ZeW<=HsMQKE0HJnRIDZVrp6}FcFSmp_WoJ8(&$-Bp2`UgK!o(@E=p0 dlns_PxyRDvlnBC~ZwNgHSb2U|rze_J>VK@%P>BEl diff --git a/core/server/createlistener.py b/core/server/createlistener.py new file mode 100644 index 0000000..d0b119f --- /dev/null +++ b/core/server/createlistener.py @@ -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 \ No newline at end of file diff --git a/core/server/server.py b/core/server/server.py index 8ab5a01..f6b92d3 100644 --- a/core/server/server.py +++ b/core/server/server.py @@ -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) diff --git a/plugins/rmass/listeners/__pycache__/synapselistener.cpython-314.pyc b/plugins/rmass/listeners/__pycache__/synapselistener.cpython-314.pyc index 386c46406335022e711f2ac6702e6742971503f5..db393d2cfcc26fc3f26a5e3009858c6d93f2e8cc 100644 GIT binary patch literal 494 zcmXw0!HN_y5KX!>ot_?hcNGsRs0*G3ae|;15%HoZh=+Jq$#xezt=;L6N`~D%HJaz1WLt3gB7%W@A(Fl) z@2H~>iA-D~Qn+0DFlp5hv|+#Z?x^>=-ZuO=&%+(l`r}69;%bsbZ@{W69h=4x1JkO5z`i%S4m^H0 z-eD+IRe^Cvxn}+m?pDi;A2kq go(#phxEJyD%LOaX{RNx-Dj$rTmC28(y%m-I1D=JN$N&HU delta 202 zcmaFIJejFpn~#@^0SNRLT*^uZ(vLwL7+``jK1%@^4GcjHB@97~C5%B#B}_rgLCpG$ zCCouA$_$#UReV9I$*Bb;nfZANA*sbBx7ZSsK^(VRY^i0bc_qbunk=_i@)C1XZ?R-& z=B3=?D$d9+FD^;sDJd0LF0^L3A8+lGX);v6)-jLBT%!nEE>3={~`xzNy>XoI2-p2O-!&hlN)X z-c8U&bOj}J9CTtg@bG_rs};6dVJ~Oc`ZdL4>$kR_YBymH2rv|V(lH&80!>5$S6l)Y z;Wa*XIwN^3x`8A6YM>SYfz(0_6*!l*nQLf7r@Ev`!}F?LmCKrWyWY@^rIKe1kR>}! z&#udxO#1F;yNU|Q)(EOONGhy>*D?YMO%9jWe=WC4xcZNH=k+h53<&NW#Km@FYNyS delta 699 zcmci8-A;mF0LJmr+FHkLog{Su%?60C^Pn~egI9fxkCzYG48;loK>`)>pn1?ihc&OH zc{gocL|0I49k+F2H}LHL{FX~%xg?$si0q|wPGqnBsMHrwrGpz8jHz+mDJDi?(j@bq;fiB$oy27~fW+@M`*%%HFUn%ES(*k}y{#0(^LYU@g& zhVXFS%Eb<;p>BiB*-;u>UdoTI7z&ECz~X0u${$kSJuK|kGT2?v8a=K zSx&hS13Omh-AdXX>7l84ZD2W&(r2wjJPUY_X_xg7Rzgv>-5W+^IYG1eJ4z4>pEKgf s8|UuGvZV|tGbx9cc>Q_w_Wz>2jfiqvk9*rs$GfW!68u5d*{rPc1tXB@GXMYp diff --git a/savedata/tokens.json b/savedata/tokens.json index dd8fcdf..edbae19 100644 --- a/savedata/tokens.json +++ b/savedata/tokens.json @@ -1 +1 @@ -{"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTIyMTE4NzEsIm5iZiI6MTc5MjIxMTY5MSwic3ViIjoiMjM4MzAyIiwidXNlcm5hbWUiOiJYeHhvdGlxIiwidXNlclR5cGUiOjEsInN0YWdlTmFtZSI6Ilh4eG90aXEiLCJhcHByb3ZlZCI6MSwibG9jYXRpb25JZCI6NDcyLCJzZWFyY2hDaXR5IjoiYXRsYW50YSIsImNvdW50cnlTaG9ydCI6IlVTIiwic2Vzc2lvbkNvdW50cnlDb250aW5lbnQiOiJOQSIsImlzRnJvemVuIjowLCJsb2NhdGlvbkxhYmVsIjoiQXRsYW50YSwgR0EiLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MjIxMTc1MX0.yPPrAkT6ZnR9Y3rLhUkWSgL6X_I0UuKznujBg2L-UkI3kGPZbe2G4ADSZBq0DGxiAVnmglwbhXZHs6QuHwIOTQ", "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bnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MjIyMjgwNCwic3ViIjoiMjM4MzAyIn0.BOPpuwg88qWk5A0XciE2wi_4mC6V9jvnQzWms0vxIkWctsGMQnhLABzuD8Zjofdf1qK5pQXxf9010SYV5c9r8A"} \ No newline at end of file