attenpy 0.2.1__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. {attenpy-0.2.1 → attenpy-0.4.0}/PKG-INFO +1 -1
  2. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/__init__.py +17 -3
  3. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/client.py +24 -5
  4. attenpy-0.4.0/attenpy/endpoints/__init__.py +17 -0
  5. attenpy-0.4.0/attenpy/endpoints/chats.py +83 -0
  6. attenpy-0.4.0/attenpy/endpoints/explores.py +42 -0
  7. attenpy-0.4.0/attenpy/endpoints/me.py +90 -0
  8. attenpy-0.4.0/attenpy/endpoints/messages.py +21 -0
  9. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/endpoints/notices.py +9 -10
  10. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/endpoints/posts.py +38 -27
  11. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/endpoints/users.py +25 -47
  12. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/http.py +26 -30
  13. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/models/__init__.py +19 -4
  14. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/models/attachment.py +8 -8
  15. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/models/base.py +3 -3
  16. attenpy-0.4.0/attenpy/models/bot.py +16 -0
  17. attenpy-0.4.0/attenpy/models/chat.py +73 -0
  18. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/models/notice.py +26 -18
  19. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/models/post.py +10 -2
  20. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/models/user.py +11 -2
  21. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/pagination.py +2 -2
  22. attenpy-0.4.0/attenpy/payloads/__init__.py +14 -0
  23. attenpy-0.4.0/attenpy/payloads/chat.py +5 -0
  24. attenpy-0.4.0/attenpy/payloads/explore.py +22 -0
  25. attenpy-0.4.0/attenpy/payloads/user.py +13 -0
  26. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/ref.py +6 -6
  27. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/snowflake.py +7 -15
  28. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/utils.py +4 -0
  29. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/ws.py +8 -23
  30. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy.egg-info/PKG-INFO +1 -1
  31. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy.egg-info/SOURCES.txt +9 -1
  32. attenpy-0.4.0/pyproject.toml +41 -0
  33. attenpy-0.2.1/attenpy/endpoints/__init__.py +0 -5
  34. attenpy-0.2.1/attenpy/payloads/__init__.py +0 -13
  35. attenpy-0.2.1/attenpy/payloads/ws.py +0 -12
  36. attenpy-0.2.1/pyproject.toml +0 -31
  37. {attenpy-0.2.1 → attenpy-0.4.0}/LICENSE +0 -0
  38. {attenpy-0.2.1 → attenpy-0.4.0}/README.md +0 -0
  39. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/exceptions.py +0 -0
  40. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/payloads/notice.py +0 -0
  41. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/payloads/post.py +0 -0
  42. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy/types.py +0 -0
  43. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy.egg-info/dependency_links.txt +0 -0
  44. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy.egg-info/requires.txt +0 -0
  45. {attenpy-0.2.1 → attenpy-0.4.0}/attenpy.egg-info/top_level.txt +0 -0
  46. {attenpy-0.2.1 → attenpy-0.4.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: attenpy
3
- Version: 0.2.1
3
+ Version: 0.4.0
4
4
  Summary: SDK for AttenAPI
5
5
  Author: AttenTeam
6
6
  License: MIT
@@ -3,30 +3,42 @@ from .exceptions import AttenpyException, HTTPException, InvalidResponseError
3
3
  from .models import (
4
4
  Attachment,
5
5
  AttachmentCategory,
6
+ Bot,
7
+ ChatChannel,
8
+ ChatMember,
9
+ ChatMessage,
10
+ ChatMessageType,
6
11
  Notice,
7
12
  NoticeKind,
8
13
  NoticeTarget,
9
14
  NoticeType,
10
15
  PartialAttachment,
16
+ PartialChatMessage,
11
17
  PartialPost,
12
18
  PartialUser,
13
19
  Post,
14
20
  User,
21
+ UserAccessStatus,
15
22
  )
16
23
  from .payloads import (
17
- BotReadyPayload,
24
+ ChatUnreadCountPayload,
18
25
  NoticeUnreadCountPayload,
19
26
  ParentsPostPayload,
20
27
  )
21
28
  from .ref import UserRef
22
29
  from .snowflake import Snowflake
23
30
 
24
- __version__ = "0.2.1"
31
+ __version__ = "0.4.0"
25
32
  __all__ = [
26
33
  "AttenpyException",
27
34
  "Attachment",
28
35
  "AttachmentCategory",
29
- "BotReadyPayload",
36
+ "Bot",
37
+ "ChatChannel",
38
+ "ChatMember",
39
+ "ChatMessage",
40
+ "ChatMessageType",
41
+ "ChatUnreadCountPayload",
30
42
  "Client",
31
43
  "HTTPException",
32
44
  "InvalidResponseError",
@@ -37,11 +49,13 @@ __all__ = [
37
49
  "NoticeUnreadCountPayload",
38
50
  "ParentsPostPayload",
39
51
  "PartialAttachment",
52
+ "PartialChatMessage",
40
53
  "PartialPost",
41
54
  "PartialUser",
42
55
  "Post",
43
56
  "Snowflake",
44
57
  "User",
58
+ "UserAccessStatus",
45
59
  "UserRef",
46
60
  "__version__",
47
61
  ]
@@ -1,6 +1,16 @@
1
1
  import asyncio
2
-
3
- from .endpoints import NoticeEndpoint, PostEndpoint, UserEndpoint
2
+ from collections.abc import Callable
3
+ from types import TracebackType
4
+
5
+ from .endpoints import (
6
+ ChatEndpoint,
7
+ ExploreEndpoint,
8
+ MeEndpoint,
9
+ MessageEndpoint,
10
+ NoticeEndpoint,
11
+ PostEndpoint,
12
+ UserEndpoint,
13
+ )
4
14
  from .http import HTTPClient
5
15
  from .ws import EventHandler, WSClient
6
16
 
@@ -27,20 +37,24 @@ class Client:
27
37
  self.ws = WSClient(self)
28
38
 
29
39
  self.users = UserEndpoint(self)
40
+ self.me = MeEndpoint(self)
30
41
  self.posts = PostEndpoint(self)
31
42
  self.notices = NoticeEndpoint(self)
43
+ self.explores = ExploreEndpoint(self)
44
+ self.chats = ChatEndpoint(self)
45
+ self.messages = MessageEndpoint(self)
32
46
 
33
47
  self._closed_event = asyncio.Event()
34
48
 
35
49
  # websocket
36
50
 
37
- def add_handler(self, event_name: str, func):
51
+ def add_handler(self, event_name: str, func: EventHandler):
38
52
  self.ws.add_handler(event_name, func)
39
53
 
40
54
  def remove_handler(self, event_name: str):
41
55
  self.ws.remove_handler(event_name)
42
56
 
43
- def on(self, event_name: str):
57
+ def on[T: EventHandler](self, event_name: str) -> Callable[[T], T]:
44
58
  return _EventHandlerRegister(self.ws, event_name)
45
59
 
46
60
  async def connect_ws(self, *, reconnect: bool = False) -> None:
@@ -74,5 +88,10 @@ class Client:
74
88
  async def __aenter__(self):
75
89
  return self
76
90
 
77
- async def __aexit__(self, exc_type, exc, tb):
91
+ async def __aexit__(
92
+ self,
93
+ exc_type: type[BaseException] | None,
94
+ exc: BaseException | None,
95
+ tb: TracebackType | None,
96
+ ) -> None:
78
97
  await self.close()
@@ -0,0 +1,17 @@
1
+ from .chats import ChatEndpoint
2
+ from .explores import ExploreEndpoint
3
+ from .me import MeEndpoint
4
+ from .messages import MessageEndpoint
5
+ from .notices import NoticeEndpoint
6
+ from .posts import PostEndpoint
7
+ from .users import UserEndpoint
8
+
9
+ __all__ = [
10
+ "UserEndpoint",
11
+ "MeEndpoint",
12
+ "PostEndpoint",
13
+ "NoticeEndpoint",
14
+ "ExploreEndpoint",
15
+ "ChatEndpoint",
16
+ "MessageEndpoint",
17
+ ]
@@ -0,0 +1,83 @@
1
+ from collections.abc import AsyncGenerator, Sequence
2
+ from typing import TYPE_CHECKING, Unpack
3
+
4
+ from ..models import Attachment, ChatChannel, ChatMember, ChatMessage, PartialChatMessage
5
+ from ..pagination import PaginateOptions, paginate
6
+ from ..payloads import ChatUnreadCountPayload
7
+ from ..ref import UserRef
8
+ from ..utils import int_or_none
9
+
10
+ if TYPE_CHECKING:
11
+ from ..client import Client
12
+
13
+
14
+ class ChatEndpoint:
15
+ def __init__(self, client: "Client"):
16
+ self.client = client
17
+
18
+ async def list(self, **kw: Unpack[PaginateOptions]) -> AsyncGenerator[ChatChannel]:
19
+ async for data in paginate(self.client.http, "/chats", **kw):
20
+ yield ChatChannel.model_validate(data)
21
+
22
+ async def get_unread_count(self) -> ChatUnreadCountPayload:
23
+ return ChatUnreadCountPayload.model_validate(
24
+ (await self.client.http.get("/chats/unread-count")).data
25
+ )
26
+
27
+ async def get(self, channel: int | ChatChannel) -> ChatChannel:
28
+ return ChatChannel.model_validate(
29
+ (await self.client.http.get(f"/chats/{int(channel)}")).data
30
+ )
31
+
32
+ async def get_members(
33
+ self, channel: int | ChatChannel, **kw: Unpack[PaginateOptions]
34
+ ) -> AsyncGenerator[ChatMember]:
35
+ async for data in paginate(self.client.http, f"/chats/{int(channel)}/members", **kw):
36
+ yield ChatMember.model_validate(data)
37
+
38
+ async def get_member(self, channel: int | ChatChannel, user: UserRef | str) -> ChatMember:
39
+ return ChatMember.model_validate(
40
+ (await self.client.http.get(f"/chats/{int(channel)}/members/{user}")).data
41
+ )
42
+
43
+ async def join(self, channel: int | ChatChannel) -> ChatChannel:
44
+ return ChatChannel.model_validate(
45
+ (
46
+ await self.client.http.patch(
47
+ f"/chats/{int(channel)}/members/{UserRef.ME}", json={"is_joined": True}
48
+ )
49
+ ).data
50
+ )
51
+
52
+ async def remove_member(self, channel: int | ChatChannel, user: UserRef | str):
53
+ await self.client.http.delete(f"/chats/{int(channel)}/members/{user}")
54
+
55
+ async def mark_read(self, channel: int | ChatChannel):
56
+ await self.client.http.post(f"/chats/{int(channel)}/read")
57
+
58
+ async def create_message(
59
+ self,
60
+ channel: int | ChatChannel,
61
+ content: str = "",
62
+ *,
63
+ attachments: Sequence[int | Attachment] | None = None,
64
+ reply: int | PartialChatMessage | None = None,
65
+ ) -> ChatMessage:
66
+ return ChatMessage.model_validate(
67
+ (
68
+ await self.client.http.post(
69
+ f"/chats/{int(channel)}/messages",
70
+ json={
71
+ "content": content,
72
+ "attachment_ids": [int(attachment) for attachment in attachments or []],
73
+ "reply_id": int_or_none(reply),
74
+ },
75
+ )
76
+ ).data
77
+ )
78
+
79
+ async def get_messages(
80
+ self, channel: int | ChatChannel, **kw: Unpack[PaginateOptions]
81
+ ) -> AsyncGenerator[ChatMessage]:
82
+ async for data in paginate(self.client.http, f"/chats/{int(channel)}/messages", **kw):
83
+ yield ChatMessage.model_validate(data)
@@ -0,0 +1,42 @@
1
+ from collections.abc import AsyncGenerator
2
+ from typing import TYPE_CHECKING, Unpack
3
+
4
+ from pydantic import TypeAdapter
5
+
6
+ from ..models import Post
7
+ from ..pagination import PaginateOptions, paginate
8
+ from ..payloads import StatPayload, TrendPayload
9
+
10
+ if TYPE_CHECKING:
11
+ from ..client import Client
12
+
13
+ TREND_DATA_TA = TypeAdapter[list[TrendPayload]](list[TrendPayload])
14
+ STAT_DATA_TA = TypeAdapter[list[StatPayload]](list[StatPayload])
15
+ MIX_DATA_TA = TypeAdapter[list[Post]](list[Post])
16
+
17
+
18
+ class ExploreEndpoint:
19
+ def __init__(self, client: "Client"):
20
+ self.client = client
21
+
22
+ async def get_recent(self, **kw: Unpack[PaginateOptions]) -> AsyncGenerator[Post]:
23
+ async for data in paginate(self.client.http, "/explore/recent", **kw):
24
+ yield Post.model_validate(data)
25
+
26
+ async def get_following_post(self, **kw: Unpack[PaginateOptions]) -> AsyncGenerator[Post]:
27
+ async for data in paginate(self.client.http, "/explore/following", **kw):
28
+ yield Post.model_validate(data)
29
+
30
+ async def get_mix_post(self) -> AsyncGenerator[Post]:
31
+ for data in MIX_DATA_TA.validate_python((await self.client.http.get("/explore/mix")).data):
32
+ yield data
33
+
34
+ async def get_trend(self) -> AsyncGenerator[TrendPayload]:
35
+ for data in TREND_DATA_TA.validate_python(
36
+ (await self.client.http.get("/explore/trend")).data
37
+ ):
38
+ yield data
39
+
40
+ async def get_stats(self) -> AsyncGenerator[StatPayload]:
41
+ for data in STAT_DATA_TA.validate_python((await self.client.http.get("/stats")).data):
42
+ yield data
@@ -0,0 +1,90 @@
1
+ from collections.abc import AsyncGenerator
2
+ from types import EllipsisType
3
+ from typing import TYPE_CHECKING, Unpack
4
+
5
+ from ..models import (
6
+ Attachment,
7
+ Bot,
8
+ PartialPost,
9
+ PartialUser,
10
+ Post,
11
+ User,
12
+ UserAccessStatus,
13
+ )
14
+ from ..pagination import PaginateOptions, paginate
15
+ from ..ref import UserRef
16
+ from ..utils import int_or_none
17
+
18
+ if TYPE_CHECKING:
19
+ from ..client import Client
20
+
21
+
22
+ class MeEndpoint:
23
+ def __init__(self, client: "Client"):
24
+ self.client = client
25
+
26
+ async def edit(
27
+ self,
28
+ *,
29
+ display_name: str | None | EllipsisType = ...,
30
+ bio: str | EllipsisType = ...,
31
+ icon: int | Attachment | None | EllipsisType = ...,
32
+ banner: int | Attachment | None | EllipsisType = ...,
33
+ pinned: int | PartialPost | None | EllipsisType = ...,
34
+ ) -> User:
35
+ payload = {}
36
+ if display_name is not ...:
37
+ payload["display_name"] = display_name
38
+ if bio is not ...:
39
+ payload["bio"] = bio
40
+ if icon is not ...:
41
+ payload["icon_id"] = int_or_none(icon)
42
+ if banner is not ...:
43
+ payload["banner_id"] = int_or_none(banner)
44
+ if pinned is not ...:
45
+ payload["pinned_id"] = int_or_none(pinned)
46
+ return User.model_validate(
47
+ (await self.client.http.patch(f"/users/{UserRef.ME}", json=payload)).data
48
+ )
49
+
50
+ async def get_mutes(self, **kw: Unpack[PaginateOptions]) -> AsyncGenerator[PartialUser]:
51
+ async for data in paginate(self.client.http, f"/users/{UserRef.ME}/mutes", **kw):
52
+ yield PartialUser.model_validate(data)
53
+
54
+ async def get_bookmarks(self, **kw: Unpack[PaginateOptions]) -> AsyncGenerator[Post]:
55
+ async for data in paginate(self.client.http, f"/users/{UserRef.ME}/bookmarks", **kw):
56
+ yield Post.model_validate(data)
57
+
58
+ async def get_accesses(self, **kw: Unpack[PaginateOptions]) -> AsyncGenerator[PartialUser]:
59
+ async for data in paginate(self.client.http, f"/users/{UserRef.ME}/accesses", **kw):
60
+ yield PartialUser.model_validate(data)
61
+
62
+ async def get_viewers(
63
+ self,
64
+ *,
65
+ status: UserAccessStatus,
66
+ **kw: Unpack[PaginateOptions],
67
+ ) -> AsyncGenerator[PartialUser]:
68
+ async for data in paginate(
69
+ self.client.http,
70
+ f"/users/{UserRef.ME}/viewers",
71
+ params={"status": status.value},
72
+ **kw,
73
+ ):
74
+ yield PartialUser.model_validate(data)
75
+
76
+ async def accept_viewer(self, viewer: UserRef | str):
77
+ await self.client.http.post(f"/users/{UserRef.ME}/viewers/{viewer}/accept")
78
+
79
+ async def decline_viewer(self, viewer: UserRef | str):
80
+ await self.client.http.post(f"/users/{UserRef.ME}/viewers/{viewer}/decline")
81
+
82
+ async def remove_viewer(self, viewer: UserRef | str):
83
+ await self.client.http.delete(f"/users/{UserRef.ME}/viewers/{viewer}")
84
+
85
+ async def get_bot(self) -> Bot | None:
86
+ data = (await self.client.http.get(f"/users/{UserRef.ME}/bot")).data
87
+ return Bot.model_validate(data) if data is not None else None
88
+
89
+ async def revoke_bot(self):
90
+ await self.client.http.delete(f"/users/{UserRef.ME}/bot")
@@ -0,0 +1,21 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from ..models import ChatMessage
4
+
5
+ if TYPE_CHECKING:
6
+ from ..client import Client
7
+
8
+
9
+ class MessageEndpoint:
10
+ def __init__(self, client: "Client"):
11
+ self.client = client
12
+
13
+ async def get(self, message: int | ChatMessage) -> ChatMessage:
14
+ return ChatMessage.model_validate(
15
+ (await self.client.http.get(f"/messages/{int(message)}")).data
16
+ )
17
+
18
+ async def delete(self, message: int | ChatMessage) -> ChatMessage:
19
+ return ChatMessage.model_validate(
20
+ (await self.client.http.delete(f"/messages/{int(message)}")).data
21
+ )
@@ -1,7 +1,7 @@
1
- from collections.abc import AsyncIterator, Sequence
1
+ from collections.abc import AsyncGenerator, Sequence
2
2
  from typing import TYPE_CHECKING, Unpack
3
3
 
4
- from ..models import Notice
4
+ from ..models import Notice, Warn
5
5
  from ..models.notice import NoticeType
6
6
  from ..pagination import PaginateOptions, paginate
7
7
  from ..payloads import NoticeUnreadCountPayload
@@ -15,11 +15,8 @@ class NoticeEndpoint:
15
15
  self.client = client
16
16
 
17
17
  async def list(
18
- self,
19
- *,
20
- types: Sequence[NoticeType] | None = None,
21
- **kw: Unpack[PaginateOptions],
22
- ) -> AsyncIterator[Notice]:
18
+ self, *, types: Sequence[NoticeType] | None = None, **kw: Unpack[PaginateOptions]
19
+ ) -> AsyncGenerator[Notice]:
23
20
  params = None
24
21
  if types:
25
22
  params = {"type": [i.value for i in set(types)]}
@@ -27,11 +24,13 @@ class NoticeEndpoint:
27
24
  yield Notice.model_validate(data)
28
25
 
29
26
  async def read_up_to(self, notice: int | Notice):
30
- await self.client.http.put(
31
- "/notices/read-up-to", json={"notice_id": int(notice)}
32
- )
27
+ await self.client.http.put("/notices/read-up-to", json={"notice_id": int(notice)})
33
28
 
34
29
  async def get_unread_count(self) -> NoticeUnreadCountPayload:
35
30
  return NoticeUnreadCountPayload.model_validate(
36
31
  (await self.client.http.get("/notices/unread-count")).data
37
32
  )
33
+
34
+ async def list_warns(self, **kw: Unpack[PaginateOptions]) -> AsyncGenerator[Warn]:
35
+ async for data in paginate(self.client.http, "/warns", **kw):
36
+ yield Warn.model_validate(data)
@@ -1,6 +1,9 @@
1
- from typing import TYPE_CHECKING, AsyncIterator, Unpack
1
+ from collections.abc import AsyncGenerator
2
+ from typing import TYPE_CHECKING, Unpack
2
3
 
3
- from ..models import PartialPost, PartialUser, Post
4
+ from pydantic import TypeAdapter
5
+
6
+ from ..models import PartialPost, PartialUser, Post, PostVisibility
4
7
  from ..pagination import (
5
8
  PaginateOptions,
6
9
  paginate,
@@ -11,6 +14,8 @@ from ..utils import int_or_none
11
14
  if TYPE_CHECKING:
12
15
  from ..client import Client
13
16
 
17
+ HISTORY_DATA_TA = TypeAdapter[list[Post]](list[Post])
18
+
14
19
 
15
20
  class PostEndpoint:
16
21
  def __init__(self, client: "Client"):
@@ -20,18 +25,28 @@ class PostEndpoint:
20
25
  self,
21
26
  content: str,
22
27
  quote: int | PartialPost | None = None,
28
+ *,
29
+ visibility: PostVisibility,
23
30
  ) -> Post:
24
31
  return Post.model_validate(
25
32
  (
26
33
  await self.client.http.post(
27
- "/posts", json={"content": content, "quote": int_or_none(quote)}
34
+ "/posts",
35
+ json={
36
+ "content": content,
37
+ "quote_id": int_or_none(quote),
38
+ "visibility": visibility,
39
+ },
28
40
  )
29
41
  ).data
30
42
  )
31
43
 
32
44
  async def get(self, post: int | PartialPost) -> Post:
45
+ return Post.model_validate((await self.client.http.get(f"/posts/{int(post)}")).data)
46
+
47
+ async def edit(self, post: int | PartialPost, content: str) -> Post:
33
48
  return Post.model_validate(
34
- (await self.client.http.get(f"/posts/{int(post)}")).data
49
+ (await self.client.http.patch(f"/posts/{int(post)}", json={"content": content})).data
35
50
  )
36
51
 
37
52
  async def reply(
@@ -39,12 +54,18 @@ class PostEndpoint:
39
54
  parent: int | PartialPost,
40
55
  content: str,
41
56
  quote: int | PartialPost | None = None,
57
+ *,
58
+ visibility: PostVisibility,
42
59
  ) -> Post:
43
60
  return Post.model_validate(
44
61
  (
45
62
  await self.client.http.post(
46
63
  f"/posts/{int(parent)}/reply",
47
- json={"content": content, "quote": int_or_none(quote)},
64
+ json={
65
+ "content": content,
66
+ "quote_id": int_or_none(quote),
67
+ "visibility": visibility,
68
+ },
48
69
  )
49
70
  ).data
50
71
  )
@@ -65,49 +86,39 @@ class PostEndpoint:
65
86
  await self.client.http.delete(f"/posts/{int(post)}/bookmark")
66
87
 
67
88
  async def repost(self, post: int | PartialPost) -> Post:
68
- return Post.model_validate(
69
- (await self.client.http.post(f"/posts/{int(post)}/repost")).data
70
- )
89
+ return Post.model_validate((await self.client.http.post(f"/posts/{int(post)}/repost")).data)
71
90
 
72
91
  async def unrepost(self, post: int | PartialPost):
73
92
  await self.client.http.delete(f"/posts/{int(post)}/repost")
74
93
 
75
94
  async def get_loves(
76
95
  self, post: int | PartialPost, **kw: Unpack[PaginateOptions]
77
- ) -> AsyncIterator[PartialUser]:
96
+ ) -> AsyncGenerator[PartialUser]:
78
97
  async for data in paginate(self.client.http, f"/posts/{int(post)}/loves", **kw):
79
98
  yield PartialUser.model_validate(data)
80
99
 
81
- async def get_history(
82
- self, post: int | PartialPost, **kw: Unpack[PaginateOptions]
83
- ) -> AsyncIterator[Post]:
84
- async for data in paginate(
85
- self.client.http, f"/posts/{int(post)}/history", **kw
100
+ async def get_history(self, post: int | PartialPost) -> AsyncGenerator[Post]:
101
+ for data in HISTORY_DATA_TA.validate_python(
102
+ (await self.client.http.get(f"/posts/{int(post)}/history")).data
86
103
  ):
87
- yield Post.model_validate(data)
104
+ yield data
88
105
 
89
106
  async def get_quotes(
90
107
  self, post: int | PartialPost, **kw: Unpack[PaginateOptions]
91
- ) -> AsyncIterator[Post]:
92
- async for data in paginate(
93
- self.client.http, f"/posts/{int(post)}/quotes", **kw
94
- ):
108
+ ) -> AsyncGenerator[Post]:
109
+ async for data in paginate(self.client.http, f"/posts/{int(post)}/quotes", **kw):
95
110
  yield Post.model_validate(data)
96
111
 
97
112
  async def get_replies(
98
113
  self, post: int | PartialPost, **kw: Unpack[PaginateOptions]
99
- ) -> AsyncIterator[Post]:
100
- async for data in paginate(
101
- self.client.http, f"/posts/{int(post)}/replies", **kw
102
- ):
114
+ ) -> AsyncGenerator[Post]:
115
+ async for data in paginate(self.client.http, f"/posts/{int(post)}/replies", **kw):
103
116
  yield Post.model_validate(data)
104
117
 
105
118
  async def get_reposts(
106
119
  self, post: int | PartialPost, **kw: Unpack[PaginateOptions]
107
- ) -> AsyncIterator[Post]:
108
- async for data in paginate(
109
- self.client.http, f"/posts/{int(post)}/reposts", **kw
110
- ):
120
+ ) -> AsyncGenerator[Post]:
121
+ async for data in paginate(self.client.http, f"/posts/{int(post)}/reposts", **kw):
111
122
  yield Post.model_validate(data)
112
123
 
113
124
  async def get_parents(self, post: int | PartialPost) -> ParentsPostPayload:
@@ -1,13 +1,14 @@
1
- from types import EllipsisType
2
- from typing import TYPE_CHECKING, AsyncIterator, Unpack
1
+ from collections.abc import AsyncGenerator
2
+ from typing import TYPE_CHECKING, Unpack
3
3
 
4
- from ..models import Attachment, PartialPost, PartialUser, Post, User
4
+ from attenpy.payloads import BanStatusPayload
5
+
6
+ from ..models import ChatChannel, PartialUser, Post, User
5
7
  from ..pagination import (
6
8
  PaginateOptions,
7
9
  paginate,
8
10
  )
9
11
  from ..ref import UserRef
10
- from ..utils import int_or_none
11
12
 
12
13
  if TYPE_CHECKING:
13
14
  from ..client import Client
@@ -20,31 +21,6 @@ class UserEndpoint:
20
21
  async def get(self, user: UserRef | str) -> User:
21
22
  return User.model_validate((await self.client.http.get(f"/users/{user}")).data)
22
23
 
23
- async def edit(
24
- self,
25
- user: UserRef | str,
26
- *,
27
- display_name: str | None | EllipsisType = ...,
28
- bio: str | EllipsisType = ...,
29
- icon: int | Attachment | None | EllipsisType = ...,
30
- banner: int | Attachment | None | EllipsisType = ...,
31
- pinned: int | PartialPost | None | EllipsisType = ...,
32
- ) -> User:
33
- payload = {}
34
- if display_name is not ...:
35
- payload["display_name"] = display_name
36
- if bio is not ...:
37
- payload["bio"] = bio
38
- if icon is not ...:
39
- payload["icon_id"] = int_or_none(icon)
40
- if banner is not ...:
41
- payload["banner_id"] = int_or_none(banner)
42
- if pinned is not ...:
43
- payload["pinned_id"] = int_or_none(pinned)
44
- return User.model_validate(
45
- (await self.client.http.patch(f"/users/{user}", json=payload)).data
46
- )
47
-
48
24
  async def follow(self, user: UserRef | str):
