This repository has been archived on 2024-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
VencordEAS/main.py

38 lines
920 B
Python
Raw Normal View History

2024-06-17 18:06:19 -04:00
import asyncio
2024-06-17 18:09:56 -04:00
import os
2024-06-17 18:06:19 -04:00
import websockets
2024-06-17 18:09:56 -04:00
from dotenv import load_dotenv
load_dotenv()
2024-06-17 18:06:19 -04:00
CONNECTIONS = set()
EAS_MESSAGE = ""
2024-06-17 18:09:56 -04:00
TOKEN = os.getenv("TOKEN")
2024-06-17 18:06:19 -04:00
async def handle(websocket):
global EAS_MESSAGE
# register clients
if websocket not in CONNECTIONS:
CONNECTIONS.add(websocket)
async for message in websocket:
2024-06-17 18:11:57 -04:00
if message == "GET":
await websocket.send(f"MSG {EAS_MESSAGE}")
2024-06-17 18:06:19 -04:00
if message.startswith(f"MSG {TOKEN} "):
# broadcast from vee
EAS_MESSAGE = message.replace(f"MSG {TOKEN} ", "")
websockets.broadcast(CONNECTIONS, f"MSG {EAS_MESSAGE}")
2024-06-18 01:07:04 -04:00
if message.startswith(f"CLEAR {TOKEN}"):
2024-06-17 18:06:19 -04:00
# clear
EAS_MESSAGE = ""
await websocket.send(f"OK")
async def main():
async with websockets.serve(handle, "0.0.0.0", 8765):
await asyncio.Future() # run forever
asyncio.run(main())