MCPcopy
hub / github.com/nonebot/nonebot2 / only

Method only

nonebot/internal/adapter/message.py:345–356  ·  view source on GitHub ↗

检查消息中是否仅包含指定消息段 参数: value: 指定消息段或消息段类型 返回: 是否仅包含指定消息段

(self, value: TMS | str)

Source from the content-addressed store, hash-verified

343 return len(self[value]) if isinstance(value, str) else super().count(value)
344
345 def only(self, value: TMS | str) -> bool:
346 """检查消息中是否仅包含指定消息段
347
348 参数:
349 value: 指定消息段或消息段类型
350
351 返回:
352 是否仅包含指定消息段
353 """
354 if isinstance(value, str):
355 return all(seg.type == value for seg in self)
356 return all(seg == value for seg in self)
357
358 def append( # pyright: ignore[reportIncompatibleMethodOverride]
359 self, obj: str | TMS

Callers 1

test_message_onlyFunction · 0.80

Calls

no outgoing calls

Tested by 1

test_message_onlyFunction · 0.64