diff --git a/olgram/settings.py b/olgram/settings.py index 906370e..1cb5b72 100644 --- a/olgram/settings.py +++ b/olgram/settings.py @@ -89,7 +89,7 @@ class ServerSettings(AbstractSettings): @classmethod @lru_cache def redis_timeout_ms(cls) -> ty.Optional[int]: - return int(timedelta(days=30).total_seconds() * 1000.0) + return int(timedelta(days=20).total_seconds() * 1000.0) @classmethod @lru_cache diff --git a/server/custom.py b/server/custom.py index 830f205..f78b959 100644 --- a/server/custom.py +++ b/server/custom.py @@ -45,10 +45,17 @@ async def send_user_message(message: types.Message, super_chat_id: int, bot): user_info += " | @" + message.from_user.username user_info += f" | #{message.from_user.id}" new_message = await message.bot.send_message(super_chat_id, text=user_info) - await message.copy_to(super_chat_id, reply_to_message_id=new_message.message_id) + await _redis.set(_message_unique_id(bot.pk, new_message.message_id), message.chat.id, + pexpire=ServerSettings.redis_timeout_ms()) + new_message_2 = await message.copy_to(super_chat_id, reply_to_message_id=new_message.message_id) + await _redis.set(_message_unique_id(bot.pk, new_message_2.message_id), message.chat.id, + pexpire=ServerSettings.redis_timeout_ms()) return new_message else: - return await message.forward(super_chat_id) + new_message = await message.forward(super_chat_id) + await _redis.set(_message_unique_id(bot.pk, new_message.message_id), message.chat.id, + pexpire=ServerSettings.redis_timeout_ms()) + return new_message async def handle_user_message(message: types.Message, super_chat_id: int, bot): @@ -81,9 +88,6 @@ async def handle_user_message(message: types.Message, super_chat_id: int, bot): else: # личные сообщения не поддерживают потоки сообщений: простой forward new_message = await send_user_message(message, super_chat_id, bot) - await _redis.set(_message_unique_id(bot.pk, new_message.message_id), message.chat.id, - pexpire=ServerSettings.redis_timeout_ms()) - bot.incoming_messages_count = F("incoming_messages_count") + 1 await bot.save(update_fields=["incoming_messages_count"])