feat: add method #MP-28

pull/26/head
xtaodada 2 years ago
parent a7dc6f0c5c
commit 045fcebd5e
No known key found for this signature in database
GPG Key ID: 4CBB3F4FA8C85659

@ -9,13 +9,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Added
- ✨ added `get_children` method a `ClientNoteActions` class.
- ✨ added `get_children` method at `ClientNoteActions` class.
- ✨ added `invalidate` method at `FollowActions` class.
- ✨ added `cancel` method at `FollowRequestActions` class.
## Removed
- 🔥 Delete `get_user` method at `FollowRequestActions` class.
## [0.3.99] 2022-12-25
## Added
- 💡 added DocString.
- ✨ added `get_state` method a `ClientNoteActions` class.
- ✨ added `get_state` method at `ClientNoteActions` class.
- ✨ added `INoteState` class.
- ✨ added `NoteState` class.
- ✨ added `IBasePoll` class.
@ -34,9 +40,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- 💡 became `is_ayuskey` attribute is deprecated(I'll remove with v0.4.0)
- ✨ added `get_exception_from_id` function.
- ✨ Return an exception appropriate for the error encountered.
- ✨ [@omg-xtao](https://github.com/omg-xtao) added `users_search_by_username_and_host` method a `UserActions` class [#24](https://github.com/yupix/MiPAC/pull/24).
- ✨ [@omg-xtao](https://github.com/omg-xtao) added `note_translate` method a `UserActions` class [#24](https://github.com/yupix/MiPAC/pull/24).
- ✨ [@omg-xtao](https://github.com/omg-xtao) added `users_search` method a `UserActions` class [#24](https://github.com/yupix/MiPAC/pull/24).
- ✨ [@omg-xtao](https://github.com/omg-xtao) added `users_search_by_username_and_host` method at `UserActions` class [#24](https://github.com/yupix/MiPAC/pull/24).
- ✨ [@omg-xtao](https://github.com/omg-xtao) added `note_translate` method at `UserActions` class [#24](https://github.com/yupix/MiPAC/pull/24).
- ✨ [@omg-xtao](https://github.com/omg-xtao) added `users_search` method at `UserActions` class [#24](https://github.com/yupix/MiPAC/pull/24).
## Changed

@ -5,12 +5,13 @@ from typing import TYPE_CHECKING
from mipac.abstract.action import AbstractAction
from mipac.http import Route
from mipac.models.follow import FollowRequest
from mipac.models.user import UserDetailed
from mipac.models.user import UserDetailed, LiteUser
from mipac.types.follow import IFollowRequest
if TYPE_CHECKING:
from mipac.http import HTTPClient
from mipac.manager.client import ClientActions
from mipac.types.user import ILiteUser
class FollowActions(AbstractAction):
@ -25,52 +26,62 @@ class FollowActions(AbstractAction):
self.__session = session
self.__client = client
async def add(self, user_id: str | None = None) -> tuple[bool, str | None]:
async def add(self, user_id: str | None = None) -> LiteUser:
"""
ユーザーをフォローします
Follow a user
Returns
-------
bool
成功ならTrue, 失敗ならFalse
str
実行に失敗した際のエラーコード
UserLite:
The user that you followed
"""
user_id = user_id or self.__user_id
data = {'userId': user_id}
res = await self.__session.request(
res: ILiteUser = await self.__session.request(
Route('POST', '/api/following/create'),
json=data,
auth=True,
lower=True,
)
if res.get('error'):
code = res['error']['code']
status = False
else:
code = None
status = True
return status, code
async def remove(self, user_id: str | None = None) -> bool:
return LiteUser(res, client=self.__client)
async def remove(self, user_id: str | None = None) -> LiteUser:
"""
ユーザーのフォローを解除します
Unfollow a user
Returns
-------
bool
成功ならTrue, 失敗ならFalse
LiteUser
The user that you unfollowed
"""
user_id = user_id or self.__user_id
data = {'userId': user_id}
res: bool = await self.__session.request(
res = await self.__session.request(
Route('POST', '/api/following/delete'), json=data, auth=True
)
return res
return LiteUser(res, client=self.__client)
async def invalidate(self, user_id: str | None = None) -> LiteUser:
"""
Make the user unfollows you
Returns
-------
LiteUser
The user that followed you
"""
user_id = user_id or self.__user_id
data = {'userId': user_id}
res: ILiteUser = await self.__session.request(
Route('POST', '/api/following/invalidate'), json=data, auth=True
)
return LiteUser(res, client=self.__client)
class FollowRequestActions(AbstractAction):
@ -87,7 +98,12 @@ class FollowRequestActions(AbstractAction):
async def get_all(self) -> list[FollowRequest]:
"""
未承認のフォローリクエストを取得します
Get all follow requests
Returns
-------
list[FollowRequest]
List of follow requests
"""
res: list[IFollowRequest] = await self.__session.request(
@ -99,27 +115,19 @@ class FollowRequestActions(AbstractAction):
FollowRequest(follow_request=i, client=self.__client) for i in res
]
async def get_user(self, user_id: str | None = None) -> UserDetailed:
async def accept(self, user_id: str | None = None) -> bool:
"""
フォローリクエスト元のユーザーを取得します
Accept a follow request
Parameters
----------
user_id : str | None, default=None
ユーザーID
user_id: str
The user ID to accept
Returns
-------
UserDetailed
フォローリクエスト元のユーザー
"""
user_id = user_id or self.__user_id
return await self.__client.user.action.get(user_id)
async def accept(self, user_id: str | None = None) -> bool:
"""
与えられたIDのユーザーのフォローリクエストを承認します
bool
Whether the request was accepted
"""
user_id = user_id or self.__user_id
@ -133,9 +141,19 @@ class FollowRequestActions(AbstractAction):
)
)
async def reject(self, user_id: str | None) -> bool:
async def reject(self, user_id: str | None = None) -> bool:
"""
与えられたIDのユーザーのフォローリクエストを拒否します
Reject a follow request
Parameters
----------
user_id: str
The user ID to reject
Returns
-------
bool
Whether the request was rejected
"""
user_id = user_id or self.__user_id
@ -148,3 +166,29 @@ class FollowRequestActions(AbstractAction):
auth=True,
)
)
async def cancel(self, user_id: str | None = None) -> LiteUser:
"""
Cancel a follow request
Parameters
----------
user_id: str
The user ID to cancel
Returns
-------
LiteUser
The user that you canceled to follow
"""
user_id = user_id or self.__user_id
data = {'userId': user_id}
res: ILiteUser = await self.__session.request(
Route('POST', '/api/following/requests/cancel'),
json=data,
auth=True,
lower=True,
)
return LiteUser(res, client=self.__client)

@ -10,6 +10,7 @@ from mipac.manager.drive import DriveManager
from mipac.manager.my import MyManager
from mipac.manager.note import NoteManager
from mipac.manager.user import UserManager
from mipac.manager.follow import FollowManager, FollowRequestManager
if TYPE_CHECKING:
from mipac.config import Config
@ -30,6 +31,8 @@ class ClientActions:
self.admin: AdminManager = AdminManager(session=session, client=self)
self.drive: DriveManager = DriveManager(session=session, client=self)
self.chart: ChartManager = ChartManager(session=session, client=self)
self.follow: FollowManager = FollowManager(session=session, client=self)
self.follow_request: FollowRequestManager = FollowRequestManager(session=session, client=self)
self._config: Config = config
def _create_user_instance(self, user: LiteUser) -> UserManager:

Loading…
Cancel
Save