summary refs log tree commit diff
path: root/main.py
diff options
context:
space:
mode:
authorberry :3 <[email protected]>2025-04-18 09:28:31 +0300
committerberry :3 <[email protected]>2025-04-18 09:28:31 +0300
commit567b0eab426eb28968986411beea60dcc6317c08 (patch)
treee9743452a7eebd89985f8eaf74e7b1ad739e9d00 /main.py
parent51be80e166c2dac6633b75a10360a0bbca6f4123 (diff)
livechat HEAD master
Diffstat (limited to 'main.py')
-rw-r--r--main.py43
1 files changed, 43 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: