diff --git a/nonebot/adapters/satori/event.py b/nonebot/adapters/satori/event.py index 754dd4f..d7772bd 100644 --- a/nonebot/adapters/satori/event.py +++ b/nonebot/adapters/satori/event.py @@ -320,7 +320,7 @@ class PrivateMessageCreatedEvent(MessageCreatedEvent, PrivateMessageEvent): def get_event_description(self) -> str: return escape_tag( f"Message {self.msg_id} from " - f"{self.user.name}({self.channel.id}): {self.get_message()!r}" + f"{self.user.name or ''}({self.channel.id}): {self.get_message()!r}" ) @@ -330,7 +330,7 @@ def get_event_description(self) -> str: return escape_tag( f"Message {self.msg_id} from " f"{self.user.name or ''}({self.channel.id})" - f"@[{self.channel.name}:{self.guild.id}/{self.channel.id}]" + f"@[{self.channel.name or ''}:{self.guild.id}/{self.channel.id}]" f": {self.get_message()!r}" ) @@ -340,7 +340,7 @@ class PrivateMessageDeletedEvent(MessageDeletedEvent, PrivateMessageEvent): def get_event_description(self) -> str: return escape_tag( f"Message {self.msg_id} from " - f"{self.user.name}({self.channel.id}) deleted" + f"{self.user.name or ''}({self.channel.id}) deleted" ) @@ -350,7 +350,7 @@ def get_event_description(self) -> str: return escape_tag( f"Message {self.msg_id} from " f"{self.user.name or ''}({self.channel.id})" - f"@[{self.channel.name}:{self.guild.id}/{self.channel.id}] deleted" + f"@[{self.channel.name or ''}:{self.guild.id}/{self.channel.id}] deleted" ) @@ -359,7 +359,7 @@ class PrivateMessageUpdatedEvent(MessageUpdatedEvent, PrivateMessageEvent): def get_event_description(self) -> str: return escape_tag( f"Message {self.msg_id} from " - f"{self.user.name}({self.channel.id}) updated" + f"{self.user.name or ''}({self.channel.id}) updated" f": {self.get_message()!r}" ) @@ -370,7 +370,7 @@ def get_event_description(self) -> str: return escape_tag( f"Message {self.msg_id} from " f"{self.user.name or ''}({self.channel.id})" - f"@[{self.channel.name}:{self.guild.id}/{self.channel.id}] updated" + f"@[{self.channel.name or ''}:{self.guild.id}/{self.channel.id}] updated" f": {self.get_message()!r}" ) diff --git a/nonebot/adapters/satori/models.py b/nonebot/adapters/satori/models.py index 755cf02..37409c9 100644 --- a/nonebot/adapters/satori/models.py +++ b/nonebot/adapters/satori/models.py @@ -16,7 +16,7 @@ class ChannelType(IntEnum): class Channel(BaseModel, extra=Extra.allow): id: str - name: str + name: Optional[str] = None type: ChannelType parent_id: Optional[str] = None @@ -48,8 +48,8 @@ def parse_joined_at(cls, v): return v try: timestamp = int(v) - except ValueError: - raise ValueError(f"invalid timestamp: {v}") + except ValueError as e: + raise ValueError(f"invalid timestamp: {v}") from e return datetime.fromtimestamp(timestamp / 1000) @@ -164,8 +164,8 @@ def parse_created_at(cls, v): return v try: timestamp = int(v) - except ValueError: - raise ValueError(f"invalid timestamp: {v}") + except ValueError as e: + raise ValueError(f"invalid timestamp: {v}") from e return datetime.fromtimestamp(timestamp / 1000) @validator("updated_at", pre=True) @@ -176,8 +176,8 @@ def parse_updated_at(cls, v): return v try: timestamp = int(v) - except ValueError: - raise ValueError(f"invalid timestamp: {v}") + except ValueError as e: + raise ValueError(f"invalid timestamp: {v}") from e return datetime.fromtimestamp(timestamp / 1000) diff --git a/pyproject.toml b/pyproject.toml index ec2687a..84bc51e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nonebot-adapter-satori" -version = "0.1.2" +version = "0.1.3" description = "Satori Protocol Adapter for Nonebot2" authors = [ {name = "RF-Tar-Railt",email = "rf_tar_railt@qq.com"},