feat: add get_user method
to check if already registered
This commit is contained in:
parent
b5a6d29ba0
commit
0e26e22785
1 changed files with 13 additions and 1 deletions
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue