feat: add get_user method

to check if already registered
This commit is contained in:
əlemi 2024-01-30 16:41:32 +01:00
parent b5a6d29ba0
commit 0e26e22785
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -6,7 +6,7 @@ from typing import Callable, Awaitable
from aiohttp import ClientSession, web
from .matrix import Event, EventType
from .matrix import Event, EventType, User
from .utils import mx_message, fmt_mxid
class AppService:
@ -99,6 +99,18 @@ class AppService:
"Content-Type": "application/json",
}
async def get_user(self, mxid: str) -> User | None:
async with self._client.request(
method="GET",
url=f"{self.client_api}/profile/{mxid}",
headers=self.api_headers,
) as res:
if res.status == 404:
return None
res.raise_for_status()
doc = await res.json()
return User(**doc)
async def register_mxid(self, mxid: str) -> None:
bare_mxid = fmt_mxid(mxid, full=False)
async with self._client.request(