From df103f6e9da1a2cf29a724aa5ac6cf90cf78d7a2 Mon Sep 17 00:00:00 2001 From: 201st-Luka Date: Wed, 23 Aug 2023 10:57:51 +0200 Subject: [PATCH] fix: `client.client_id` cannot be set to taken value fixed the bug which allowed to set multiple client ids to the same value --- pyclasher/client.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pyclasher/client.py b/pyclasher/client.py index 09b7986..47c59d0 100644 --- a/pyclasher/client.py +++ b/pyclasher/client.py @@ -189,9 +189,17 @@ def client_id(self): @client_id.setter def client_id(self, new_id): + global client_id + if isinstance(new_id, str) and new_id.isdigit(): + new_id = int(new_id) + if not isinstance(new_id, (int, str)): raise TypeError(f"Expected types int, str got {type(new_id)} " f"instead.") + for client in Client.__instances: + if client.client_id == new_id: + raise ValueError(f"`new_id` {new_id} has already been taken " + f"and must be different") self._client_id = new_id return