mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 07:42:11 +01:00 
			
		
		
		
	Add possibility to load Matrix credentials from env configuration
This commit is contained in:
		@@ -23,14 +23,18 @@ class Matrix:
 | 
			
		||||
        Retrieve the bot account.
 | 
			
		||||
        If not logged, log in and store access token.
 | 
			
		||||
        """
 | 
			
		||||
        if not os.getenv("SYNAPSE_PASSWORD"):
 | 
			
		||||
        if not os.getenv("SYNAPSE_PASSWORD") and not os.getenv("SYNAPSE_TOKEN"):
 | 
			
		||||
            return FakeMatrixClient()
 | 
			
		||||
 | 
			
		||||
        from nio import AsyncClient
 | 
			
		||||
        client = AsyncClient("https://tfjm.org", "@tfjmbot:tfjm.org")
 | 
			
		||||
        client.user_id = "@tfjmbot:tfjm.org"
 | 
			
		||||
 | 
			
		||||
        if os.path.isfile(".matrix_token"):
 | 
			
		||||
        if os.getenv("SYNAPSE_TOKEN"):
 | 
			
		||||
            client.access_token = os.getenv("SYNAPSE_TOKEN")
 | 
			
		||||
            client.device_id = os.getenv("SYNAPSE_DEVICE")
 | 
			
		||||
            return client
 | 
			
		||||
        elif os.path.isfile(".matrix_token"):
 | 
			
		||||
            with open(".matrix_device", "r") as f:
 | 
			
		||||
                cls._device_id = f.read().rstrip(" \t\r\n")
 | 
			
		||||
                client.device_id = cls._device_id
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user