Style updates & minor fixes
This commit is contained in:
parent
143e1f23f8
commit
421bba7f1f
@ -17,7 +17,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
from mautrix.appservice import IntentAPI
|
|
||||||
from mautrix.types import Format, MessageEventContent, RelationType, RoomID, UserID
|
from mautrix.types import Format, MessageEventContent, RelationType, RoomID, UserID
|
||||||
from mautrix.util import utf16_surrogate
|
from mautrix.util import utf16_surrogate
|
||||||
from mautrix.util.formatter import (
|
from mautrix.util.formatter import (
|
||||||
|
@ -125,18 +125,18 @@ class Client:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def register_device(cls, passcode: str, **req: JSON) -> None:
|
def register_device(cls, passcode: str, **req: JSON) -> Awaitable[None]:
|
||||||
"""Register a (fake) device that will be associated with the provided login credentials."""
|
"""Register a (fake) device that will be associated with the provided login credentials."""
|
||||||
await cls._api_request_void("register_device", passcode=passcode, **req)
|
return cls._api_request_void("register_device", passcode=passcode, **req)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def login(cls, **req: JSON) -> OAuthCredential:
|
async def login(cls, **req: JSON) -> Awaitable[OAuthCredential]:
|
||||||
"""
|
"""
|
||||||
Obtain a session token by logging in with user-provided credentials.
|
Obtain a session token by logging in with user-provided credentials.
|
||||||
Must have first called register_device with these credentials.
|
Must have first called register_device with these credentials.
|
||||||
"""
|
"""
|
||||||
# NOTE Actually returns an auth LoginData, but this only needs an OAuthCredential
|
# NOTE Actually returns an auth LoginData, but this only needs an OAuthCredential
|
||||||
return await cls._api_request_result(OAuthCredential, "login", **req)
|
return cls._api_request_result(OAuthCredential, "login", **req)
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
@ -254,8 +254,8 @@ class Client:
|
|||||||
await self._rpc_client.request("disconnect", mxid=self.user.mxid)
|
await self._rpc_client.request("disconnect", mxid=self.user.mxid)
|
||||||
await self._on_disconnect(None)
|
await self._on_disconnect(None)
|
||||||
|
|
||||||
async def get_settings(self) -> SettingsStruct:
|
def get_settings(self) -> Awaitable[SettingsStruct]:
|
||||||
return await self._api_user_request_result(SettingsStruct, "get_settings")
|
return self._api_user_request_result(SettingsStruct, "get_settings")
|
||||||
|
|
||||||
async def get_own_profile(self) -> ProfileStruct:
|
async def get_own_profile(self) -> ProfileStruct:
|
||||||
profile_req_struct = await self._api_user_request_result(ProfileReqStruct, "get_own_profile")
|
profile_req_struct = await self._api_user_request_result(ProfileReqStruct, "get_own_profile")
|
||||||
@ -269,22 +269,22 @@ class Client:
|
|||||||
)
|
)
|
||||||
return profile_req_struct.profile
|
return profile_req_struct.profile
|
||||||
|
|
||||||
async def get_portal_channel_info(self, channel_props: ChannelProps) -> PortalChannelInfo:
|
def get_portal_channel_info(self, channel_props: ChannelProps) -> Awaitable[PortalChannelInfo]:
|
||||||
return await self._api_user_request_result(
|
return self._api_user_request_result(
|
||||||
PortalChannelInfo,
|
PortalChannelInfo,
|
||||||
"get_portal_channel_info",
|
"get_portal_channel_info",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get_participants(self, channel_props: ChannelProps) -> list[UserInfoUnion]:
|
def get_participants(self, channel_props: ChannelProps) -> Awaitable[list[UserInfoUnion]]:
|
||||||
return await self._api_user_request_result(
|
return self._api_user_request_result(
|
||||||
ResultListType(UserInfoUnion),
|
ResultListType(UserInfoUnion),
|
||||||
"get_participants",
|
"get_participants",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get_chats(self, channel_props: ChannelProps, sync_from: Long | None, limit: int | None) -> list[Chatlog]:
|
def get_chats(self, channel_props: ChannelProps, sync_from: Long | None, limit: int | None) -> Awaitable[list[Chatlog]]:
|
||||||
return await self._api_user_request_result(
|
return self._api_user_request_result(
|
||||||
ResultListType(Chatlog),
|
ResultListType(Chatlog),
|
||||||
"get_chats",
|
"get_chats",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
@ -292,8 +292,8 @@ class Client:
|
|||||||
limit=limit,
|
limit=limit,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def list_friends(self) -> FriendListStruct:
|
def list_friends(self) -> Awaitable[FriendListStruct]:
|
||||||
return await self._api_user_request_result(
|
return self._api_user_request_result(
|
||||||
FriendListStruct,
|
FriendListStruct,
|
||||||
"list_friends",
|
"list_friends",
|
||||||
)
|
)
|
||||||
@ -314,14 +314,14 @@ class Client:
|
|||||||
await self._rpc_client.request("get_memo_ids", mxid=self.user.mxid)
|
await self._rpc_client.request("get_memo_ids", mxid=self.user.mxid)
|
||||||
)
|
)
|
||||||
|
|
||||||
async def send_chat(
|
def send_chat(
|
||||||
self,
|
self,
|
||||||
channel_props: ChannelProps,
|
channel_props: ChannelProps,
|
||||||
text: str,
|
text: str,
|
||||||
reply_to: ReplyAttachment | None,
|
reply_to: ReplyAttachment | None,
|
||||||
mentions: list[MentionStruct] | None,
|
mentions: list[MentionStruct] | None,
|
||||||
) -> Long:
|
) -> Awaitable[Long]:
|
||||||
return await self._api_user_request_result(
|
return self._api_user_request_result(
|
||||||
Long,
|
Long,
|
||||||
"send_chat",
|
"send_chat",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
@ -330,7 +330,7 @@ class Client:
|
|||||||
mentions=[m.serialize() for m in mentions] if mentions is not None else None,
|
mentions=[m.serialize() for m in mentions] if mentions is not None else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def send_media(
|
def send_media(
|
||||||
self,
|
self,
|
||||||
channel_props: ChannelProps,
|
channel_props: ChannelProps,
|
||||||
media_type: KnownChatType,
|
media_type: KnownChatType,
|
||||||
@ -340,8 +340,8 @@ class Client:
|
|||||||
width: int | None = None,
|
width: int | None = None,
|
||||||
height: int | None = None,
|
height: int | None = None,
|
||||||
ext: str | None = None,
|
ext: str | None = None,
|
||||||
) -> Long:
|
) -> Awaitable[Long]:
|
||||||
return await self._api_user_request_result(
|
return self._api_user_request_result(
|
||||||
Long,
|
Long,
|
||||||
"send_media",
|
"send_media",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
@ -353,69 +353,69 @@ class Client:
|
|||||||
ext=ext,
|
ext=ext,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def delete_chat(
|
def delete_chat(
|
||||||
self,
|
self,
|
||||||
channel_props: ChannelProps,
|
channel_props: ChannelProps,
|
||||||
chat_id: Long,
|
chat_id: Long,
|
||||||
) -> None:
|
) -> Awaitable[None]:
|
||||||
return await self._api_user_request_void(
|
return self._api_user_request_void(
|
||||||
"delete_chat",
|
"delete_chat",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
chat_id=chat_id.serialize(),
|
chat_id=chat_id.serialize(),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def mark_read(
|
def mark_read(
|
||||||
self,
|
self,
|
||||||
channel_props: ChannelProps,
|
channel_props: ChannelProps,
|
||||||
read_until_chat_id: Long,
|
read_until_chat_id: Long,
|
||||||
) -> None:
|
) -> Awaitable[None]:
|
||||||
return await self._api_user_request_void(
|
return self._api_user_request_void(
|
||||||
"mark_read",
|
"mark_read",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
read_until_chat_id=read_until_chat_id.serialize(),
|
read_until_chat_id=read_until_chat_id.serialize(),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def send_perm(
|
def send_perm(
|
||||||
self,
|
self,
|
||||||
channel_props: ChannelProps,
|
channel_props: ChannelProps,
|
||||||
user_id: Long,
|
user_id: Long,
|
||||||
perm: OpenChannelUserPerm,
|
perm: OpenChannelUserPerm,
|
||||||
) -> None:
|
) -> Awaitable[None]:
|
||||||
return await self._api_user_request_void(
|
return self._api_user_request_void(
|
||||||
"send_perm",
|
"send_perm",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
user_id=user_id.serialize(),
|
user_id=user_id.serialize(),
|
||||||
perm=perm,
|
perm=perm,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def set_channel_name(
|
def set_channel_name(
|
||||||
self,
|
self,
|
||||||
channel_props: ChannelProps,
|
channel_props: ChannelProps,
|
||||||
name: str,
|
name: str,
|
||||||
) -> None:
|
) -> Awaitable[None]:
|
||||||
return await self._api_user_request_void(
|
return self._api_user_request_void(
|
||||||
"set_channel_name",
|
"set_channel_name",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
name=name,
|
name=name,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def set_channel_description(
|
def set_channel_description(
|
||||||
self,
|
self,
|
||||||
channel_props: ChannelProps,
|
channel_props: ChannelProps,
|
||||||
description: str,
|
description: str,
|
||||||
) -> None:
|
) -> Awaitable[None]:
|
||||||
return await self._api_user_request_void(
|
return self._api_user_request_void(
|
||||||
"set_channel_description",
|
"set_channel_description",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
description=description,
|
description=description,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def set_channel_photo(
|
def set_channel_photo(
|
||||||
self,
|
self,
|
||||||
channel_props: ChannelProps,
|
channel_props: ChannelProps,
|
||||||
photo_url: str,
|
photo_url: str,
|
||||||
) -> None:
|
) -> Awaitable[None]:
|
||||||
return await self._api_user_request_void(
|
return self._api_user_request_void(
|
||||||
"set_channel_photo",
|
"set_channel_photo",
|
||||||
channel_props=channel_props.serialize(),
|
channel_props=channel_props.serialize(),
|
||||||
photo_url=photo_url,
|
photo_url=photo_url,
|
||||||
|
@ -241,6 +241,7 @@ class User(DBUser, BaseUser):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def oauth_credential(self) -> OAuthCredential:
|
def oauth_credential(self) -> OAuthCredential:
|
||||||
|
assert None not in (self.ktid, self.uuid, self.access_token, self.refresh_token)
|
||||||
return OAuthCredential(
|
return OAuthCredential(
|
||||||
self.ktid,
|
self.ktid,
|
||||||
self.uuid,
|
self.uuid,
|
||||||
@ -383,6 +384,7 @@ class User(DBUser, BaseUser):
|
|||||||
|
|
||||||
async def post_login(self, is_startup: bool) -> None:
|
async def post_login(self, is_startup: bool) -> None:
|
||||||
self.log.info("Running post-login actions")
|
self.log.info("Running post-login actions")
|
||||||
|
assert self.ktid
|
||||||
self._add_to_cache()
|
self._add_to_cache()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -407,7 +409,7 @@ class User(DBUser, BaseUser):
|
|||||||
pu.Puppet.get_mxid_from_id(portal.ktid): [portal.mxid]
|
pu.Puppet.get_mxid_from_id(portal.ktid): [portal.mxid]
|
||||||
async for portal in po.Portal.get_all_by_receiver(self.ktid)
|
async for portal in po.Portal.get_all_by_receiver(self.ktid)
|
||||||
if portal.mxid
|
if portal.mxid
|
||||||
}
|
} if self.ktid else {}
|
||||||
|
|
||||||
@async_time(METRIC_CONNECT_AND_SYNC)
|
@async_time(METRIC_CONNECT_AND_SYNC)
|
||||||
async def connect_and_sync(self, sync_count: int | None) -> bool:
|
async def connect_and_sync(self, sync_count: int | None) -> bool:
|
||||||
@ -503,7 +505,8 @@ class User(DBUser, BaseUser):
|
|||||||
|
|
||||||
return self._sync_channel(channel_info)
|
return self._sync_channel(channel_info)
|
||||||
|
|
||||||
async def _sync_channel(self, channel_info: ChannelInfo):
|
async def _sync_channel(self, channel_info: ChannelInfo) -> None:
|
||||||
|
assert self.ktid
|
||||||
portal = await po.Portal.get_by_ktid(
|
portal = await po.Portal.get_by_ktid(
|
||||||
channel_info.channelId,
|
channel_info.channelId,
|
||||||
kt_receiver=self.ktid,
|
kt_receiver=self.ktid,
|
||||||
@ -692,6 +695,7 @@ class User(DBUser, BaseUser):
|
|||||||
|
|
||||||
@async_time(METRIC_CHAT)
|
@async_time(METRIC_CHAT)
|
||||||
async def on_chat(self, chat: Chatlog, channel_id: Long, channel_type: ChannelType) -> None:
|
async def on_chat(self, chat: Chatlog, channel_id: Long, channel_type: ChannelType) -> None:
|
||||||
|
assert self.ktid
|
||||||
portal = await po.Portal.get_by_ktid(
|
portal = await po.Portal.get_by_ktid(
|
||||||
channel_id,
|
channel_id,
|
||||||
kt_receiver=self.ktid,
|
kt_receiver=self.ktid,
|
||||||
@ -712,6 +716,7 @@ class User(DBUser, BaseUser):
|
|||||||
channel_id: Long,
|
channel_id: Long,
|
||||||
channel_type: ChannelType,
|
channel_type: ChannelType,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
assert self.ktid
|
||||||
portal = await po.Portal.get_by_ktid(
|
portal = await po.Portal.get_by_ktid(
|
||||||
channel_id,
|
channel_id,
|
||||||
kt_receiver=self.ktid,
|
kt_receiver=self.ktid,
|
||||||
@ -731,6 +736,7 @@ class User(DBUser, BaseUser):
|
|||||||
channel_id: Long,
|
channel_id: Long,
|
||||||
channel_type: ChannelType,
|
channel_type: ChannelType,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
assert self.ktid
|
||||||
puppet = await pu.Puppet.get_by_ktid(sender_id)
|
puppet = await pu.Puppet.get_by_ktid(sender_id)
|
||||||
portal = await po.Portal.get_by_ktid(
|
portal = await po.Portal.get_by_ktid(
|
||||||
channel_id,
|
channel_id,
|
||||||
@ -749,13 +755,14 @@ class User(DBUser, BaseUser):
|
|||||||
channel_id: Long,
|
channel_id: Long,
|
||||||
channel_type: ChannelType,
|
channel_type: ChannelType,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
assert self.ktid
|
||||||
portal = await po.Portal.get_by_ktid(
|
portal = await po.Portal.get_by_ktid(
|
||||||
channel_id,
|
channel_id,
|
||||||
kt_receiver=self.ktid,
|
kt_receiver=self.ktid,
|
||||||
kt_type=channel_type,
|
kt_type=channel_type,
|
||||||
)
|
)
|
||||||
if portal:
|
await portal.backfill_lock.wait("meta change")
|
||||||
await portal.update_info(self, info)
|
await portal.update_info(self, info)
|
||||||
|
|
||||||
@async_time(METRIC_PROFILE_CHANGE)
|
@async_time(METRIC_PROFILE_CHANGE)
|
||||||
async def on_profile_changed(self, info: OpenLinkChannelUserInfo) -> None:
|
async def on_profile_changed(self, info: OpenLinkChannelUserInfo) -> None:
|
||||||
@ -771,6 +778,7 @@ class User(DBUser, BaseUser):
|
|||||||
channel_id: Long,
|
channel_id: Long,
|
||||||
channel_type: ChannelType,
|
channel_type: ChannelType,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
assert self.ktid
|
||||||
portal = await po.Portal.get_by_ktid(
|
portal = await po.Portal.get_by_ktid(
|
||||||
channel_id,
|
channel_id,
|
||||||
kt_receiver=self.ktid,
|
kt_receiver=self.ktid,
|
||||||
@ -783,18 +791,22 @@ class User(DBUser, BaseUser):
|
|||||||
await portal.set_power_levels(user_power_levels)
|
await portal.set_power_levels(user_power_levels)
|
||||||
|
|
||||||
@async_time(METRIC_CHANNEL_JOIN)
|
@async_time(METRIC_CHANNEL_JOIN)
|
||||||
def on_channel_join(self, channel_info: ChannelInfo) -> Awaitable[None]:
|
async def on_channel_join(self, channel_info: ChannelInfo) -> None:
|
||||||
return self._sync_channel(channel_info)
|
assert self.ktid
|
||||||
|
await self._sync_channel(channel_info)
|
||||||
|
|
||||||
@async_time(METRIC_CHANNEL_LEFT)
|
@async_time(METRIC_CHANNEL_LEFT)
|
||||||
async def on_channel_left(self, channel_id: Long, channel_type: ChannelType) -> None:
|
async def on_channel_left(self, channel_id: Long, channel_type: ChannelType | None) -> None:
|
||||||
|
assert self.ktid
|
||||||
portal = await po.Portal.get_by_ktid(
|
portal = await po.Portal.get_by_ktid(
|
||||||
channel_id,
|
channel_id,
|
||||||
kt_receiver=self.ktid,
|
kt_receiver=self.ktid,
|
||||||
kt_type=channel_type,
|
kt_type=channel_type,
|
||||||
)
|
)
|
||||||
if portal.mxid:
|
if portal.mxid:
|
||||||
await portal.main_intent.kick_user(portal.mxid, self.mxid, "Left this channel from KakaoTalk")
|
user = await pu.Puppet.get_by_ktid(self.ktid)
|
||||||
|
await portal.backfill_lock.wait("channel left")
|
||||||
|
await portal.handle_kakaotalk_user_left(self, user, user)
|
||||||
|
|
||||||
@async_time(METRIC_CHANNEL_KICKED)
|
@async_time(METRIC_CHANNEL_KICKED)
|
||||||
async def on_channel_kicked(
|
async def on_channel_kicked(
|
||||||
@ -804,6 +816,7 @@ class User(DBUser, BaseUser):
|
|||||||
channel_id: Long,
|
channel_id: Long,
|
||||||
channel_type: ChannelType
|
channel_type: ChannelType
|
||||||
) -> None:
|
) -> None:
|
||||||
|
assert self.ktid
|
||||||
portal = await po.Portal.get_by_ktid(
|
portal = await po.Portal.get_by_ktid(
|
||||||
channel_id,
|
channel_id,
|
||||||
kt_receiver=self.ktid,
|
kt_receiver=self.ktid,
|
||||||
@ -822,6 +835,7 @@ class User(DBUser, BaseUser):
|
|||||||
channel_id: Long,
|
channel_id: Long,
|
||||||
channel_type: ChannelType
|
channel_type: ChannelType
|
||||||
) -> None:
|
) -> None:
|
||||||
|
assert self.ktid
|
||||||
portal = await po.Portal.get_by_ktid(
|
portal = await po.Portal.get_by_ktid(
|
||||||
channel_id,
|
channel_id,
|
||||||
kt_receiver=self.ktid,
|
kt_receiver=self.ktid,
|
||||||
@ -839,6 +853,7 @@ class User(DBUser, BaseUser):
|
|||||||
channel_id: Long,
|
channel_id: Long,
|
||||||
channel_type: ChannelType
|
channel_type: ChannelType
|
||||||
) -> None:
|
) -> None:
|
||||||
|
assert self.ktid
|
||||||
portal = await po.Portal.get_by_ktid(
|
portal = await po.Portal.get_by_ktid(
|
||||||
channel_id,
|
channel_id,
|
||||||
kt_receiver=self.ktid,
|
kt_receiver=self.ktid,
|
||||||
|
@ -29,8 +29,8 @@ import {
|
|||||||
/** @typedef {import("node-kakao").MentionStruct} MentionStruct */
|
/** @typedef {import("node-kakao").MentionStruct} MentionStruct */
|
||||||
/** @typedef {import("node-kakao/dist/talk").TalkChannelList} TalkChannelList */
|
/** @typedef {import("node-kakao/dist/talk").TalkChannelList} TalkChannelList */
|
||||||
|
|
||||||
import pkg from "node-kakao"
|
import openlink from "node-kakao/openlink"
|
||||||
const { OpenChannelUserPerm } = pkg
|
const { OpenChannelUserPerm } = openlink
|
||||||
|
|
||||||
import chat from "node-kakao/chat"
|
import chat from "node-kakao/chat"
|
||||||
const { KnownChatType } = chat
|
const { KnownChatType } = chat
|
||||||
@ -317,9 +317,7 @@ class UserClient {
|
|||||||
this.#talkClient.channelList,
|
this.#talkClient.channelList,
|
||||||
channelProps.type
|
channelProps.type
|
||||||
)
|
)
|
||||||
const res = await channelList.addChannel({
|
const res = await channelList.addChannel({ channelId: channelProps.id })
|
||||||
channelId: channelProps.id,
|
|
||||||
})
|
|
||||||
if (!res.success) {
|
if (!res.success) {
|
||||||
throw new Error(`Unable to add ${channelProps.type} channel ${channelProps.id}`)
|
throw new Error(`Unable to add ${channelProps.type} channel ${channelProps.id}`)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user