2 files changed, 46 insertions, 0 deletions
diff --git a/main.py b/main.py
index 4b81068..f5a0209 100644
--- a/main.py
+++ b/main.py
@@ -540,6 +540,49 @@ async def handler(websocket):
if str(websocket.id) not in client_data:
await websocket.send(util.error("unauthorized", listener))
continue
+ if "chat" in r and r["chat"] == "livechat":
+ attachments = []
+ for i in r["attachments"]:
+ if urlparse(i).hostname in attachment_whitelist:
+ attachments.append(i)
+ if len(r["content"]) == 0 and len(r["attachments"]) == 0:
+ await websocket.send(util.error("lengthInvalid", listener))
+ continue
+ username = client_data[str(websocket.id)]["username"]
+ author = util.author_data(username)
+ replies = []
+ for i in r["replies"]:
+ post = db.posts.get_by_id(i)
+ if type(post) == dict and i not in replies:
+ replies.append(post)
+ data = {
+ "_id": str(uuid.uuid4()),
+ "created": time.time(),
+ "content": r["content"],
+ "replies": replies,
+ "attachments": attachments,
+ "author": username
+ }
+ # posted = db.posts.add(data)
+ # if posted != True:
+ # await websocket.send(util.error(fc, listener))
+ # continue
+ data["author"] = author
+ data["origin"] = "livechat"
+ incr = -1
+ for j in data["replies"]:
+ incr += 1
+ reply_author = db.acc.get_author(j["author"])
+ if type(reply_author) != dict:
+ reply_author = {}
+ data["replies"][incr]["author"] = reply_author
+ broadcast(clients, json.dumps({
+ "command": "new_post",
+ "origin": "livechat",
+ "data": data
+ }))
+ await websocket.send(json.dumps({"error": False, "listener": listener}))
+ continue
attachments = []
for i in r["attachments"]:
if urlparse(i).hostname in attachment_whitelist:
diff --git a/start.sh b/start.sh
new file mode 100755
index 0000000..6ee90a4
--- /dev/null
+++ b/start.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+cd /stuff/soktdeer/deer
+./.venv/bin/python main.py
|