Skip to content

Commit

Permalink
✨ version 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Oct 16, 2023
1 parent 42b8f79 commit 09d9d29
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 37 deletions.
2 changes: 1 addition & 1 deletion nonebot/adapters/satori/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async def _heartbeat(self, info: ClientInfo, ws: WebSocket):
await asyncio.sleep(9)

async def ws(self, info: ClientInfo) -> None:
ws_url = f"ws://{info.host}:{info.port}/v1/events"
ws_url = info.ws_base / "events"
req = Request("GET", ws_url, timeout=60.0)
heartbeat_task: Optional["asyncio.Task"] = None
while True:
Expand Down
88 changes: 53 additions & 35 deletions nonebot/adapters/satori/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async def send_message(
self,
channel_id: str,
message: Union[str, Message, MessageSegment],
):
) -> List[SatoriMessage]:
"""发送消息
参数:
Expand All @@ -228,6 +228,20 @@ async def send_message(
"""
return await self.message_create(channel_id=channel_id, content=str(message))

async def send_private_message(
self,
user_id: str,
message: Union[str, Message, MessageSegment],
) -> List[SatoriMessage]:
"""发送私聊消息
参数:
user_id: 要发送的用户 ID
message: 要发送的消息
"""
channel = await self.user_channel_create(user_id=user_id)
return await self.message_create(channel_id=channel.id, message=message)

