mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 01:58:23 +02:00
Run matrix script into an async loop
This commit is contained in:
@ -4,8 +4,6 @@
|
||||
from enum import Enum
|
||||
import os
|
||||
|
||||
from asgiref.sync import async_to_sync
|
||||
|
||||
|
||||
class Matrix:
|
||||
"""
|
||||
@ -51,7 +49,6 @@ class Matrix:
|
||||
return client
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def set_display_name(cls, name: str):
|
||||
"""
|
||||
Set the display name of the bot account.
|
||||
@ -60,7 +57,6 @@ class Matrix:
|
||||
return await client.set_displayname(name)
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def set_avatar(cls, avatar_url: str): # pragma: no cover
|
||||
"""
|
||||
Set the display avatar of the bot account.
|
||||
@ -69,7 +65,6 @@ class Matrix:
|
||||
return await client.set_avatar(avatar_url)
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def get_avatar(cls): # pragma: no cover
|
||||
"""
|
||||
Set the display avatar of the bot account.
|
||||
@ -79,7 +74,6 @@ class Matrix:
|
||||
return resp.avatar_url if hasattr(resp, "avatar_url") else resp
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def upload(
|
||||
cls,
|
||||
data_provider,
|
||||
@ -146,7 +140,6 @@ class Matrix:
|
||||
if not isinstance(client, FakeMatrixClient) else None, None
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def create_room(
|
||||
cls,
|
||||
visibility=None,
|
||||
@ -232,7 +225,6 @@ class Matrix:
|
||||
return resp.room_id if resp and hasattr(resp, "room_id") else None
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def invite(cls, room_id: str, user_id: str):
|
||||
"""
|
||||
Invite a user to a room.
|
||||
@ -251,7 +243,6 @@ class Matrix:
|
||||
return await client.room_invite(room_id, user_id)
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def send_message(cls, room_id: str, body: str, formatted_body: str = None,
|
||||
msgtype: str = "m.text", html: bool = True):
|
||||
"""
|
||||
@ -274,7 +265,6 @@ class Matrix:
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def add_integration(cls, room_id: str, widget_url: str, state_key: str,
|
||||
widget_type: str = "customwidget", widget_name: str = "Custom widget",
|
||||
widget_title: str = ""):
|
||||
@ -301,7 +291,6 @@ class Matrix:
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def remove_integration(cls, room_id: str, state_key: str):
|
||||
client = await cls._get_client()
|
||||
if room_id.startswith("#"):
|
||||
@ -314,7 +303,6 @@ class Matrix:
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def kick(cls, room_id: str, user_id: str, reason: str = None):
|
||||
"""
|
||||
Kick a user from a room, or withdraw their invitation.
|
||||
@ -337,7 +325,6 @@ class Matrix:
|
||||
return await client.room_kick(room_id, user_id, reason)
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def set_room_power_level(cls, room_id: str, user_id: str, power_level: int): # pragma: no cover
|
||||
"""
|
||||
Put a given power level to a user in a certain room.
|
||||
@ -364,7 +351,6 @@ class Matrix:
|
||||
return await client.room_put_state(room_id, "m.room.power_levels", content=content, state_key=resp.state_key)
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def set_room_power_level_event(cls, room_id: str, event: str, power_level: int): # pragma: no cover
|
||||
"""
|
||||
Define the minimal power level to have to send a certain event type
|
||||
@ -395,7 +381,6 @@ class Matrix:
|
||||
return await client.room_put_state(room_id, "m.room.power_levels", content=content, state_key=resp.state_key)
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def set_room_avatar(cls, room_id: str, avatar_uri: str):
|
||||
"""
|
||||
Define the avatar of a room.
|
||||
|
Reference in New Issue
Block a user