From 966bd77a8b8affe06f872547f98a8cd354ef2108 Mon Sep 17 00:00:00 2001 From: RF-Tar-Railt <3165388245@qq.com> Date: Sat, 13 Jan 2024 20:42:21 +0800 Subject: [PATCH] chore: format --- avilla/core/application.py | 4 ++-- avilla/core/context/_selector.py | 4 ++-- avilla/core/event.py | 3 +-- avilla/core/metadata.py | 16 +++++++++++++--- avilla/core/selector.py | 2 +- avilla/core/tools/filter.py | 2 +- avilla/elizabeth/perform/action/contact.py | 2 +- avilla/elizabeth/perform/action/friend.py | 2 +- avilla/elizabeth/perform/action/group.py | 2 +- avilla/elizabeth/perform/action/member.py | 2 +- avilla/elizabeth/perform/event/friend.py | 6 +----- avilla/elizabeth/perform/event/group.py | 8 ++------ avilla/elizabeth/perform/event/member.py | 8 ++------ avilla/onebot/v11/perform/event/notice.py | 2 +- avilla/qqapi/perform/action/guild_member.py | 2 +- avilla/qqapi/perform/action/message.py | 8 ++++---- avilla/qqapi/perform/event/message.py | 10 +++++----- avilla/standard/core/profile/__init__.py | 2 +- avilla/twilight/twilight.py | 8 ++++---- 19 files changed, 45 insertions(+), 48 deletions(-) diff --git a/avilla/core/application.py b/avilla/core/application.py index 9d392d62..7d234305 100644 --- a/avilla/core/application.py +++ b/avilla/core/application.py @@ -14,14 +14,14 @@ from avilla.core._runtime import get_current_avilla from avilla.core.account import AccountInfo, BaseAccount from avilla.core.dispatchers import AvillaBuiltinDispatcher +from avilla.core.event import MetadataModified from avilla.core.protocol import BaseProtocol from avilla.core.ryanvk.staff import Staff from avilla.core.selector import Selector from avilla.core.service import AvillaService from avilla.core.utilles import identity -from avilla.core.event import MetadataModified -from avilla.standard.core.request import RequestEvent from avilla.standard.core.activity import ActivityEvent +from avilla.standard.core.request import RequestEvent if TYPE_CHECKING: from graia.broadcast import Decorator, Dispatchable, Namespace, T_Dispatcher diff --git a/avilla/core/context/_selector.py b/avilla/core/context/_selector.py index d55c64df..363e01b2 100644 --- a/avilla/core/context/_selector.py +++ b/avilla/core/context/_selector.py @@ -1,7 +1,7 @@ from __future__ import annotations -from copy import deepcopy, copy from collections.abc import Mapping +from copy import copy, deepcopy from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar, overload from typing_extensions import Concatenate, ParamSpec, Self, Unpack @@ -10,7 +10,7 @@ from avilla.core.ryanvk import Fn from avilla.core.selector import EMPTY_MAP, Selector from avilla.standard.core.privilege import Privilege -from avilla.standard.core.profile import Nick, Summary, Avatar +from avilla.standard.core.profile import Avatar, Nick, Summary if TYPE_CHECKING: from . import Context diff --git a/avilla/core/event.py b/avilla/core/event.py index a67ea0d4..c36b87f9 100644 --- a/avilla/core/event.py +++ b/avilla/core/event.py @@ -7,11 +7,10 @@ from graia.broadcast.entities.dispatcher import BaseDispatcher from graia.broadcast.entities.event import Dispatchable -from graia.broadcast.entities.signatures import Force from typing_extensions import Unpack from avilla.core.account import BaseAccount -from avilla.core.metadata import FieldReference, Metadata, MetadataRoute +from avilla.core.metadata import Metadata, MetadataRoute from avilla.core.selector import Selector from ._runtime import cx_context diff --git a/avilla/core/metadata.py b/avilla/core/metadata.py index 83edefaf..704da441 100644 --- a/avilla/core/metadata.py +++ b/avilla/core/metadata.py @@ -2,7 +2,7 @@ from contextvars import ContextVar from dataclasses import dataclass, field -from typing import Any, Generic, TypeVar, Union, overload, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Generic, TypeVar, Union, overload from weakref import WeakKeyDictionary from typing_extensions import Self, TypeVarTuple, Unpack @@ -66,10 +66,13 @@ def __init_subclass__(cls) -> None: super().__init_subclass__() if TYPE_CHECKING: + @classmethod def inh(cls: type[_MetadataT1]) -> _MetadataT1: ... + else: + @classmethod def inh(cls: type[_MetadataT1]) -> FieldReference[_MetadataT1]: return FieldReference(cls) @@ -134,10 +137,13 @@ def clear_params(self) -> None: cell.clear_params() if TYPE_CHECKING: + @property def inh(self: MetadataRoute[Unpack[tuple[Any, ...]], _MetadataT1]) -> _MetadataT1: ... + else: + @property def inh(self: MetadataRoute[Unpack[tuple[Any, ...]], _MetadataT1]) -> RouteFieldReference[_MetadataT1]: return RouteFieldReference(self) @@ -166,7 +172,9 @@ def __getattr__(self, item: str) -> Self: def __call__(self, *args: Any, **kwargs: Any) -> Self: prev = self.__steps[-1] - self.__steps[-1] = f"{prev}({', '.join(repr(arg) for arg in args)}, {', '.join(f'{key}={repr(value)}' for key, value in kwargs.items())})" + self.__steps[ + -1 + ] = f"{prev}({', '.join(repr(arg) for arg in args)}, {', '.join(f'{key}={repr(value)}' for key, value in kwargs.items())})" return self def __getitem__(self, item: Any) -> Self: @@ -195,7 +203,9 @@ def __getattr__(self, item: str) -> Self: def __call__(self, *args: Any, **kwargs: Any) -> Self: prev = self.__steps[-1] - self.__steps[-1] = f"{prev}({', '.join(repr(arg) for arg in args)}, {', '.join(f'{key}={repr(value)}' for key, value in kwargs.items())})" + self.__steps[ + -1 + ] = f"{prev}({', '.join(repr(arg) for arg in args)}, {', '.join(f'{key}={repr(value)}' for key, value in kwargs.items())})" return self def __getitem__(self, item: Any) -> Self: diff --git a/avilla/core/selector.py b/avilla/core/selector.py index 327edd13..14ba3d54 100644 --- a/avilla/core/selector.py +++ b/avilla/core/selector.py @@ -1,8 +1,8 @@ from __future__ import annotations import re -from copy import deepcopy from collections.abc import Callable, Mapping +from copy import deepcopy from dataclasses import dataclass from itertools import filterfalse from types import MappingProxyType diff --git a/avilla/core/tools/filter.py b/avilla/core/tools/filter.py index 78266edc..ec996bd9 100644 --- a/avilla/core/tools/filter.py +++ b/avilla/core/tools/filter.py @@ -7,7 +7,7 @@ from typing import Any, Generic, Protocol, TypeVar from graia.broadcast import BaseDispatcher, DispatcherInterface, ExecutionStop -from typing_extensions import ParamSpec, Self +from typing_extensions import ParamSpec from avilla.core.account import BaseAccount from avilla.core.context import Context diff --git a/avilla/elizabeth/perform/action/contact.py b/avilla/elizabeth/perform/action/contact.py index 6b582c41..dcc9c49c 100644 --- a/avilla/elizabeth/perform/action/contact.py +++ b/avilla/elizabeth/perform/action/contact.py @@ -4,7 +4,7 @@ from avilla.core.ryanvk.collector.account import AccountCollector from avilla.core.selector import Selector -from avilla.standard.core.profile import Nick, Summary, Avatar +from avilla.standard.core.profile import Avatar, Nick, Summary if TYPE_CHECKING: from ...account import ElizabethAccount # noqa diff --git a/avilla/elizabeth/perform/action/friend.py b/avilla/elizabeth/perform/action/friend.py index 7e7866f3..454282e9 100644 --- a/avilla/elizabeth/perform/action/friend.py +++ b/avilla/elizabeth/perform/action/friend.py @@ -6,7 +6,7 @@ from avilla.core.ryanvk.collector.account import AccountCollector from avilla.core.selector import Selector -from avilla.standard.core.profile import Nick, Summary, Avatar +from avilla.standard.core.profile import Avatar, Nick, Summary from avilla.standard.core.relation.capability import RelationshipTerminate if TYPE_CHECKING: diff --git a/avilla/elizabeth/perform/action/group.py b/avilla/elizabeth/perform/action/group.py index b4e5e77e..aadd62df 100644 --- a/avilla/elizabeth/perform/action/group.py +++ b/avilla/elizabeth/perform/action/group.py @@ -9,7 +9,7 @@ from avilla.core.selector import Selector from avilla.elizabeth.const import PRIVILEGE_LEVEL from avilla.standard.core.privilege import MuteAllCapability, Privilege -from avilla.standard.core.profile import Summary, SummaryCapability, Avatar, Nick +from avilla.standard.core.profile import Avatar, Nick, Summary, SummaryCapability from avilla.standard.core.relation import SceneCapability if TYPE_CHECKING: diff --git a/avilla/elizabeth/perform/action/member.py b/avilla/elizabeth/perform/action/member.py index 91408dab..b3a8a99b 100644 --- a/avilla/elizabeth/perform/action/member.py +++ b/avilla/elizabeth/perform/action/member.py @@ -15,7 +15,7 @@ Privilege, PrivilegeCapability, ) -from avilla.standard.core.profile import Nick, NickCapability, Summary, Avatar +from avilla.standard.core.profile import Avatar, Nick, NickCapability, Summary from avilla.standard.core.relation import SceneCapability if TYPE_CHECKING: diff --git a/avilla/elizabeth/perform/event/friend.py b/avilla/elizabeth/perform/event/friend.py index 6f5f540c..0cd7d84b 100644 --- a/avilla/elizabeth/perform/event/friend.py +++ b/avilla/elizabeth/perform/event/friend.py @@ -36,11 +36,7 @@ async def friend_input_status_changed(self, raw_event: dict): context, friend, InputtingStatus, - { - InputtingStatus.inh().value: ModifyDetail( - "update", raw_event["inputting"], not raw_event["inputting"] - ) - }, + {InputtingStatus.inh().value: ModifyDetail("update", raw_event["inputting"], not raw_event["inputting"])}, operator=friend, scene=friend, ) diff --git a/avilla/elizabeth/perform/event/group.py b/avilla/elizabeth/perform/event/group.py index 8980c2af..1bb60e20 100644 --- a/avilla/elizabeth/perform/event/group.py +++ b/avilla/elizabeth/perform/event/group.py @@ -113,9 +113,7 @@ async def bot_mute(self, raw_event: dict): MuteInfo, { MuteInfo.inh().muted: ModifyDetail("update", True, False), - MuteInfo.inh().duration: ModifyDetail( - "set", timedelta(seconds=raw_event["durationSeconds"]), None - ), + MuteInfo.inh().duration: ModifyDetail("set", timedelta(seconds=raw_event["durationSeconds"]), None), }, operator=operator, scene=group, @@ -310,9 +308,7 @@ async def group_entrance_announcement_change(self, raw_event: dict): group, Announcement, { - Announcement.inh().content: ModifyDetail( - "update", raw_event["current"], raw_event["origin"] - ), + Announcement.inh().content: ModifyDetail("update", raw_event["current"], raw_event["origin"]), }, operator=operator or group.member(account_route["account"]), # bot self if no operator scene=group, diff --git a/avilla/elizabeth/perform/event/member.py b/avilla/elizabeth/perform/event/member.py index 96435112..a3efe2cd 100644 --- a/avilla/elizabeth/perform/event/member.py +++ b/avilla/elizabeth/perform/event/member.py @@ -76,9 +76,7 @@ async def member_card_change(self, raw_event: dict): context, member, Nick, - { - Nick.inh().nickname: ModifyDetail("update", raw_event["current"], raw_event["origin"]) - }, + {Nick.inh().nickname: ModifyDetail("update", raw_event["current"], raw_event["origin"])}, operator=operator or group.member(account_route["account"]), scene=group, ) @@ -279,9 +277,7 @@ async def member_mute(self, raw_event: dict): MuteInfo, { MuteInfo.inh().muted: ModifyDetail("update", True, False), - MuteInfo.inh().duration: ModifyDetail( - "set", timedelta(seconds=raw_event["durationSeconds"]), None - ), + MuteInfo.inh().duration: ModifyDetail("set", timedelta(seconds=raw_event["durationSeconds"]), None), }, operator=operator or group.member(account_route["account"]), scene=group, diff --git a/avilla/onebot/v11/perform/event/notice.py b/avilla/onebot/v11/perform/event/notice.py index 1d38802a..70f58f9f 100644 --- a/avilla/onebot/v11/perform/event/notice.py +++ b/avilla/onebot/v11/perform/event/notice.py @@ -7,11 +7,11 @@ from avilla.core.context import Context from avilla.core.event import ( + DirectSessionCreated, MetadataModified, ModifyDetail, SceneCreated, SceneDestroyed, - DirectSessionCreated, ) from avilla.core.selector import Selector from avilla.onebot.v11.capability import OneBot11Capability diff --git a/avilla/qqapi/perform/action/guild_member.py b/avilla/qqapi/perform/action/guild_member.py index dbbec7bc..77826acb 100644 --- a/avilla/qqapi/perform/action/guild_member.py +++ b/avilla/qqapi/perform/action/guild_member.py @@ -8,7 +8,7 @@ from avilla.core.selector import Selector from avilla.qqapi.const import PRIVILEGE_TRANS from avilla.standard.core.privilege import MuteCapability, MuteInfo, Privilege -from avilla.standard.core.profile import Nick, Summary, Avatar +from avilla.standard.core.profile import Avatar, Nick, Summary from avilla.standard.core.relation import SceneCapability if TYPE_CHECKING: diff --git a/avilla/qqapi/perform/action/message.py b/avilla/qqapi/perform/action/message.py index 3dbca1d7..b52fa4af 100644 --- a/avilla/qqapi/perform/action/message.py +++ b/avilla/qqapi/perform/action/message.py @@ -7,7 +7,7 @@ from graia.amnesia.message import MessageChain from loguru import logger -from avilla.core import CoreCapability, Message, Context +from avilla.core import Context, CoreCapability, Message from avilla.core.exceptions import ActionFailed from avilla.core.ryanvk.collector.account import AccountCollector from avilla.core.selector import Selector @@ -287,7 +287,7 @@ async def create_dms_user(self, target: Selector) -> Selector: ) context = self.context if context: - context.cache[f"{context.scene.display_without_land}#dms"] = result['guild_id'] + context.cache[f"{context.scene.display_without_land}#dms"] = result["guild_id"] return target.into(f"land.guild({result['guild_id']})") @QQAPICapability.create_dms.collect(m, target="land.guild.member") @@ -303,7 +303,7 @@ async def create_dms_member(self, target: Selector) -> Selector: ) context = self.context if context: - context.cache[f"{context.scene.display_without_land}#dms"] = result['guild_id'] + context.cache[f"{context.scene.display_without_land}#dms"] = result["guild_id"] return target.into(f"land.guild({result['guild_id']})") @MessageSend.send.collect(m, target="land.guild.user") @@ -317,7 +317,7 @@ async def send_direct_msg( context = self.context msg = await QQAPICapability(self.account.staff).serialize(message) if not context or not (send_guild_id := context.cache.get(f"{context.scene.display_without_land}#dms")): - send_guild_id = (await self.create_dms_user(target)).pattern["guild"] + send_guild_id = (await self.create_dms_user(target)).pattern["guild"] if context and (event_id := context.cache.get(target.display_without_land)): msg["msg_id"] = event_id if reply: diff --git a/avilla/qqapi/perform/event/message.py b/avilla/qqapi/perform/event/message.py index acfccd57..4e6a1a34 100644 --- a/avilla/qqapi/perform/event/message.py +++ b/avilla/qqapi/perform/event/message.py @@ -12,7 +12,7 @@ from avilla.qqapi.collector.connection import ConnectionCollector from avilla.qqapi.element import Reference from avilla.standard.core.message import MessageReceived, MessageRevoked -from avilla.standard.core.profile import Nick, Summary, Avatar +from avilla.standard.core.profile import Avatar, Nick, Summary class QQAPIEventMessagePerform((m := ConnectionCollector())._): @@ -65,7 +65,7 @@ async def at_message(self, event_type: str, raw_event: dict): raw_event["author"]["username"], raw_event["member"].get("nick", raw_event["author"]["username"]), None ), Summary(raw_event["author"]["username"], "channel member"), - Avatar(raw_event["author"]["avatar"]) + Avatar(raw_event["author"]["avatar"]), ) context._collect_metadatas(msg.to_selector(), msg) return MessageReceived(context, msg) @@ -157,7 +157,7 @@ async def direct_message(self, event_type: ..., raw_event: dict): raw_event["author"]["username"], raw_event["member"].get("nick", raw_event["author"]["username"]), None ), Summary(raw_event["author"]["username"], "channel member"), - Avatar(raw_event["author"]["avatar"]) + Avatar(raw_event["author"]["avatar"]), ) context._collect_metadatas(msg.to_selector(), msg) return MessageReceived(context, msg) @@ -291,7 +291,7 @@ async def public_message_delete(self, event_type: ..., raw_event: dict): author, Nick(raw_event["message"]["author"]["username"], raw_event["message"]["author"]["username"], None), Summary(raw_event["message"]["author"]["username"], "channel member"), - Avatar(raw_event["message"]["author"]["avatar"]) + Avatar(raw_event["message"]["author"]["avatar"]), ) return MessageRevoked(context, author.message(raw_event["message"]["id"]), operator) @@ -317,6 +317,6 @@ async def direct_message_delete(self, event_type: ..., raw_event: dict): author, Nick(raw_event["message"]["author"]["username"], raw_event["message"]["author"]["username"], None), Summary(raw_event["message"]["author"]["username"], "channel member"), - Avatar(raw_event["message"]["author"]["avatar"]) + Avatar(raw_event["message"]["author"]["avatar"]), ) return MessageRevoked(context, author.message(raw_event["message"]["id"]), operator) diff --git a/avilla/standard/core/profile/__init__.py b/avilla/standard/core/profile/__init__.py index b101bd12..9365d17f 100644 --- a/avilla/standard/core/profile/__init__.py +++ b/avilla/standard/core/profile/__init__.py @@ -1,5 +1,5 @@ from .capability import NickCapability as NickCapability from .capability import SummaryCapability as SummaryCapability +from .metadata import Avatar as Avatar from .metadata import Nick as Nick from .metadata import Summary as Summary -from .metadata import Avatar as Avatar diff --git a/avilla/twilight/twilight.py b/avilla/twilight/twilight.py index 08ec48d7..dca0ae62 100644 --- a/avilla/twilight/twilight.py +++ b/avilla/twilight/twilight.py @@ -27,16 +27,16 @@ overload, ) -from typing_extensions import Self - -from avilla.core.elements import Element -from avilla.core.utilles import identity from graia.amnesia.message.chain import MessageChain from graia.broadcast.builtin.derive import Derive, DeriveDispatcher from graia.broadcast.entities.decorator import Decorator from graia.broadcast.entities.dispatcher import BaseDispatcher from graia.broadcast.interfaces.decorator import DecoratorInterface from graia.broadcast.interfaces.dispatcher import DispatcherInterface +from typing_extensions import Self + +from avilla.core.elements import Element +from avilla.core.utilles import identity from .base import ChainDecorator from .commander_util import ParamToken, TextToken, tokenize