From b6b1b27858e718071c115c64ca607a66385e186a Mon Sep 17 00:00:00 2001 From: Mercurio <47455213+NotLugozzi@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:40:51 +0100 Subject: [PATCH] Added check when adding friends to avoid multiple repeated entries (thx again to @JoeMama for finding this out) --- calls.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/calls.py b/calls.py index 7ec7f2c..f751207 100644 --- a/calls.py +++ b/calls.py @@ -58,20 +58,19 @@ def add_friend(token, friend_uid): else: friends = {} + if friend_uid in friends.values(): + return "Friend already in the list." + index = len(friends) - friend_key = f"friend{index}" - if friend_key not in friends: - friends[friend_key] = friend_uid - friends_json = json.dumps(friends) + friends[friend_key] = friend_uid + friends_json = json.dumps(friends) - cursor.execute( - "UPDATE users SET friend_list = %s WHERE session_token = %s;", - (friends_json, token) - ) - conn.commit() - else: - return False + cursor.execute( + "UPDATE users SET friend_list = %s WHERE session_token = %s;", + (friends_json, token) + ) + conn.commit() return True except Exception as e: