Skip to content

Commit

Permalink
Merge pull request #69 from yupix/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
yupix authored Apr 25, 2023
2 parents 47af713 + 0044ed4 commit 7ae446e
Show file tree
Hide file tree
Showing 47 changed files with 1,393 additions and 453 deletions.
414 changes: 229 additions & 185 deletions CHANGELOG.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ Client.config.from_dict(is_ayuskey=True, use_version=13)

上記のように複数の値を同時に更新する場合特に`from_dict`は有効な方法になります。

### 注意事項

### 一部サーバー(インスタンス)のバージョンによっては正常に動作しない可能性があります

MiPACの特徴として、v11,v12,v13のバージョンごとに生じる変更点をなるべく気にしなくてよいように作成していますが、現状の最新版であるv13でもv13の中で削除されたり、増えたりした物があります。結果的に追従しきれていない箇所があることがあります。そのため、そのような物を見つけた場合は、使用しているサーバーのバージョンと使用できないエンドポイント名をIssueに送信してください。

### モデルを基本的に自分でインスタンス化することは推奨しません

MiPACのモデルでは多くの場合、キーワード引数に `client`を受け取り、それを用いて`api` プロパティを生成します。しかし、サポート途中の機能なのではそこが省かれ、リリース後にモデルのインスタンス化に必要な引数として `client` が追加されることがあります。また、他にもモデルの更新のために引数が変更される可能性があります。そのため、引数の変更に関することをCHANGELOG等で通知することはありません。

### 開発者向け情報

