diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 65abd71..c0c92e0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,7 @@ repos: stages: [commit] - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.1.1 hooks: - id: black stages: [commit] diff --git a/nonebot_plugin_all4one/middlewares/base.py b/nonebot_plugin_all4one/middlewares/base.py index 4fb859e..dc2c50d 100644 --- a/nonebot_plugin_all4one/middlewares/base.py +++ b/nonebot_plugin_all4one/middlewares/base.py @@ -131,9 +131,7 @@ async def get_self_info( """获取机器人自身信息""" raise NotImplementedError - async def get_user_info( - self, *, user_id: str, **kwargs: Any - ) -> Dict[ + async def get_user_info(self, *, user_id: str, **kwargs: Any) -> Dict[ Union[Literal["user_id", "user_name", "user_displayname", "user_remark"], str], str, ]: diff --git a/nonebot_plugin_all4one/middlewares/qqguild.py b/nonebot_plugin_all4one/middlewares/qqguild.py index b055429..3bee58b 100644 --- a/nonebot_plugin_all4one/middlewares/qqguild.py +++ b/nonebot_plugin_all4one/middlewares/qqguild.py @@ -267,7 +267,9 @@ async def send_message( # NoneBot 的默认 API_TIMEOUT 为 30s,这里设置为 25s result = await e.get_audit_result(timeout=25) if result.message_id is None: - raise ob_exception.PlatformError("failed", 34001, "消息审核未通过", None) + raise ob_exception.PlatformError( + "failed", 34001, "消息审核未通过", None + ) time = result.audit_time.timestamp() # type: ignore message_id = { "message_id": result.message_id, @@ -351,9 +353,9 @@ async def get_guild_member_info( "user_displayname": member.nick or "", "qqguild.user": member.user.dict() if member.user else None, "qqguild.roles": member.roles, - "qqguild.joined_at": member.joined_at.timestamp() - if member.joined_at - else None, + "qqguild.joined_at": ( + member.joined_at.timestamp() if member.joined_at else None + ), } async def _get_all_members(self, guild_id: str) -> List[Member]: @@ -388,9 +390,9 @@ async def get_guild_member_list( "user_displayname": member.nick or "", "qqguild.user": member.user.dict() if member.user else None, "qqguild.roles": member.roles, - "qqguild.joined_at": member.joined_at.timestamp() - if member.joined_at - else None, + "qqguild.joined_at": ( + member.joined_at.timestamp() if member.joined_at else None + ), } ) return members_list @@ -425,15 +427,15 @@ async def get_channel_list( { "channel_id": str(channel.id) if channel.id else "", "channel_name": channel.name or "", - "qqguild.guild_id": str(channel.guild_id) - if channel.guild_id - else "", + "qqguild.guild_id": ( + str(channel.guild_id) if channel.guild_id else "" + ), "qqguild.channel_type": channel.type, "qqguild.position": channel.position, "qqguild.parent_id": channel.parent_id, - "qqguild.owner_id": str(channel.owner_id) - if channel.owner_id - else "", + "qqguild.owner_id": ( + str(channel.owner_id) if channel.owner_id else "" + ), "qqguild.sub_type": channel.sub_type, "qqguild.private_type": channel.private_type, } @@ -449,7 +451,10 @@ async def set_channel_name( @supported_action async def get_channel_member_info( self, *, guild_id: str, channel_id: str, user_id: str, **kwargs: Any - ) -> Dict[Union[Literal["user_id", "user_name", "user_displayname"], str], Any,]: + ) -> Dict[ + Union[Literal["user_id", "user_name", "user_displayname"], str], + Any, + ]: member = await self.bot.get_member(guild_id=int(guild_id), user_id=int(user_id)) if member.user is None: raise ob_exception.PlatformError("failed", 34001, "用户不存在", None) @@ -460,9 +465,9 @@ async def get_channel_member_info( "user_displayname": member.nick or "", "qqguild.user": member.user.dict() if member.user else {}, "qqguild.roles": member.roles, - "qqguild.joined_at": member.joined_at.timestamp() - if member.joined_at - else None, + "qqguild.joined_at": ( + member.joined_at.timestamp() if member.joined_at else None + ), } @supported_action @@ -517,9 +522,9 @@ def can_view(member: Member) -> bool: "user_displayname": member.nick or "", "qqguild.user": member.user.dict() if member.user else {}, "qqguild.roles": member.roles, - "qqguild.joined_at": member.joined_at.timestamp() - if member.joined_at - else None, + "qqguild.joined_at": ( + member.joined_at.timestamp() if member.joined_at else None + ), } ) return members_list diff --git a/nonebot_plugin_all4one/middlewares/telegram.py b/nonebot_plugin_all4one/middlewares/telegram.py index 27bca1c..c5e4c74 100644 --- a/nonebot_plugin_all4one/middlewares/telegram.py +++ b/nonebot_plugin_all4one/middlewares/telegram.py @@ -64,9 +64,11 @@ async def to_onebot_event(self, event: Event) -> List[OneBotEvent]: 0, OneBotMessageSegment.reply( f"{event.reply_to_message.chat.id}/{event.reply_to_message.message_id}", - user_id=event.reply_to_message.get_user_id() - if not isinstance(event.reply_to_message, ChannelPostEvent) - else "", + user_id=( + event.reply_to_message.get_user_id() + if not isinstance(event.reply_to_message, ChannelPostEvent) + else "" + ), ), ) elif isinstance(event, NoticeEvent): @@ -219,9 +221,7 @@ async def get_self_info( } @supported_action - async def get_user_info( - self, *, user_id: str, **kwargs: Any - ) -> Dict[ + async def get_user_info(self, *, user_id: str, **kwargs: Any) -> Dict[ Union[Literal["user_id", "user_name", "user_displayname", "user_remark"], str], str, ]: diff --git a/nonebot_plugin_all4one/migrations/6e6321bc6c48_init_db.py b/nonebot_plugin_all4one/migrations/6e6321bc6c48_init_db.py index 1a12d5e..85a90b9 100644 --- a/nonebot_plugin_all4one/migrations/6e6321bc6c48_init_db.py +++ b/nonebot_plugin_all4one/migrations/6e6321bc6c48_init_db.py @@ -5,6 +5,7 @@ Create Date: 2023-02-20 21:50:33.023674 """ + import sqlalchemy as sa from alembic import op diff --git a/nonebot_plugin_all4one/migrations/d0a1d19f3408_.py b/nonebot_plugin_all4one/migrations/d0a1d19f3408_.py index 20272a1..04c8b8d 100644 --- a/nonebot_plugin_all4one/migrations/d0a1d19f3408_.py +++ b/nonebot_plugin_all4one/migrations/d0a1d19f3408_.py @@ -5,6 +5,7 @@ Create Date: 2023-02-26 14:09:17.473872 """ + import sqlalchemy as sa from alembic import op diff --git a/nonebot_plugin_all4one/onebotimpl/__init__.py b/nonebot_plugin_all4one/onebotimpl/__init__.py index fd039c6..866fa21 100644 --- a/nonebot_plugin_all4one/onebotimpl/__init__.py +++ b/nonebot_plugin_all4one/onebotimpl/__init__.py @@ -383,9 +383,9 @@ async def _handle_ws(self, conn: WebsocketConfig, websocket: WebSocket) -> None: async def _http_webhook(self, conn: HTTPWebhookConfig): headers = { - "Content-Type": "application/msgpack" - if conn.use_msgpack - else "application/json", + "Content-Type": ( + "application/msgpack" if conn.use_msgpack else "application/json" + ), "User-Agent": "OneBot/12 NoneBot Plugin All4One/0.1.0", "X-OneBot-Version": "12", "X-Impl": "nonebot-plugin-all4one", diff --git a/tests/middlewares/villa/test_villa.py b/tests/middlewares/villa/test_villa.py index f5aa6f1..55fee6a 100644 --- a/tests/middlewares/villa/test_villa.py +++ b/tests/middlewares/villa/test_villa.py @@ -32,5 +32,6 @@ async def test_to_onebot_event(app: App): assert channel_create.message_id == "C9G5-O2GK-FJB9-EVB0" assert channel_create.channel_id == "39761" assert ( - channel_create.alt_message == "/帮助" + channel_create.alt_message + == "/帮助" )