async def update_message(
self,
channel_id: str,
Expand All @@ -241,15 +255,15 @@ async def update_message(
message_id: 要更新的消息 ID
message: 要更新的消息
"""
return await self.message_update(channel_id=channel_id, message_id=message_id, content=str(message))
await self.message_update(channel_id=channel_id, message_id=message_id, content=str(message))

@API
async def message_create(
self,
*,
channel_id: str,
content: str,
):
) -> List[SatoriMessage]:
request = Request(
"POST",
self.info.api_base / "message.create",
Expand All @@ -259,7 +273,7 @@ async def message_create(
return [SatoriMessage.parse_obj(i) for i in res]

@API
async def message_get(self, *, channel_id: str, message_id: str):
async def message_get(self, *, channel_id: str, message_id: str) -> SatoriMessage:
request = Request(
"POST",
self.info.api_base / "message.get",
Expand All @@ -269,7 +283,7 @@ async def message_get(self, *, channel_id: str, message_id: str):
return SatoriMessage.parse_obj(res)

@API
async def message_delete(self, *, channel_id: str, message_id: str):
async def message_delete(self, *, channel_id: str, message_id: str) -> None:
request = Request(
"POST",
self.info.api_base / "message.delete",
Expand All @@ -284,7 +298,7 @@ async def message_update(
channel_id: str,
message_id: str,
content: str,
):
) -> None:
request = Request(
"POST",
self.info.api_base / "message.update",
Expand All @@ -297,7 +311,9 @@ async def message_update(
await self._request(request)

@API
async def message_list(self, *, channel_id: str, next_token: Optional[str] = None):
async def message_list(
self, *, channel_id: str, next_token: Optional[str] = None
) -> PageResult[SatoriMessage]:
request = Request(
"POST",
self.info.api_base / "message.list",
Expand All @@ -306,7 +322,7 @@ async def message_list(self, *, channel_id: str, next_token: Optional[str] = Non
return PageResult[SatoriMessage].parse_obj(await self._request(request))

@API
async def channel_get(self, *, channel_id: str):
async def channel_get(self, *, channel_id: str) -> Channel:
request = Request(
"POST",
self.info.api_base / "channel.get",
Expand All @@ -316,7 +332,7 @@ async def channel_get(self, *, channel_id: str):
return Channel.parse_obj(res)

@API
async def channel_list(self, *, guild_id: str, next_token: Optional[str] = None):
async def channel_list(self, *, guild_id: str, next_token: Optional[str] = None) -> PageResult[Channel]:
request = Request(
"POST",
self.info.api_base / "channel.list",
Expand All @@ -325,7 +341,7 @@ async def channel_list(self, *, guild_id: str, next_token: Optional[str] = None)
return PageResult[Channel].parse_obj(await self._request(request))

@API
async def channel_create(self, *, guild_id: str, data: Channel):
async def channel_create(self, *, guild_id: str, data: Channel) -> Channel:
request = Request(
"POST",
self.info.api_base / "channel.create",
Expand All @@ -339,7 +355,7 @@ async def channel_update(
*,
channel_id: str,
data: Channel,
):
) -> None:
request = Request(
"POST",
self.info.api_base / "channel.update",
Expand All @@ -348,7 +364,7 @@ async def channel_update(
await self._request(request)

@API
async def channel_delete(self, *, channel_id: str):
async def channel_delete(self, *, channel_id: str) -> None:
request = Request(
"POST",
self.info.api_base / "channel.delete",
Expand All @@ -357,7 +373,7 @@ async def channel_delete(self, *, channel_id: str):
await self._request(request)

@API
async def user_channel_create(self, *, user_id: str):
async def user_channel_create(self, *, user_id: str) -> Channel:
request = Request(
"POST",
self.info.api_base / "user.channel.create",
Expand All @@ -366,7 +382,7 @@ async def user_channel_create(self, *, user_id: str):
return Channel.parse_obj(await self._request(request))

@API
async def guild_get(self, *, guild_id: str):
async def guild_get(self, *, guild_id: str) -> Guild:
request = Request(
"POST",
self.info.api_base / "guild.get",
Expand All @@ -375,7 +391,7 @@ async def guild_get(self, *, guild_id: str):
return Guild.parse_obj(await self._request(request))

@API
async def guild_list(self, *, next_token: Optional[str] = None):
async def guild_list(self, *, next_token: Optional[str] = None) -> PageResult[Guild]:
request = Request(
"POST",
self.info.api_base / "guild.list",
Expand All @@ -384,7 +400,7 @@ async def guild_list(self, *, next_token: Optional[str] = None):
return PageResult[Guild].parse_obj(await self._request(request))

@API
async def guild_approve(self, *, request_id: str, approve: bool, comment: str):
async def guild_approve(self, *, request_id: str, approve: bool, comment: str) -> None:
request = Request(
"POST",
self.info.api_base / "guild.approve",
Expand All @@ -393,7 +409,9 @@ async def guild_approve(self, *, request_id: str, approve: bool, comment: str):
await self._request(request)

@API
async def guild_member_list(self, *, guild_id: str, next_token: Optional[str] = None):
async def guild_member_list(
self, *, guild_id: str, next_token: Optional[str] = None
) -> PageResult[OuterMember]:
request = Request(
"POST",
self.info.api_base / "guild.member.list",
Expand All @@ -402,7 +420,7 @@ async def guild_member_list(self, *, guild_id: str, next_token: Optional[str] =
return PageResult[OuterMember].parse_obj(await self._request(request))

@API
async def guild_member_get(self, *, guild_id: str, user_id: str):
async def guild_member_get(self, *, guild_id: str, user_id: str) -> OuterMember:
request = Request(
"POST",
self.info.api_base / "guild.member.get",
Expand All @@ -411,7 +429,7 @@ async def guild_member_get(self, *, guild_id: str, user_id: str):
return OuterMember.parse_obj(await self._request(request))

@API
async def guild_member_kick(self, *, guild_id: str, user_id: str, permanent: bool = False):
async def guild_member_kick(self, *, guild_id: str, user_id: str, permanent: bool = False) -> None:
request = Request(
"POST",
self.info.api_base / "guild.member.kick",
Expand All @@ -420,7 +438,7 @@ async def guild_member_kick(self, *, guild_id: str, user_id: str, permanent: boo
await self._request(request)

@API
async def guild_member_approve(self, *, request_id: str, approve: bool, comment: str):
async def guild_member_approve(self, *, request_id: str, approve: bool, comment: str) -> None:
request = Request(
"POST",
self.info.api_base / "guild.member.approve",
Expand All @@ -429,7 +447,7 @@ async def guild_member_approve(self, *, request_id: str, approve: bool, comment:
await self._request(request)

@API
async def guild_member_role_set(self, *, guild_id: str, user_id: str, role_id: str):
async def guild_member_role_set(self, *, guild_id: str, user_id: str, role_id: str) -> None:
request = Request(
"POST",
self.info.api_base / "guild.member.role.set",
Expand All @@ -438,7 +456,7 @@ async def guild_member_role_set(self, *, guild_id: str, user_id: str, role_id: s
await self._request(request)

@API
async def guild_member_role_unset(self, *, guild_id: str, user_id: str, role_id: str):
async def guild_member_role_unset(self, *, guild_id: str, user_id: str, role_id: str) -> None:
request = Request(
"POST",
self.info.api_base / "guild.member.role.unset",
Expand All @@ -447,7 +465,7 @@ async def guild_member_role_unset(self, *, guild_id: str, user_id: str, role_id:
await self._request(request)

@API
async def guild_role_list(self, guild_id: str, next_token: Optional[str] = None):
async def guild_role_list(self, guild_id: str, next_token: Optional[str] = None) -> PageResult[Role]:
request = Request(
"POST",
self.info.api_base / "guild.role.list",
Expand All @@ -461,7 +479,7 @@ async def guild_role_create(
*,
guild_id: str,
role: Role,
):
) -> Role:
request = Request(
"POST",
self.info.api_base / "guild.role.create",
Expand All @@ -476,7 +494,7 @@ async def guild_role_update(
guild_id: str,
role_id: str,
role: Role,
):
) -> None:
request = Request(
"POST",
self.info.api_base / "guild.role.update",
Expand All @@ -485,7 +503,7 @@ async def guild_role_update(
await self._request(request)

@API
async def guild_role_delete(self, *, guild_id: str, role_id: str):
async def guild_role_delete(self, *, guild_id: str, role_id: str) -> None:
request = Request(
"POST",
self.info.api_base / "guild.role.delete",
Expand All @@ -500,7 +518,7 @@ async def reaction_create(
channel_id: str,
message_id: str,
emoji: str,
):
) -> None:
request = Request(
"POST",
self.info.api_base / "reaction.create",
Expand All @@ -516,7 +534,7 @@ async def reaction_delete(
message_id: str,
emoji: str,
user_id: Optional[str] = None,
):
) -> None:
data = {"channel_id": channel_id, "message_id": message_id, "emoji": emoji}
if user_id is not None:
data["user_id"] = user_id
Expand All @@ -534,7 +552,7 @@ async def reaction_clear(
channel_id: str,
message_id: str,
emoji: Optional[str] = None,
):
) -> None:
data = {"channel_id": channel_id, "message_id": message_id}
if emoji is not None:
data["emoji"] = emoji
Expand All @@ -553,7 +571,7 @@ async def reaction_list(
message_id: str,
emoji: str,
next_token: Optional[str] = None,
):
) -> PageResult[User]:
request = Request(
"POST",
self.info.api_base / "reaction.list",
Expand All @@ -567,15 +585,15 @@ async def reaction_list(
return PageResult[User].parse_obj(await self._request(request))

@API
async def login_get(self):
async def login_get(self) -> Login:
request = Request(
"POST",
self.info.api_base / "login.get",
)
return Login.parse_obj(await self._request(request))

@API
async def user_get(self, *, user_id: str):
async def user_get(self, *, user_id: str) -> User:
request = Request(
"POST",
self.info.api_base / "user.get",
Expand All @@ -584,7 +602,7 @@ async def user_get(self, *, user_id: str):
return User.parse_obj(await self._request(request))

@API
async def friend_list(self, *, next_token: Optional[str] = None):
async def friend_list(self, *, next_token: Optional[str] = None) -> PageResult[User]:
request = Request(
"POST",
self.info.api_base / "friend.list",
Expand All @@ -593,7 +611,7 @@ async def friend_list(self, *, next_token: Optional[str] = None):
return PageResult[User].parse_obj(await self._request(request))

@API
async def friend_approve(self, *, request_id: str, approve: bool, comment: str):
async def friend_approve(self, *, request_id: str, approve: bool, comment: str) -> None:
request = Request(
"POST",
self.info.api_base / "friend.approve",
Expand All @@ -607,7 +625,7 @@ async def internal(
*,
action: str,
**kwargs,
):
) -> Any:
request = Request(
"POST",
self.info.api_base / "internal" / action,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nonebot-adapter-satori"
version = "0.5.1"
version = "0.6.0"
description = "Satori Protocol Adapter for Nonebot2"
authors = [
{name = "RF-Tar-Railt",email = "[email protected]"},
Expand Down

0 comments on commit 09d9d29

Please sign in to comment.