49
25
  await self.client.http.post(f"/users/{user}/follow")
50
26
 
@@ -59,48 +35,50 @@ class UserEndpoint:
59
35
 
60
36
  async def get_followers(
61
37
  self, user: UserRef | str, **kw: Unpack[PaginateOptions]
62
- ) -> AsyncIterator[PartialUser]:
38
+ ) -> AsyncGenerator[PartialUser]:
63
39
  async for data in paginate(self.client.http, f"/users/{user}/followers", **kw):
64
40
  yield PartialUser.model_validate(data)
65
41
 
66
42
  async def get_following(
67
43
  self, user: UserRef | str, **kw: Unpack[PaginateOptions]
68
- ) -> AsyncIterator[PartialUser]:
44
+ ) -> AsyncGenerator[PartialUser]:
69
45
  async for data in paginate(self.client.http, f"/users/{user}/following", **kw):
70
46
  yield PartialUser.model_validate(data)
71
47
 
72
- async def get_mutes(
73
- self, user: UserRef | str, **kw: Unpack[PaginateOptions]
74
- ) -> AsyncIterator[PartialUser]:
75
- async for data in paginate(self.client.http, f"/users/{user}/mutes", **kw):
76
- yield PartialUser.model_validate(data)
77
-
78
48
  async def get_posts(
79
49
  self, user: UserRef | str, **kw: Unpack[PaginateOptions]
80
- ) -> AsyncIterator[Post]:
50
+ ) -> AsyncGenerator[Post]:
81
51
  async for data in paginate(self.client.http, f"/users/{user}/posts", **kw):
