mirror of
				https://gitlab.com/animath/si/plateforme-corres2math.git
				synced 2025-11-04 11:52:27 +01:00 
			
		
		
		
	Define Bot avatar
This commit is contained in:
		@@ -1,7 +1,9 @@
 | 
			
		||||
import os
 | 
			
		||||
 | 
			
		||||
from asgiref.sync import async_to_sync
 | 
			
		||||
from nio import RoomPreset
 | 
			
		||||
 | 
			
		||||
from corres2math.matrix import Matrix, RoomVisibility
 | 
			
		||||
from corres2math.matrix import Matrix, RoomVisibility, UploadError
 | 
			
		||||
from django.core.management import BaseCommand
 | 
			
		||||
from registration.models import AdminRegistration, Registration
 | 
			
		||||
 | 
			
		||||
@@ -10,6 +12,20 @@ class Command(BaseCommand):
 | 
			
		||||
    def handle(self, *args, **options):
 | 
			
		||||
        Matrix.set_display_name("Bot des Correspondances")
 | 
			
		||||
 | 
			
		||||
        if not os.path.isfile(".matrix_avatar"):
 | 
			
		||||
            stat_file = os.stat("corres2math/static/logo.png")
 | 
			
		||||
            with open("corres2math/static/logo.png", "rb") as f:
 | 
			
		||||
                resp, _ = Matrix.upload(f, filename="logo.png", content_type="image/png", filesize=stat_file.st_size)
 | 
			
		||||
            if isinstance(resp, UploadError):
 | 
			
		||||
                raise Exception(resp)
 | 
			
		||||
            avatar_uri = resp.content_uri
 | 
			
		||||
            with open(".matrix_avatar", "w") as f:
 | 
			
		||||
                f.write(avatar_uri)
 | 
			
		||||
            Matrix.set_avatar(avatar_uri)
 | 
			
		||||
        else:
 | 
			
		||||
            with open(".matrix_avatar", "r") as f:
 | 
			
		||||
                avatar_uri = f.read().rstrip(" \t\r\n")
 | 
			
		||||
 | 
			
		||||
        if not async_to_sync(Matrix.resolve_room_alias)("#faq:correspondances-maths.fr"):
 | 
			
		||||
            Matrix.create_room(
 | 
			
		||||
                visibility=RoomVisibility.public,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user