Skip to content

Commit

Permalink
feat: RawEmoji, Emoji クラスを削除 #10
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Aug 29, 2022
1 parent ccb8c3b commit 9e45f5c
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 90 deletions.
34 changes: 0 additions & 34 deletions mipac/core/models/emoji.py

This file was deleted.

12 changes: 0 additions & 12 deletions mipac/manager/modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@

from mipac.core.models.chat import RawChat
from mipac.core.models.drive import RawFolder
from mipac.core.models.emoji import RawEmoji
from mipac.core.models.instance import RawInstance
from mipac.models.chat import Chat
from mipac.models.drive import File, Folder
from mipac.models.emoji import Emoji
from mipac.models.instance import Instance
from mipac.models.note import Note, NoteReaction
from mipac.models.user import FollowRequest, User

if TYPE_CHECKING:
from mipac.core import RawFile, RawUser
from mipac.core.models.reaction import RawNoteReaction
from mipac.manager.client import ClientActions


Expand All @@ -42,13 +38,5 @@ def create_file_instance(self, raw_file: RawFile) -> File:
def new_follow_request(self, raw_follow_request: Any) -> FollowRequest:
return FollowRequest(raw_follow_request)

def new_note_reaction(
self, raw_note_reaction: RawNoteReaction
) -> NoteReaction:
return NoteReaction(raw_note_reaction, client=self._client)

def new_emoji(self, raw_emoji: RawEmoji) -> Emoji:
return Emoji(raw_emoji, client=self._client)

def new_folder(self, raw_folder: RawFolder) -> Folder:
return Folder(raw_folder, client=self._client)
13 changes: 4 additions & 9 deletions mipac/manager/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
from typing import TYPE_CHECKING, Optional

from mipac.abc.manager import AbstractManager
from mipac.core.models.emoji import RawEmoji
from mipac.core.models.reaction import RawNoteReaction
from mipac.http import HTTPClient, Route
from mipac.models.emoji import CustomEmoji
from mipac.util import remove_dict_empty

if TYPE_CHECKING:
from mipac.client import ClientActions
from mipac.models.emoji import Emoji
from mipac.models.note import NoteReaction

__all__ = 'ReactionManager'
Expand Down Expand Up @@ -77,15 +75,12 @@ async def get_reaction(
lower=True,
)
return [
self.__client._modeler.new_note_reaction(RawNoteReaction(i))
NoteReaction(i)
for i in res
]

async def get_emoji_list(self) -> list[Emoji]:
async def get_emoji_list(self) -> list[CustomEmoji]:
data = await self.__session.request(
Route('GET', '/api/meta'), json={'detail': False}, auth=True
)
return [
self.__client._modeler.new_emoji(RawEmoji(i))
for i in data['emojis']
]
return [CustomEmoji(i, client=self.__client) for i in data['emojis']]
2 changes: 0 additions & 2 deletions mipac/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .chat import Chat
from .drive import File, Folder, Properties
from .emoji import Emoji
from .instance import Instance, InstanceMeta
from .note import Follow, Header, Note, NoteReaction, Poll
from .notification import Reaction
Expand All @@ -13,7 +12,6 @@
'Folder',
'InstanceMeta',
'Instance',
'Emoji',
'User',
'FollowRequest',
'Followee',
Expand Down
64 changes: 38 additions & 26 deletions mipac/models/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,55 @@

from typing import TYPE_CHECKING

from mipac.core.models.emoji import RawEmoji
from mipac.types.emoji import ICustomEmoji

if TYPE_CHECKING:
from mipac.client import ClientActions

__all__ = ('Emoji',)


class Emoji:
def __init__(self, raw_data: RawEmoji, *, client: ClientActions):
self._raw_data = raw_data
self._client = client
__all__ = ('CustomEmoji', )


class CustomEmoji:
"""
Attributes
----------
id : Optional[str]
絵文字のID
aliases : Optional[list[str]]
絵文字のエイリアス
name : Optional[str]
絵文字の名前
category : Optional[str]
絵文字のカテゴリ
host : Optional[str]
絵文字のホスト
url : Optional[str]
絵文字のURL
"""

__slots__ = ('id', 'aliases', 'name', 'category', 'url', '__emoji', '__client')

def __init__(self, emoji: ICustomEmoji, *, client: ClientActions):
self.__emoji: ICustomEmoji = emoji
self.__client: ClientActions = client


@property
def id(self):
return self._raw_data.id
def id(self) -> str:
return self.__emoji['id']

@property
def aliases(self):
return self._raw_data.aliases
def aliases(self) -> list[str]:
return self.__emoji['aliases']

@property
def name(self):
return self._raw_data.name
def name(self) -> str:
return self.__emoji['name']

@property
def category(self):
return self._raw_data.category
def category(self) -> str:
return self.__emoji['category']

@property
def host(self):
return self._raw_data.host

@property
def url(self):
return self._raw_data.url

# @property
# def action(self):
# return mi.framework.manager.ClientActions().emoji
def url(self) -> str:
return self.__emoji['url']
5 changes: 2 additions & 3 deletions mipac/models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from typing import TYPE_CHECKING, Optional

from mipac.core.models.emoji import RawEmoji
from mipac.core.models.instance import RawInstance
from mipac.models.emoji import Emoji
from mipac.models.emoji import CustomEmoji
from mipac.types.instance import MetaPayload

if TYPE_CHECKING:
Expand Down Expand Up @@ -49,7 +48,7 @@ def __init__(self, data: MetaPayload):
self.mascot_image_url: str = data['mascot_image_url']
self.error_image: str = data['error_image_url']
self.max_note_text_length: int = data['max_note_text_length']
self.emojis: list[Emoji] = [Emoji(RawEmoji(i)) for i in data['emojis']]
self.emojis: list[CustomEmoji] = [CustomEmoji(i) for i in data['emojis']]
self.ads: list = data['ads']
self.enable_email: bool = bool(data['enable_email'])
self.enable_twitter_integration = bool(
Expand Down
6 changes: 3 additions & 3 deletions mipac/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from typing import TYPE_CHECKING, Any, List, Optional, Union

from mipac.core.models.user import RawChannel, RawPinnedNote, RawUser
from mipac.models.emoji import CustomEmoji
from mipac.types.user import FieldContentPayload, PinnedPagePayload

if TYPE_CHECKING:
from mipac.actions.user import UserActions
from mipac.manager.client import ClientActions
from mipac.models.drive import File
from mipac.models.emoji import Emoji
from mipac.models.instance import Instance

__all__ = ['User', 'FollowRequest', 'Followee']
Expand Down Expand Up @@ -178,9 +178,9 @@ def local_only(self) -> bool:
return self._raw_data.local_only

@property
def emojis(self) -> Optional[list[Emoji]]:
def emojis(self) -> list[CustomEmoji] | None:
return [
self._client._modeler.new_emoji(i) for i in self._raw_data.emojis
CustomEmoji(i, client=self._client) for i in self._raw_data.emojis
]

@property
Expand Down
7 changes: 6 additions & 1 deletion mipac/types/emoji.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from typing import Optional, TypedDict

__all__ = ('EmojiPayload', 'ICustomEmojiLite')
__all__ = ('EmojiPayload', 'ICustomEmojiLite', 'ICustomEmoji')


class ICustomEmojiLite(TypedDict):
name: str
url: str

class ICustomEmoji(ICustomEmojiLite):
id: str
category: str
aliases: list[str]


class EmojiPayload(TypedDict):
id: Optional[str]
Expand Down

0 comments on commit 9e45f5c

Please sign in to comment.