82
52
  yield Post.model_validate(data)
83
53
 
84
54
  async def get_medias(
85
55
  self, user: UserRef | str, **kw: Unpack[PaginateOptions]
86
- ) -> AsyncIterator[Post]:
56
+ ) -> AsyncGenerator[Post]:
87
57
  async for data in paginate(self.client.http, f"/users/{user}/medias", **kw):
88
58
  yield Post.model_validate(data)
89
59
 
90
60
  async def get_loves(
91
61
  self, user: UserRef | str, **kw: Unpack[PaginateOptions]
92
- ) -> AsyncIterator[Post]:
62
+ ) -> AsyncGenerator[Post]:
93
63
  async for data in paginate(self.client.http, f"/users/{user}/loves", **kw):
94
64
  yield Post.model_validate(data)
95
65
 
96
- async def get_bookmarks(
97
- self, user: UserRef | str, **kw: Unpack[PaginateOptions]
98
- ) -> AsyncIterator[Post]:
99
- async for data in paginate(self.client.http, f"/users/{user}/bookmarks", **kw):
100
- yield Post.model_validate(data)
101
-
102
66
  async def get_reposts(
103
67
  self, user: UserRef | str, **kw: Unpack[PaginateOptions]
104
- ) -> AsyncIterator[Post]:
68
+ ) -> AsyncGenerator[Post]:
105
69
  async for data in paginate(self.client.http, f"/users/{user}/reposts", **kw):
106
70
  yield Post.model_validate(data)
71
+
72
+ async def ban_status(self, user: UserRef | str) -> BanStatusPayload:
73
+ return BanStatusPayload.model_validate(
74
+ (await self.client.http.get(f"/users/{user}/ban")).data
75
+ )
76
+
77
+ async def request_access(self, user: UserRef | str):
78
+ await self.client.http.post(f"/users/{user}/access")
79
+
80
+ async def remove_access(self, user: UserRef | str):
81
+ await self.client.http.delete(f"/users/{user}/access")
82
+
83
+ async def get_chat(self, user: UserRef | str) -> ChatChannel:
84
+ return ChatChannel.model_validate((await self.client.http.get(f"/users/{user}/chat")).data)