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

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

@ -5,7 +5,8 @@ from .emoji import EmojiPayload
from .user import UserPayload from .user import UserPayload
__all__ = ( __all__ = (
'NotePayload', 'INoteRequired',
'INote',
'GeoPayload', 'GeoPayload',
'ReactionPayload', 'ReactionPayload',
'PollPayload', 'PollPayload',
@ -60,47 +61,43 @@ class RenotePayload(TypedDict):
channel_id: Optional[str] channel_id: Optional[str]
class _NoteOptional(TypedDict, total=False): class INoteRequired(TypedDict):
""" id: str
ノートに必ず存在すると限らない物 created_at: str
""" user_id: str
user: UserPayload
text: str emojis: List[EmojiPayload]
cw: str reactions: Dict[str, Any]
geo: GeoPayload
class NotePayload(_NoteOptional): class INote(INoteRequired, total=False):
""" """
note object 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): class OptionalReaction(TypedDict, total=False):
@ -108,7 +105,7 @@ class OptionalReaction(TypedDict, total=False):
type: str type: str
is_read: bool is_read: bool
user: UserPayload user: UserPayload
note: NotePayload note: INote
id: str id: str

Loading…
Cancel
Save