feat: Noteの型を修正 issue #11

pull/11/head
yupix 2 years ago
parent 7426f82dc7
commit d0e214c440
No known key found for this signature in database
GPG Key ID: 2FF705F5C56D9C06

@ -7,7 +7,7 @@ from mipac.core.models.drive import RawFile
from mipac.core.models.emoji import RawEmoji
from mipac.core.models.poll import RawPoll
from mipac.core.models.user import RawUser
from mipac.types.note import NotePayload, ReactionPayload, RenotePayload
from mipac.types.note import INote, ReactionPayload, RenotePayload
from mipac.util import upper_to_lower
__all__ = ('RawRenote', 'RawReaction', 'RawNote')
@ -76,9 +76,7 @@ class RawRenote:
self.reply_id = data['reply_id']
self.renote_id = data['renote_id']
self.uri = data.get('uri')
self.poll: Optional[RawPoll] = RawPoll(data['poll']) if data.get(
'poll'
) else None
self.poll: Optional[RawPoll] = RawPoll(data['poll']) if 'poll' in data else None
class RawReaction:
@ -186,7 +184,7 @@ class RawNote:
'channel_id',
)
def __init__(self, data: NotePayload):
def __init__(self, data: INote):
self.id: str = data['id']
self.created_at: datetime = datetime.strptime(
data['created_at'], '%Y-%m-%dT%H:%M:%S.%fZ'
@ -197,27 +195,25 @@ class RawNote:
self.cw: Optional[str] = data.get('cw')
self.renote: Optional[RawRenote] = RawRenote(
data['renote']
) if data.get('renote') else None
) if 'renote' in data else None
self.visibility: Optional[str] = data.get(
'visibility'
) # This may be an optional
)
self.renote_count: Optional[int] = data.get(
'renote_count'
) # TODO: Optionalかどうか
)
self.replies_count: Optional[int] = data.get(
'replies_count'
) # TODO: Optionalかどうか
)
self.reactions: Dict[str, Any] = data['reactions']
self.emojis: List[RawEmoji] = [RawEmoji(i) for i in data['emojis']]
self.file_ids: Optional[List[str]] = data['file_ids']
self.file_ids: Optional[List[str]] = data.get('file_ids')
self.files: List[RawFile] = [
RawFile(upper_to_lower(i)) for i in data['files']
]
self.reply_id: Optional[str] = data['reply_id']
self.renote_id: Optional[str] = data['renote_id']
self.poll: Optional[RawPoll] = RawPoll(data['poll']) if data.get(
'poll'
) else None
] if 'files' in data else []
self.reply_id: Optional[str] = data.get('reply_id')
self.renote_id: Optional[str] = data.get('renote_id')
self.poll: Optional[RawPoll] = RawPoll(data['poll']) if 'poll' in data else None
self.visible_user_ids: Optional[List[str]] = data.get(
'visible_user_ids', []
)

@ -16,7 +16,8 @@ from mipac.types.instance import (
)
from mipac.types.note import (
GeoPayload,
NotePayload,
INoteRequired,
INote,
OptionalReaction,
PollPayload,
ReactionPayload,
@ -50,7 +51,8 @@ __all__ = (
'FolderPayload',
'FilePayload',
'EmojiPayload',
'NotePayload',
'INoteRequired',
'INote',
'GeoPayload',
'ReactionPayload',
'PollPayload',

@ -5,7 +5,8 @@ from .emoji import EmojiPayload
from .user import UserPayload
__all__ = (
'NotePayload',
'INoteRequired',
'INote',
'GeoPayload',
'ReactionPayload',
'PollPayload',
@ -60,47 +61,43 @@ class RenotePayload(TypedDict):
channel_id: Optional[str]
class _NoteOptional(TypedDict, total=False):
"""
ノートに必ず存在すると限らない物
"""
text: str
cw: str
geo: GeoPayload
class INoteRequired(TypedDict):
id: str
created_at: str
user_id: str
user: UserPayload
emojis: List[EmojiPayload]
reactions: Dict[str, Any]
class NotePayload(_NoteOptional):
class INote(INoteRequired, total=False):
"""
note object
"""
visibility: str
renote_count: int
replies_count: int
file_ids: List[str]
files: List[FilePayload]
reply_id: str
renote_id: str
poll: PollPayload
visible_user_ids: List[str]
via_mobile: bool
local_only: bool
extract_mentions: bool
extract_hashtags: bool
extract_emojis: bool
preview: bool
media_ids: List[str]
renote: RenotePayload
field: dict
tags: List[str]
channel_id: str
text: str
cw: str
geo: GeoPayload
id: str
created_at: str
user_id: str
user: UserPayload
visibility: Optional[str]
renote_count: Optional[int]
replies_count: Optional[int]
reactions: Dict[str, Any]
emojis: List[EmojiPayload]
file_ids: Optional[List[str]]
files: Optional[List[FilePayload]]
reply_id: Optional[str]
renote_id: Optional[str]
poll: Optional[PollPayload]
visible_user_ids: Optional[List[str]]
via_mobile: Optional[bool]
local_only: Optional[bool]
extract_mentions: Optional[bool]
extract_hashtags: Optional[bool]
extract_emojis: Optional[bool]
preview: Optional[bool]
media_ids: Optional[List[str]]
renote: Optional[RenotePayload]
field: Optional[dict]
tags: Optional[List[str]]
channel_id: Optional[str]
class OptionalReaction(TypedDict, total=False):
@ -108,7 +105,7 @@ class OptionalReaction(TypedDict, total=False):
type: str
is_read: bool
user: UserPayload
note: NotePayload
note: INote
id: str

Loading…
Cancel
Save