diff --git a/bot.py b/bot.py index 3b81e2c..c66a94d 100644 --- a/bot.py +++ b/bot.py @@ -42,14 +42,13 @@ class Core: self.set_state('pause') if self.state == 'dialog': current_dialog = mongo.get_current_dialog(self.chat_id) - with redis.lock('search'): - mongo.finish_dialog(current_dialog['_id']) - if self.chat_id == current_dialog['chat_id_1']: - another_chat_id = current_dialog['chat_id_2'] - else: - another_chat_id = current_dialog['chat_id_1'] - self.send_message('πŸ€– Π”ΠΈΠ°Π»ΠΎΠ³ ΠΎΠΊΠΎΠ½Ρ‡Π΅Π½, ΠΆΠ΄Ρƒ тСбя снова!') - self.start_new_dialog([another_chat_id]) + mongo.finish_dialog(current_dialog['_id']) + if self.chat_id == current_dialog['chat_id_1']: + another_chat_id = current_dialog['chat_id_2'] + else: + another_chat_id = current_dialog['chat_id_1'] + self.send_message('πŸ€– Π”ΠΈΠ°Π»ΠΎΠ³ ΠΎΠΊΠΎΠ½Ρ‡Π΅Π½, ΠΆΠ΄Ρƒ тСбя снова!') + self.start_new_dialog([another_chat_id]) return if self.state == 'pause': self.send_message('πŸ€– БСйчас Ρ‚Π²ΠΎΠΉ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚ Π½Π΅ Π°ΠΊΡ‚ΠΈΠ²Π΅Π½. Активируй Π΅Π³ΠΎ с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ /start') @@ -58,14 +57,13 @@ class Core: self.send_message('πŸ€– Поиск собСсСдника ΠΎΠΊΠΎΠ½Ρ‡Π΅Π½, ΠΆΠ΄Ρƒ тСбя снова!') return if self.message_text == '/next' or self.message_text == '/start': - with redis.lock('search'): - if self.state == 'dialog': - dialog = mongo.get_current_dialog(self.chat_id) - self.start_new_dialog([dialog['chat_id_1'], dialog['chat_id_2']]) - return - else: - self.start_new_dialog([self.chat_id]) - return + if self.state == 'dialog': + dialog = mongo.get_current_dialog(self.chat_id) + self.start_new_dialog([dialog['chat_id_1'], dialog['chat_id_2']]) + return + else: + self.start_new_dialog([self.chat_id]) + return def handle_state_search(self): self.send_message('πŸ€– Поиски собСсСдника ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠ°ΡŽΡ‚ΡΡ') diff --git a/tools/redis.py b/tools/redis.py index 6f3e6d1..c248fbf 100644 --- a/tools/redis.py +++ b/tools/redis.py @@ -23,11 +23,6 @@ class RedisClient: with self.cli as cli: cli.set(f"ruletka_{key}", value) - @contextlib.contextmanager - def lock(self, key): - with self.cli.lock(f"ruletka_{key}"): - yield - redis_client = RedisClient( settings.REDIS_HOST,