このプロジェクトでは [black](https://github.com/psf/black)のforkである、[axblack](https://github.com/axiros/axblack)を利用しています。主な違いはダブルクォートがデフォルトではなく、シングルクォートになっている点です
Expand Down
2 changes: 1 addition & 1 deletion compiler/datas/v13_api.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"openapi": "3.0.0",
"info": {
"version": "13.11.3",
"version": "13.10.3",
"title": "Misskey API",
"x-logo": { "url": "/static-assets/api-doc.png" }
},
Expand Down
3 changes: 2 additions & 1 deletion mipac/actions/admins/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from mipac.types.admin import IIndexStat, IModerationLog, IServerInfo, ITableStats, IUserIP
from mipac.types.meta import IAdminMeta, IUpdateMetaBody
from mipac.types.user import IUserDetailed
from mipac.util import cache, convert_dict_keys_to_camel
from mipac.utils.cache import cache
from mipac.utils.format import convert_dict_keys_to_camel

if TYPE_CHECKING:
from mipac.manager.client import ClientManager
Expand Down
2 changes: 1 addition & 1 deletion mipac/actions/admins/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mipac.http import Route
from mipac.models.emoji import CustomEmoji
from mipac.types.emoji import ICustomEmoji
from mipac.util import check_multi_arg
from mipac.utils.util import check_multi_arg

if TYPE_CHECKING:
from mipac.http import HTTPClient
Expand Down
73 changes: 73 additions & 0 deletions mipac/actions/channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Literal, overload

from mipac.abstract.action import AbstractAction
from mipac.http import HTTPClient, Route
from mipac.models.channel import Channel
from mipac.models.lite.channel import ChannelLite
from mipac.types.channel import IChannel, IChannelLite

if TYPE_CHECKING:
from mipac.client import ClientManager


class ClientChannelActions(AbstractAction):
def __init__(
self, channel_id: str | None = None, *, session: HTTPClient, client: ClientManager
):
self._channel_id: str | None = channel_id
self._session: HTTPClient = session
self._client: ClientManager = client

async def favorite(self, channel_id: str | None = None):
if self._client._config.use_version < 13:
raise Exception()

channel_id = self._channel_id or channel_id
if channel_id is None:
raise Exception()

res: bool = await self._session.request(
Route('POST', '/api/channels/favorite'), auth=True, json={'channelId': channel_id}
)

return res

async def unfavorite(self, channel_id: str | None = None):

if self._client._config.use_version < 13:
raise Exception()

channel_id = self._channel_id or channel_id
if channel_id is None:
raise Exception()

res: bool = await self._session.request(
Route('POST', '/api/channels/unfavorite'), auth=True, json={'channelId': channel_id}
)

return res


class ChannelActions(ClientChannelActions):
def __init__(
self, channel_id: str | None = None, *, session: HTTPClient, client: ClientManager
):
super().__init__(channel_id=channel_id, session=session, client=client)

async def get_my_favorite(self) -> list[Channel]:
"""お気に入りに登録したチャンネルの一覧を取得します。
Returns
-------
Channel
チャンネル
"""
if self._client._config.use_version < 13:
raise Exception()

res: list[IChannel] = await self._session.request(
Route('POST', '/api/channels/my-favorites'), auth=True
)
return [Channel(i, client=self._client) for i in res]
2 changes: 1 addition & 1 deletion mipac/actions/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mipac.http import HTTPClient, Route
from mipac.models.chat import ChatMessage
from mipac.types.chat import IChatMessage
from mipac.util import check_multi_arg
from mipac.utils.util import check_multi_arg

if TYPE_CHECKING:
from mipac.manager.client import ClientManager
Expand Down
129 changes: 91 additions & 38 deletions mipac/actions/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,52 @@
from mipac.http import HTTPClient, Route
from mipac.models.drive import File, Folder
from mipac.types.drive import IDriveFile
from mipac.util import bool_to_string, remove_dict_empty
from mipac.utils.format import bool_to_string, remove_dict_empty
from mipac.utils.util import deprecated

if TYPE_CHECKING:
from mipac.manager.client import ClientManager

__all__ = ('DriveActions', 'FileActions', 'FolderActions')


class FileActions(AbstractAction):
class ClientFileActions(AbstractAction):
def __init__(
self, file_id: str | None = None, *, session: HTTPClient, client: ClientManager
self,
file_id: str | None = None,
folder_id: str | None = None,
*,
session: HTTPClient,
client: ClientManager
) -> None:
self.__session: HTTPClient = session
self.__client: ClientManager = client
self.__file_id = file_id
self._session: HTTPClient = session
self._client: ClientManager = client
self._file_id = file_id
self._folder_id = folder_id

async def show_file(self, file_id: str | None, url: str | None) -> File:
async def remove(self, file_id: str | None = None) -> bool:
"""
ファイルの情報を取得します。
指定したIDのファイルを削除します
Parameters
----------
file_id : str | None, default=None
ファイルのID
url : str | None, default=None
ファイルのURL
削除するファイルのID
Returns
-------
File
ファイルの情報
bool
削除に成功したかどうか
"""

data = remove_dict_empty({'fileId': file_id, 'url': url})
res: IDriveFile = await self.__session.request(
Route('POST', '/api/admin/drive/show-file'), json=data, auth=True, lower=True,
file_id = file_id or self._file_id
return bool(
await self._session.request(
Route('POST', '/api/drive/files/delete'), json={'fileId': file_id}, auth=True,
)
)
return File(res, client=self.__client)

@deprecated
async def remove_file(self, file_id: str | None = None) -> bool:
"""
指定したIDのファイルを削除します
Expand All @@ -61,13 +68,48 @@ async def remove_file(self, file_id: str | None = None) -> bool:
削除に成功したかどうか
"""

file_id = file_id or self.__file_id
file_id = file_id or self._file_id
return bool(
await self.__session.request(
await self._session.request(
Route('POST', '/api/drive/files/delete'), json={'fileId': file_id}, auth=True,
)
)


class FileActions(ClientFileActions):
def __init__(
self,
file_id: str | None = None,
folder_id: str | None = None,
*,
session: HTTPClient,
client: ClientManager
) -> None:
super().__init__(file_id=file_id, folder_id=folder_id, session=session, client=client)

async def show_file(self, file_id: str | None = None, url: str | None = None) -> File:
"""
ファイルの情報を取得します。
Parameters
----------
file_id : str | None, default=None
ファイルのID
url : str | None, default=None
ファイルのURL
Returns
-------
File
ファイルの情報
"""

data = remove_dict_empty({'fileId': file_id, 'url': url})
res: IDriveFile = await self._session.request(
Route('POST', '/api/admin/drive/show-file'), json=data, auth=True, lower=True,
)
return File(res, client=self._client)

async def get_files(
self,
limit: int = 10,
Expand Down Expand Up @@ -95,17 +137,19 @@ async def get_files(
if limit > 100:
raise ParameterError('limit must be less than 100')

folder_id = self._folder_id or folder_id

data = {
'limit': limit,
'sinceId': since_id,
'untilId': until_id,
'folderId': folder_id,
'Type': file_type,
}
res: list[IDriveFile] = await self.__session.request(
res: list[IDriveFile] = await self._session.request(
Route('POST', '/api/drive/files'), json=data, auth=True, lower=True
)
return [File(i, client=self.__client) for i in res]
return [File(i, client=self._client) for i in res]

async def upload_file(
self,
Expand Down Expand Up @@ -140,6 +184,8 @@ async def upload_file(
アップロードしたファイルの情報
"""
file_byte = open(file, 'rb') if file else None
folder_id = self._folder_id or folder_id

data = {
'file': file_byte,
'name': file_name,
Expand All @@ -148,19 +194,19 @@ async def upload_file(
'isSensitive': bool_to_string(is_sensitive),
'force': bool_to_string(force),
}
res: IDriveFile = await self.__session.request(
res: IDriveFile = await self._session.request(
Route('POST', '/api/drive/files/create'), data=data, auth=True, lower=True,
)
return File(res, client=self.__client)
return File(res, client=self._client)


class FolderActions(AbstractAction):
class ClientFolderActions(AbstractAction):
def __init__(
self, folder_id: str | None = None, *, session: HTTPClient, client: ClientManager
):
self.__folder_id = folder_id
self.__session: HTTPClient = session
self.__client: ClientManager = client
self._folder_id = folder_id
self._session: HTTPClient = session
self._client: ClientManager = client

async def create(self, name: str, parent_id: str | None = None) -> bool:
"""
Expand All @@ -178,10 +224,10 @@ async def create(self, name: str, parent_id: str | None = None) -> bool:
bool
作成に成功したか否か
"""
parent_id = parent_id or self.__folder_id
parent_id = parent_id or self._folder_id

data = {'name': name, 'parent_id': parent_id}
res: bool = await self.__session.request(
res: bool = await self._session.request(
Route('POST', '/api/drive/folders/create'), json=data, lower=True, auth=True,
)
return bool(res)
Expand All @@ -198,9 +244,9 @@ async def delete(self, folder_id: str | None = None) -> bool:
bool
削除に成功したか否か
"""
folder_id = folder_id or self.__folder_id
folder_id = folder_id or self._folder_id
data = {'folderId': folder_id}
res: bool = await self.__session.request(
res: bool = await self._session.request(
Route('POST', '/api/drive/folders/delete'), json=data, lower=True, auth=True,
)
return bool(res)
Expand Down Expand Up @@ -232,24 +278,31 @@ async def get_files(
if limit > 100:
raise ParameterError('limit must be less than 100')

folder_id = folder_id or self.__folder_id
folder_id = folder_id or self._folder_id
data = {
'limit': limit,
'sinceId': since_id,
'untilId': until_id,
'folderId': folder_id,
'Type': file_type,
}
res: list[IDriveFile] = await self.__session.request(
res: list[IDriveFile] = await self._session.request(
Route('POST', '/api/drive/files'), json=data, auth=True, lower=True
)
return [File(i, client=self.__client) for i in res]
return [File(i, client=self._client) for i in res]


class FolderActions(ClientFolderActions):
def __init__(
self, folder_id: str | None = None, *, session: HTTPClient, client: ClientManager
):
super().__init__(folder_id=folder_id, session=session, client=client)


class DriveActions(AbstractAction):
def __init__(self, session: HTTPClient, client: ClientManager):
self.__session: HTTPClient = session
self.__client: ClientManager = client
self._session: HTTPClient = session
self._client: ClientManager = client

async def get_folders(
self,
Expand Down Expand Up @@ -279,7 +332,7 @@ async def get_folders(
'untilId': until_id,
'folderId': folder_id,
}
data = await self.__session.request(
data = await self._session.request(
Route('POST', '/api/drive/folders'), json=data, lower=True, auth=True,
)
return [Folder(i, client=self.__client) for i in data]
return [Folder(i, client=self._client) for i in data]
Loading

0 comments on commit 7ae446e

Please sign in to comment.