Skip to content

Commit

Permalink
feat: progress #10
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Aug 29, 2022
1 parent d504d64 commit f7ef493
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 397 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Removed

- `RenotePayload`, `Renote` クラスを削除しました。今後は `INote`, `Note` クラスをご利用ください
- `RenotePayload`, `Renote`, `IRenote` クラスを削除しました。今後は `INote`, `Note` クラスをご利用ください
- `RawEmoji`, `Emoji` クラスを削除しました。 今後は `ICustomEmoji`, `CustomEmoji` クラスをご利用ください
- `IReactionRequired`, `ReactionPayload`を削除しました。 今後は `IReactionNf` をご利用ください

Expand Down
12 changes: 3 additions & 9 deletions mipac/actions/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def show_file(
auth=True,
lower=True,
)
return self.__client._modeler.create_file_instance(RawFile(res))
return File(res, client=self.__client)

async def remove_file(self, file_id: Optional[str] = None) -> bool:
"""
Expand Down Expand Up @@ -117,10 +117,7 @@ async def get_files(
res: list[IDriveFile] = await self.__session.request(
Route('POST', '/api/drive/files'), json=data, auth=True, lower=True
)
return [
self.__client._modeler.create_file_instance(RawFile(i))
for i in res
]
return [File(i, client=self.__client) for i in res]


class FolderActions(AbstractAction):
Expand Down Expand Up @@ -222,10 +219,7 @@ async def get_files(
res: list[IDriveFile] = await self.__session.request(
Route('POST', '/api/drive/files'), json=data, auth=True, lower=True
)
return [
self.__client._modeler.create_file_instance(RawFile(i))
for i in res
]
return [File(i, client=self.__client) for i in res]


class DriveActions(AbstractAction):
Expand Down
18 changes: 9 additions & 9 deletions mipac/actions/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
if TYPE_CHECKING:
from mipac.manager.client import ClientActions
from mipac.models.note import Note
from mipac.models.user import User
from mipac.models.user import UserDetailed

__all__ = ['UserActions']

Expand All @@ -28,14 +28,14 @@ def __init__(
self,
session: HTTPClient,
client: ClientActions,
user: Optional[User] = None,
user: Optional[UserDetailed] = None,
):
self.__session: HTTPClient = session
self.__user: Optional[User] = user
self.__user: Optional[UserDetailed] = user
self.__client: ClientActions = client
self.note: NoteManager = NoteManager(session=session, client=client)

async def get_me(self) -> User:
async def get_me(self) -> UserDetailed:
"""
ログインしているユーザーの情報を取得します
"""
Expand All @@ -49,7 +49,7 @@ async def get(
user_id: Optional[str] = None,
username: Optional[str] = None,
host: Optional[str] = None,
) -> User:
) -> UserDetailed:
"""
ユーザーのプロフィールを取得します。一度のみサーバーにアクセスしキャッシュをその後は使います。
fetch_userを使った場合はキャッシュが廃棄され再度サーバーにアクセスします。
Expand All @@ -65,7 +65,7 @@ async def get(
Returns
-------
User
UserDetailed
ユーザー情報
"""

Expand All @@ -84,7 +84,7 @@ async def fetch(
username: Optional[str] = None,
host: Optional[str] = None,
**kwargs,
) -> User:
) -> UserDetailed:
"""
サーバーにアクセスし、ユーザーのプロフィールを取得します。基本的には get_userをお使いください。
Expand All @@ -99,7 +99,7 @@ async def fetch(
Returns
-------
User
UserDetailed
ユーザー情報
"""
if not check_multi_arg(user_id, username):
Expand Down Expand Up @@ -152,7 +152,7 @@ async def get_notes(
)
return [Note(i, client=self.__client) for i in res]

def get_mention(self, user: Optional[User] = None) -> str:
def get_mention(self, user: Optional[UserDetailed] = None) -> str:
"""
Get mention name of user.
Expand Down
4 changes: 2 additions & 2 deletions mipac/core/models/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime
from typing import Any, Optional

from mipac.types.drive import FolderPayload, IDriveFile, PropertiesPayload
from mipac.types.drive import FolderPayload, IDriveFile, IFileProperties
from mipac.types.user import UserPayload

__all__ = ('RawProperties', 'RawFolder', 'RawFile')
Expand All @@ -23,7 +23,7 @@ class RawProperties:

__slots__ = ('width', 'height', 'avg_color')

def __init__(self, data: PropertiesPayload):
def __init__(self, data: IFileProperties):
self.width: Optional[int] = data.get('width')
self.height: int = data['height']
self.avg_color: Optional[str] = data.get('avg_color')
Expand Down
188 changes: 2 additions & 186 deletions mipac/core/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
from typing import Any, Optional

from mipac.core.models.drive import RawFile
from mipac.core.models.emoji import RawEmoji
from mipac.core.models.instance import RawInstance
from mipac.types.user import IChannel, IPinnedNote, UserPayload
from mipac.types.user import IChannel, IPinnedNote

__all__ = ('RawUserDetails', 'RawUser', 'RawChannel', 'RawPinnedNote')
__all__ = ('RawUserDetails', 'RawChannel', 'RawPinnedNote')


class RawChannel:
Expand Down Expand Up @@ -72,185 +70,3 @@ def __init__(self, data: IPinnedNote):
self.uri: Optional[str] = data.get('uri')
self.url: Optional[str] = data.get('url')
self.my_reaction: Optional[dict[str, Any]] = data.get('my_reaction')


class RawUserDetails:
"""
ユーザー情報だが、一般的に使うか怪しいもの
Attributes
----------
avatar_blurhash: Optional[str]
ユーザーのアバターのblurhash
avatar_color: str
ユーザーのアバターの色
lang: str
ユーザーの言語
"""

__slots__ = (
'avatar_blurhash',
'avatar_color',
'banner_url',
'banner_blurhash',
'banner_color',
'two_factor_enabled',
'use_password_less_login',
'security_keys',
'has_pending_follow_request_from_you',
'has_pending_follow_request_to_you',
'public_reactions',
'lang',
)

def __init__(self, data):
self.avatar_blurhash: Optional[str] = data.get('avatar_blurhash')
self.avatar_color: Optional[str] = data.get('avatar_color')
self.banner_url = data.get('banner_url')
self.banner_blurhash = data.get('banner_blurhash')
self.banner_color = data.get('banner_color')
self.two_factor_enabled = data.get('two_factor_enabled', False)
self.use_password_less_login = data.get(
'use_password_less_login', False
)
self.security_keys = data.get('security_keys', False)
self.has_pending_follow_request_from_you = data.get(
'has_pending_follow_request_from_you', False
)
self.has_pending_follow_request_to_you = data.get(
'has_pending_follow_request_to_you', False
)
self.public_reactions = data.get('public_reactions', False)
self.lang = data.get('lang')


class RawUser:
"""
id : str
ユーザーのID
name : str
ユーザーの名前
nickname : Optional[str]
ユーザーの表示名
host : Optional[str]
# TODO: いい感じに
avatar_url : Optional[str]
ユーザーのアバターurl
is_admin : bool
管理者か否か
is_bot : bool
ボットか否か
is_cat : bool
ねこか否か
is_lady : bool
お嬢様か否か (Ayuskeyのみ)
emojis : Optional[list[str]]
# TODO 謎
url : Optional[str]
# TODO 謎
uri : Optional[str]
# TODO 謎
created_at : Optional[datetime]
ユーザーの作成日時
ff_visibility : str
# TODO 謎
is_following : bool
フォローされてるか否か
is_follow : bool
フォローしているか否か
is_blocking : bool
ブロックしているか否か
is_blocked : bool
ブロックされてるか否か
is_muted : bool
ミュートしているか否か
details : RawUserDetails
ユーザーの詳細情報
instance : Optional[RawInstance]
インスタンスの情報
"""

__slots__ = (
'id',
'name',
'nickname',
'host',
'avatar_url',
'is_admin',
'is_moderator',
'is_bot',
'is_cat',
'is_lady',
'emojis',
'online_status',
'url',
'uri',
'created_at',
'updated_at',
'is_locked',
'is_silenced',
'is_suspended',
'description',
'location',
'birthday',
'fields',
'followers_count',
'following_count',
'notes_count',
'pinned_note_ids',
'pinned_notes',
'pinned_page_id',
'pinned_page',
'ff_visibility',
'is_following',
'is_follow',
'is_blocking',
'is_blocked',
'is_muted',
'details',
'instance',
)

def __init__(self, data: UserPayload):
self.id: str = data['user_id'] if data.get('user_id') else data['id']
self.name: str = data['username']
self.nickname: Optional[str] = data.get('name')
self.host: Optional[str] = data.get('host')
self.avatar_url: Optional[str] = data.get('avatar_url')
self.is_admin: bool = bool(data.get('is_admin'))
self.is_moderator: bool = bool(data.get('is_moderator'))
self.is_bot: bool = bool(data.get('is_bot'))
self.is_cat: bool = bool(data.get('is_cat', False))
self.is_lady: bool = bool(data.get('is_lady', False))
self.emojis: Optional[list[str]] = data.get('emojis')
self.online_status = data.get('online_status', None)
self.url: Optional[str] = data.get('url')
self.uri: Optional[str] = data.get('uri')
self.created_at: Optional[datetime] = datetime.strptime(
data['created_at'], '%Y-%m-%dT%H:%M:%S.%fZ'
) if data.get('created_at') else None
self.updated_at = data.get('updated_at')
self.is_locked = data.get('is_locked', False)
self.is_silenced = data.get('is_silenced', False)
self.is_suspended = data.get('is_suspended', False)
self.description = data.get('description')
self.location = data.get('location')
self.birthday = data.get('birthday')
self.fields = data.get('fields', [])
self.followers_count = data.get('followers_count', 0)
self.following_count = data.get('following_count', 0)
self.notes_count = data.get('notes_count', 0)
self.pinned_note_ids = data.get('pinned_note_ids', [])
self.pinned_notes = data.get('pinned_notes', [])
self.pinned_page_id = data.get('pinned_page_id')
self.pinned_page = data.get('pinned_page')
self.ff_visibility: str = data.get('ff_visibility', 'public')
self.is_following: bool = bool(data.get('is_following', False))
self.is_follow: bool = bool(data.get('is_follow', False))
self.is_blocking: bool = bool(data.get('is_blocking', False))
self.is_blocked: bool = bool(data.get('is_blocked', False))
self.is_muted: bool = bool(data.get('is_muted', False))
self.details: RawUserDetails = RawUserDetails(data)
self.instance: Optional[RawInstance] = RawInstance(
data['instance']
) if data.get('instance') else None
6 changes: 3 additions & 3 deletions mipac/manager/admin/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

if TYPE_CHECKING:
from mipac.client import ClientActions
from mipac.models.user import User
from mipac.models.user import UserDetailed


class AdminUserManager:
Expand Down Expand Up @@ -47,7 +47,7 @@ async def delete_account(self, user_id: Optional[str] = None) -> bool:
)
return bool(res)

async def show_user(self, user_id: Optional[str] = None) -> User:
async def show_user(self, user_id: Optional[str] = None) -> UserDetailed:
"""
Shows the user with the specified user ID.
Expand All @@ -58,7 +58,7 @@ async def show_user(self, user_id: Optional[str] = None) -> User:
Returns
-------
User
UserDetailed
"""

user_id = user_id or self.__user_id
Expand Down
6 changes: 3 additions & 3 deletions mipac/manager/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

if TYPE_CHECKING:
from mipac.config import Config
from mipac.models.user import User
from mipac.models.user import UserDetailed

__all__ = ('ClientActions',)

Expand All @@ -34,11 +34,11 @@ def __init__(self, session: HTTPClient, config: Config):
self._config: Config = config
self._modeler: Modeler = Modeler(self)

def _create_user_instance(self, user: User) -> UserManager:
def _create_user_instance(self, user: UserDetailed) -> UserManager:
return UserManager(session=self.__session, client=self, user=user)

def _create_note_instance(self, note_id: str) -> NoteManager:
return NoteManager(note_id, session=self.__session, client=self)

async def get_me(self) -> User:
async def get_me(self) -> UserDetailed:
return await self.user.action.get_me()
Loading

0 comments on commit f7ef493

Please sign in to comment.