mirror of https://github.com/Mai-with-u/MaiBot.git
remove redundant assert
parent
8d93e56336
commit
ce74df51db
|
|
@ -11,13 +11,13 @@ class DatabaseUserInfo(AbstractClassFlag):
|
|||
user_nickname: str = field(default_factory=str)
|
||||
user_cardname: Optional[str] = None
|
||||
|
||||
def __post_init__(self):
|
||||
assert isinstance(self.platform, str), "platform must be a string"
|
||||
assert isinstance(self.user_id, str), "user_id must be a string"
|
||||
assert isinstance(self.user_nickname, str), "user_nickname must be a string"
|
||||
assert isinstance(self.user_cardname, str) or self.user_cardname is None, (
|
||||
"user_cardname must be a string or None"
|
||||
)
|
||||
# def __post_init__(self):
|
||||
# assert isinstance(self.platform, str), "platform must be a string"
|
||||
# assert isinstance(self.user_id, str), "user_id must be a string"
|
||||
# assert isinstance(self.user_nickname, str), "user_nickname must be a string"
|
||||
# assert isinstance(self.user_cardname, str) or self.user_cardname is None, (
|
||||
# "user_cardname must be a string or None"
|
||||
# )
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
@ -26,12 +26,12 @@ class DatabaseGroupInfo(AbstractClassFlag):
|
|||
group_name: str = field(default_factory=str)
|
||||
group_platform: Optional[str] = None
|
||||
|
||||
def __post_init__(self):
|
||||
assert isinstance(self.group_id, str), "group_id must be a string"
|
||||
assert isinstance(self.group_name, str), "group_name must be a string"
|
||||
assert isinstance(self.group_platform, str) or self.group_platform is None, (
|
||||
"group_platform must be a string or None"
|
||||
)
|
||||
# def __post_init__(self):
|
||||
# assert isinstance(self.group_id, str), "group_id must be a string"
|
||||
# assert isinstance(self.group_name, str), "group_name must be a string"
|
||||
# assert isinstance(self.group_platform, str) or self.group_platform is None, (
|
||||
# "group_platform must be a string or None"
|
||||
# )
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
@ -43,23 +43,19 @@ class DatabaseChatInfo(AbstractClassFlag):
|
|||
user_info: DatabaseUserInfo = field(default_factory=DatabaseUserInfo)
|
||||
group_info: Optional[DatabaseGroupInfo] = None
|
||||
|
||||
def __post_init__(self):
|
||||
assert isinstance(self.stream_id, str), "stream_id must be a string"
|
||||
assert isinstance(self.platform, str), "platform must be a string"
|
||||
assert isinstance(self.create_time, float), "create_time must be a float"
|
||||
assert isinstance(self.last_active_time, float), "last_active_time must be a float"
|
||||
assert isinstance(self.user_info, DatabaseUserInfo), "user_info must be a DatabaseUserInfo instance"
|
||||
assert isinstance(self.group_info, DatabaseGroupInfo) or self.group_info is None, (
|
||||
"group_info must be a DatabaseGroupInfo instance or None"
|
||||
)
|
||||
# def __post_init__(self):
|
||||
# assert isinstance(self.stream_id, str), "stream_id must be a string"
|
||||
# assert isinstance(self.platform, str), "platform must be a string"
|
||||
# assert isinstance(self.create_time, float), "create_time must be a float"
|
||||
# assert isinstance(self.last_active_time, float), "last_active_time must be a float"
|
||||
# assert isinstance(self.user_info, DatabaseUserInfo), "user_info must be a DatabaseUserInfo instance"
|
||||
# assert isinstance(self.group_info, DatabaseGroupInfo) or self.group_info is None, (
|
||||
# "group_info must be a DatabaseGroupInfo instance or None"
|
||||
# )
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class DatabaseMessages(AbstractClassFlag):
|
||||
# chat_info: DatabaseChatInfo
|
||||
# user_info: DatabaseUserInfo
|
||||
# group_info: Optional[DatabaseGroupInfo] = None
|
||||
|
||||
message_id: str = field(default_factory=str)
|
||||
time: float = field(default_factory=float)
|
||||
chat_id: str = field(default_factory=str)
|
||||
|
|
@ -70,25 +66,6 @@ class DatabaseMessages(AbstractClassFlag):
|
|||
key_words_lite: Optional[str] = None
|
||||
is_mentioned: Optional[bool] = None
|
||||
|
||||
# 从 chat_info 扁平化而来的字段
|
||||
# chat_info_stream_id: str = field(default_factory=str)
|
||||
# chat_info_platform: str = field(default_factory=str)
|
||||
# chat_info_user_platform: str = field(default_factory=str)
|
||||
# chat_info_user_id: str = field(default_factory=str)
|
||||
# chat_info_user_nickname: str = field(default_factory=str)
|
||||
# chat_info_user_cardname: Optional[str] = None
|
||||
# chat_info_group_platform: Optional[str] = None
|
||||
# chat_info_group_id: Optional[str] = None
|
||||
# chat_info_group_name: Optional[str] = None
|
||||
# chat_info_create_time: float = field(default_factory=float)
|
||||
# chat_info_last_active_time: float = field(default_factory=float)
|
||||
|
||||
# 从顶层 user_info 扁平化而来的字段 (消息发送者信息)
|
||||
# user_platform: str = field(default_factory=str)
|
||||
# user_id: str = field(default_factory=str)
|
||||
# user_nickname: str = field(default_factory=str)
|
||||
# user_cardname: Optional[str] = None
|
||||
|
||||
processed_plain_text: Optional[str] = None # 处理后的纯文本消息
|
||||
display_message: Optional[str] = None # 显示的消息
|
||||
|
||||
|
|
@ -103,29 +80,6 @@ class DatabaseMessages(AbstractClassFlag):
|
|||
|
||||
selected_expressions: Optional[str] = None
|
||||
|
||||
# def __post_init__(self):
|
||||
|
||||
# if self.chat_info_group_id and self.chat_info_group_name:
|
||||
# self.group_info = DatabaseGroupInfo(
|
||||
# group_id=self.chat_info_group_id,
|
||||
# group_name=self.chat_info_group_name,
|
||||
# group_platform=self.chat_info_group_platform,
|
||||
# )
|
||||
|
||||
# chat_user_info = DatabaseUserInfo(
|
||||
# user_id=self.chat_info_user_id,
|
||||
# user_nickname=self.chat_info_user_nickname,
|
||||
# user_cardname=self.chat_info_user_cardname,
|
||||
# platform=self.chat_info_user_platform,
|
||||
# )
|
||||
# self.chat_info = DatabaseChatInfo(
|
||||
# stream_id=self.chat_info_stream_id,
|
||||
# platform=self.chat_info_platform,
|
||||
# create_time=self.chat_info_create_time,
|
||||
# last_active_time=self.chat_info_last_active_time,
|
||||
# user_info=chat_user_info,
|
||||
# group_info=self.group_info,
|
||||
# )
|
||||
def __init__(self, **kwargs: Any):
|
||||
defined = {f.name: f for f in fields(self.__class__)}
|
||||
for name, f in defined.items():
|
||||
|
|
@ -135,6 +89,7 @@ class DatabaseMessages(AbstractClassFlag):
|
|||
setattr(self, name, f.default)
|
||||
else:
|
||||
raise TypeError(f"缺失必需字段: {name}")
|
||||
|
||||
self.group_info = None
|
||||
self.user_info = DatabaseUserInfo(
|
||||
user_id=kwargs.get("user_id"), # type: ignore
|
||||
|
|
@ -164,3 +119,12 @@ class DatabaseMessages(AbstractClassFlag):
|
|||
user_info=chat_user_info,
|
||||
group_info=self.group_info,
|
||||
)
|
||||
|
||||
# def __post_init__(self):
|
||||
# assert isinstance(self.message_id, str), "message_id must be a string"
|
||||
# assert isinstance(self.time, float), "time must be a float"
|
||||
# assert isinstance(self.chat_id, str), "chat_id must be a string"
|
||||
# assert isinstance(self.reply_to, str) or self.reply_to is None, "reply_to must be a string or None"
|
||||
# assert isinstance(self.interest_value, float) or self.interest_value is None, (
|
||||
# "interest_value must be a float or None"
|
||||
# )
|
||||
|
|
|
|||
Loading…
Reference in New Issue