Skip to content

Commit

Permalink
feat: MiPAC v0.6.0への対応
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Feb 20, 2024
1 parent 54108c8 commit 36494ef
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 63 deletions.
4 changes: 2 additions & 2 deletions mipa/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
27 changes: 4 additions & 23 deletions mipa/ext/commands/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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: 直す
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
4 changes: 2 additions & 2 deletions mipa/ext/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
48 changes: 14 additions & 34 deletions mipa/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -54,21 +53,20 @@
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,
INoteUpdatedDelete,
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__)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
aiohttp==3.8.4
mipac==0.5.0
aiohttp==3.9.1
mipac==0.6.0
versioneer

0 comments on commit 36494ef

Please sign in to comment.