mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-27 18:45:05 +08:00
🐛 Fix: Message.__contains__()
未考虑 bool(MessageSegment)
存在 False 情况导致的异常结果 (#2572)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
This commit is contained in:
parent
ef7782167f
commit
11142253fb
@ -285,7 +285,7 @@ class Message(List[TMS], abc.ABC):
|
||||
消息内是否存在给定消息段或给定类型的消息段
|
||||
"""
|
||||
if isinstance(value, str):
|
||||
return bool(next((seg for seg in self if seg.type == value), None))
|
||||
return next((seg for seg in self if seg.type == value), None) is not None
|
||||
return super().__contains__(value)
|
||||
|
||||
def has(self, value: Union[TMS, str]) -> bool:
|
||||
|
@ -192,6 +192,11 @@ def test_message_contains():
|
||||
assert message.has("foo") is False
|
||||
assert "foo" not in message
|
||||
|
||||
assert not bool(FakeMessageSegment.text(""))
|
||||
msg_with_empty_seg = FakeMessage([FakeMessageSegment.text("")])
|
||||
assert msg_with_empty_seg.has("text") is True
|
||||
assert "text" in msg_with_empty_seg
|
||||
|
||||
|
||||
def test_message_only():
|
||||
message = FakeMessage(
|
||||
|
Loading…
Reference in New Issue
Block a user