From 36494ef5de2f21f769daeadab2eceebb8407ee0d Mon Sep 17 00:00:00 2001 From: yupix Date: Tue, 20 Feb 2024 21:28:43 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20MiPAC=20v0.6.0=E3=81=B8=E3=81=AE?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mipa/client.py | 4 +-- mipa/ext/commands/bot.py | 27 +++----------------- mipa/ext/commands/context.py | 4 +-- mipa/state.py | 48 +++++++++++------------------------- requirements.txt | 4 +-- 5 files changed, 24 insertions(+), 63 deletions(-) diff --git a/mipa/client.py b/mipa/client.py index 234d43e..e5b7729 100644 --- a/mipa/client.py +++ b/mipa/client.py @@ -41,7 +41,7 @@ from aiohttp import ClientWebSocketResponse from mipac.client import Client as API from mipac.manager.client import ClientManager -from mipac.models.user import UserDetailed +from mipac.models.user import MeDetailed from mipa.exception import WebSocketNotConnected, WebSocketReconnect from mipa.gateway import MisskeyWebSocket @@ -70,7 +70,7 @@ def __init__( self.loop = asyncio.get_event_loop() if loop is None else loop self.core: API self._connection: ConnectionState - self.user: UserDetailed + self.user: MeDetailed self.ws: Optional[MisskeyWebSocket] = None self.should_reconnect = True diff --git a/mipa/ext/commands/bot.py b/mipa/ext/commands/bot.py index 710a6ac..85ad6bb 100644 --- a/mipa/ext/commands/bot.py +++ b/mipa/ext/commands/bot.py @@ -47,9 +47,8 @@ Union, ) -from mipac.models.chat import ChatMessage from mipac.models.emoji import CustomEmoji -from mipac.models.user import UserDetailed +from mipac.models.user import MeDetailed, UserDetailedNotMe from mipa import Client from mipa.exception import ( @@ -90,7 +89,7 @@ def __init__(self, **options: dict[Any, Any]): self.token: Optional[str] = None self.origin_uri: Optional[str] = None self.__extensions: dict[str, Any] = {} - self.user: UserDetailed + self.user: MeDetailed self.__cogs: dict[str, Cog] = {} self.strip_after_prefix = options.get("strip_after_prefix", False) # self.logger = get_module_logger(__name__) TODO: 直す @@ -313,7 +312,7 @@ async def progress_command(self, message): else: continue - async def on_user_follow(self, user: UserDetailed): + async def on_user_follow(self, user: UserDetailedNotMe): """ When you follow a user @@ -322,7 +321,7 @@ async def on_user_follow(self, user: UserDetailed): user : UserDetailed """ - async def on_user_unfollow(self, user: UserDetailed): + async def on_user_unfollow(self, user: UserDetailedNotMe): """ When you unfollow a user @@ -422,24 +421,6 @@ async def on_follow_request_accept(self, notice: NotificationFollow): notice : NotificationFollow """ - async def on_chat(self, message: ChatMessage): - """ - When someone send you a chat message - - Parameters - ---------- - message : ChatMessage - """ - - async def on_chat_unread_message(self, message: ChatMessage): - """ - When someone send you a chat message, - and you have not connected to that chat. - - Parameters - ---------- - message : ChatMessage - """ async def on_achievement_earned(self, notice: NotificationAchievement): """ diff --git a/mipa/ext/commands/context.py b/mipa/ext/commands/context.py index e09c1bd..d82254f 100644 --- a/mipa/ext/commands/context.py +++ b/mipa/ext/commands/context.py @@ -30,7 +30,7 @@ from typing import TYPE_CHECKING from mipac import Note -from mipac.models.lite.user import LiteUser +from mipac.models.lite.user import PartialUser if TYPE_CHECKING: from mipa.ext.commands import CMD, BotBase @@ -60,7 +60,7 @@ def message(self) -> Note: return self.__message @property - def author(self) -> LiteUser: + def author(self) -> PartialUser: return self.__message.author @property diff --git a/mipa/state.py b/mipa/state.py index ff914e4..eca1caa 100644 --- a/mipa/state.py +++ b/mipa/state.py @@ -42,7 +42,6 @@ ) from mipac.models import Note -from mipac.models.chat import ChatMessage from mipac.models.emoji import CustomEmoji from mipac.models.note import NoteDeleted from mipac.models.notification import ( @@ -54,9 +53,9 @@ NotificationReaction, ) from mipac.models.reaction import PartialReaction -from mipac.models.user import UserDetailed +from mipac.models.user import MeDetailed, UserDetailedNotMe +from mipac.types.user import IUserDetailedNotMeSchema, IMeDetailedSchema from mipac.types import INote -from mipac.types.chat import IChatMessage from mipac.types.emoji import ICustomEmoji from mipac.types.note import ( INoteUpdated, @@ -64,11 +63,10 @@ INoteUpdatedReaction, ) from mipac.utils.format import str_lower, upper_to_lower +from mipac.types.notification import INotification -if TYPE_CHECKING: - from mipac.types.notification import INotification - from mipac.types.user import IUserDetailed +if TYPE_CHECKING: from mipa.client import Client _log = logging.getLogger(__name__) @@ -145,21 +143,25 @@ async def parse_channel(self, message: Dict[str, Any], **kwargs) -> None: else: _log.debug(f"Unknown event type: {channel_type}") - async def parse_follow(self, message: IUserDetailed, **kwargs) -> None: + async def parse_follow( + self, message: IUserDetailedNotMeSchema, **kwargs + ) -> None: """ When you follow someone, this event will be called """ - user: UserDetailed = UserDetailed( + user = UserDetailedNotMe( message, client=self.api, ) self.__dispatch("user_follow", user) - async def parse_unfollow(self, message: IUserDetailed, **kwargs): + async def parse_unfollow( + self, message: IUserDetailedNotMeSchema, **kwargs + ): """ When you unfollow someone, this event will be called """ - user: UserDetailed = UserDetailed( + user = UserDetailedNotMe( message, client=self.api, ) @@ -196,8 +198,8 @@ async def parse_reacted( ): self.__dispatch("reacted", PartialReaction(reaction, client=self.api)) - async def parse_me_updated(self, user: IUserDetailed, **kwargs): - self.__dispatch("me_updated", UserDetailed(user, client=self.api)) + async def parse_me_updated(self, user: IMeDetailedSchema, **kwargs): + self.__dispatch("me_updated", MeDetailed(user, client=self.api)) async def parse_announcement_created( self, message: Dict[str, Any], **kwargs @@ -254,28 +256,6 @@ async def parse_read_all_messaging_messages( ) -> None: pass - async def parse_messaging_message( - self, message: IChatMessage, **kwargs - ) -> None: - """ - チャットが来た際のデータを処理する関数 - """ - self.__dispatch( - "chat", - ChatMessage(message, client=self.api), - ) - - async def parse_unread_messaging_message( - self, message: IChatMessage, **kwargs - ) -> None: - """ - チャットが既読になっていない場合のデータを処理する関数 - """ - self.__dispatch( - "chat_unread_message", - ChatMessage(message, client=self.api), - ) - async def parse_notification( self, notification_data: Dict[str, Any], **kwargs ) -> None: diff --git a/requirements.txt b/requirements.txt index 3236de8..db41237 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -aiohttp==3.8.4 -mipac==0.5.0 +aiohttp==3.9.1 +mipac==0.6.0 versioneer