Added check when adding friends to avoid multiple repeated entries (thx again to @JoeMama for finding this out)
This commit is contained in:
parent
d04dcce8e4
commit
b6b1b27858
21
calls.py
21
calls.py
|
@ -58,20 +58,19 @@ def add_friend(token, friend_uid):
|
||||||
else:
|
else:
|
||||||
friends = {}
|
friends = {}
|
||||||
|
|
||||||
|
if friend_uid in friends.values():
|
||||||
|
return "Friend already in the list."
|
||||||
|
|
||||||
index = len(friends)
|
index = len(friends)
|
||||||
|
|
||||||
friend_key = f"friend{index}"
|
friend_key = f"friend{index}"
|
||||||
if friend_key not in friends:
|
friends[friend_key] = friend_uid
|
||||||
friends[friend_key] = friend_uid
|
friends_json = json.dumps(friends)
|
||||||
friends_json = json.dumps(friends)
|
|
||||||
|
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"UPDATE users SET friend_list = %s WHERE session_token = %s;",
|
"UPDATE users SET friend_list = %s WHERE session_token = %s;",
|
||||||
(friends_json, token)
|
(friends_json, token)
|
||||||
)
|
)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in a new issue