mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-14 07:56:49 +00:00
🎨 format code using black and isort
This commit is contained in:
@ -22,9 +22,10 @@ class UserPermission(str, Enum):
|
||||
* ``ADMINISTRATOR``: 群管理
|
||||
* ``MEMBER``: 普通群成员
|
||||
"""
|
||||
OWNER = 'OWNER'
|
||||
ADMINISTRATOR = 'ADMINISTRATOR'
|
||||
MEMBER = 'MEMBER'
|
||||
|
||||
OWNER = "OWNER"
|
||||
ADMINISTRATOR = "ADMINISTRATOR"
|
||||
MEMBER = "MEMBER"
|
||||
|
||||
|
||||
class NudgeSubjectKind(str, Enum):
|
||||
@ -36,8 +37,9 @@ class NudgeSubjectKind(str, Enum):
|
||||
* ``Group``: 群
|
||||
* ``Friend``: 好友
|
||||
"""
|
||||
Group = 'Group'
|
||||
Friend = 'Friend'
|
||||
|
||||
Group = "Group"
|
||||
Friend = "Friend"
|
||||
|
||||
|
||||
class GroupInfo(BaseModel):
|
||||
@ -48,7 +50,7 @@ class GroupInfo(BaseModel):
|
||||
|
||||
class GroupChatInfo(BaseModel):
|
||||
id: int
|
||||
name: str = Field(alias='memberName')
|
||||
name: str = Field(alias="memberName")
|
||||
permission: UserPermission
|
||||
group: GroupInfo
|
||||
|
||||
@ -71,6 +73,7 @@ class Event(BaseEvent):
|
||||
.. _mirai-api-http 事件类型:
|
||||
https://github.com/project-mirai/mirai-api-http/blob/master/docs/EventType.md
|
||||
"""
|
||||
|
||||
self_id: int
|
||||
type: str
|
||||
|
||||
@ -79,11 +82,12 @@ class Event(BaseEvent):
|
||||
"""
|
||||
此事件类的工厂函数, 能够通过事件数据选择合适的子类进行序列化
|
||||
"""
|
||||
type = data['type']
|
||||
type = data["type"]
|
||||
|
||||
def all_subclasses(cls: Type[Event]):
|
||||
return set(cls.__subclasses__()).union(
|
||||
[s for c in cls.__subclasses__() for s in all_subclasses(c)])
|
||||
[s for c in cls.__subclasses__() for s in all_subclasses(c)]
|
||||
)
|
||||
|
||||
event_class: Optional[Type[Event]] = None
|
||||
for subclass in all_subclasses(cls):
|
||||
@ -99,23 +103,25 @@ class Event(BaseEvent):
|
||||
return event_class.parse_obj(data)
|
||||
except ValidationError as e:
|
||||
logger.info(
|
||||
f'Failed to parse {data} to class {event_class.__name__}: '
|
||||
f'{e.errors()!r}. Fallback to parent class.')
|
||||
f"Failed to parse {data} to class {event_class.__name__}: "
|
||||
f"{e.errors()!r}. Fallback to parent class."
|
||||
)
|
||||
event_class = event_class.__base__ # type: ignore
|
||||
|
||||
raise ValueError(f'Failed to serialize {data}.')
|
||||
raise ValueError(f"Failed to serialize {data}.")
|
||||
|
||||
@overrides(BaseEvent)
|
||||
def get_type(self) -> Literal["message", "notice", "request", "meta_event"]:
|
||||
from . import meta, notice, message, request
|
||||
|
||||
if isinstance(self, message.MessageEvent):
|
||||
return 'message'
|
||||
return "message"
|
||||
elif isinstance(self, notice.NoticeEvent):
|
||||
return 'notice'
|
||||
return "notice"
|
||||
elif isinstance(self, request.RequestEvent):
|
||||
return 'request'
|
||||
return "request"
|
||||
else:
|
||||
return 'meta_event'
|
||||
return "meta_event"
|
||||
|
||||
@overrides(BaseEvent)
|
||||
def get_event_name(self) -> str:
|
||||
|
Reference in New Issue
Block a user