Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Jan 13, 2024
1 parent 554444e commit 966bd77
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 48 deletions.
4 changes: 2 additions & 2 deletions avilla/core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions avilla/core/context/_selector.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions avilla/core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions avilla/core/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion avilla/core/selector.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion avilla/core/tools/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion avilla/elizabeth/perform/action/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion avilla/elizabeth/perform/action/friend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion avilla/elizabeth/perform/action/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion avilla/elizabeth/perform/action/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 1 addition & 5 deletions avilla/elizabeth/perform/event/friend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
8 changes: 2 additions & 6 deletions avilla/elizabeth/perform/event/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions avilla/elizabeth/perform/event/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion avilla/onebot/v11/perform/event/notice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion avilla/qqapi/perform/action/guild_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions avilla/qqapi/perform/action/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions avilla/qqapi/perform/event/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())._):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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)
2 changes: 1 addition & 1 deletion avilla/standard/core/profile/__init__.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions avilla/twilight/twilight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 966bd77

Please sign in to comment.