mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-21 04:38:21 +02:00
Define Bot avatar
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import os
|
||||
from typing import Tuple
|
||||
|
||||
from asgiref.sync import async_to_sync
|
||||
from nio import *
|
||||
@ -11,6 +12,7 @@ class Matrix:
|
||||
@classmethod
|
||||
async def _get_client(cls) -> AsyncClient:
|
||||
client = AsyncClient("https://correspondances-maths.fr", "@corres2mathbot:correspondances-maths.fr")
|
||||
client.user_id = "@corres2mathbot:correspondances-maths.fr"
|
||||
|
||||
if os.path.isfile(".matrix_token"):
|
||||
with open(".matrix_device", "r") as f:
|
||||
@ -36,6 +38,26 @@ class Matrix:
|
||||
client = await cls._get_client()
|
||||
return await client.set_displayname(name)
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def set_avatar(cls, avatar_url: str) -> Union[ProfileSetAvatarResponse, ProfileSetAvatarError]:
|
||||
client = await cls._get_client()
|
||||
return await client.set_avatar(avatar_url)
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def upload(
|
||||
cls,
|
||||
data_provider: DataProvider,
|
||||
content_type: str = "application/octet-stream",
|
||||
filename: Optional[str] = None,
|
||||
encrypt: bool = False,
|
||||
monitor: Optional[TransferMonitor] = None,
|
||||
filesize: Optional[int] = None,
|
||||
) -> Tuple[Union[UploadResponse, UploadError], Optional[Dict[str, Any]]]:
|
||||
client = await cls._get_client()
|
||||
return await client.upload(data_provider, content_type, filename, encrypt, monitor, filesize)
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def create_room(
|
||||
@ -93,7 +115,6 @@ class Matrix:
|
||||
resp = await client.room_get_state_event(room_id, "m.room.power_levels")
|
||||
content = resp.content
|
||||
content["users"][user_id] = power_level
|
||||
print(content)
|
||||
return await client.room_put_state(room_id, "m.room.power_levels", content=content, state_key=resp.state_key)
|
||||
|
||||
@classmethod
|
||||
@ -109,5 +130,4 @@ class Matrix:
|
||||
content["events"][event] = power_level
|
||||
else:
|
||||
content[event] = power_level
|
||||
print(content)
|
||||
return await client.room_put_state(room_id, "m.room.power_levels", content=content, state_key=resp.state_key)
|
||||
|
Reference in New Issue
Block a user