Updated arg system & made websocked somehow work???

This commit is contained in:
2025-02-08 15:50:33 +01:00
parent e2869fb8a2
commit 1c7170bb81
10 changed files with 77 additions and 52 deletions
+2 -2
View File
@@ -6,7 +6,7 @@ import os
from macros import *
class Bot:
args: list[str] = ["NO_RUST", "--dev", "--py"]
args: dict = {"NO_RUST": True, "dev": True, "py": True, "port": 2920}
password: str = os.environ.get("ASSISTANT_R_PASS")
secret: str = os.environ.get("ASSISTANT_R_TOKEN")
@@ -26,5 +26,5 @@ class Bot:
data_f: TextIOWrapper = None
data: dict = {}
def set_args(self, args: list[str]):
def set_args(self, args: dict):
self.args = args
+5 -4
View File
@@ -15,15 +15,16 @@ def main():
except NameError:
py_print("No command args found from Rust. Don't worry though, we have backup in place.")
py_print("ARGS:", str(bot.args[1:]))
if bot.args["dev"]:
py_print("ARGS:", str(bot.args))
py_print("Reading data...")
data.read_data(bot)
if "--py" not in bot.args:
if True: #bot.args["py"]:
py_print("Connecting to local websocket...")
asyncio.run(py_websocket.websocket_client())
asyncio.run(py_websocket.websocket_client(bot))
py_websocket.send_message("[Connection test] Hello from Python!")
#py_websocket.send_message("[Connection test] Hello from Python!")
main()
+4 -3
View File
@@ -1,5 +1,6 @@
import websockets
from macros import py_print
import bot as botPy
ws_global = None
@@ -9,11 +10,11 @@ async def send_message(message: str):
await ws_global.send(message)
async def websocket_client():
async def websocket_client(bot: botPy.Bot):
global ws_global
async with websockets.connect("ws://127.0.0.1:9001") as ws:
async with websockets.connect(f"ws://127.0.0.1:{bot.args["port"]}") as ws:
ws_global = ws
py_print("Connected webSocket server on ws://127.0.0.1:9001")
py_print(f"Connected webSocket server on ws://127.0.0.1:{bot.args["port"]}")
while True:
response = await ws.recv()