Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions astrbot/core/astr_agent_tool_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ async def call_local_llm_tool(
# 这里逐步执行异步生成器, 对于每个 yield 返回的 ret, 执行下面的代码
# 返回值只能是 MessageEventResult 或者 None(无返回值)
_has_yielded = True
if isinstance(ret, (MessageEventResult, CommandResult)):
if isinstance(ret, MessageEventResult | CommandResult):
# 如果返回值是 MessageEventResult, 设置结果并继续
event.set_result(ret)
yield
Expand All @@ -273,7 +273,7 @@ async def call_local_llm_tool(
elif inspect.iscoroutine(ready_to_call):
# 如果只是一个协程, 直接执行
ret = await ready_to_call
if isinstance(ret, (MessageEventResult, CommandResult)):
if isinstance(ret, MessageEventResult | CommandResult):
event.set_result(ret)
yield
else:
Expand Down
1 change: 1 addition & 0 deletions astrbot/core/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -3217,6 +3217,7 @@ class ChatProviderTemplate(TypedDict):
"string": "",
"text": "",
"list": [],
"file": [],
"object": {},
"template_list": [],
}
4 changes: 2 additions & 2 deletions astrbot/core/message/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def __init__(self, content: list[BaseMessageComponent], **_):
async def to_dict(self):
data_content = []
for comp in self.content:
if isinstance(comp, (Image, Record)):
if isinstance(comp, Image | Record):
# For Image and Record segments, we convert them to base64
bs64 = await comp.convert_to_base64()
data_content.append(
Expand All @@ -584,7 +584,7 @@ async def to_dict(self):
# For File segments, we need to handle the file differently
d = await comp.to_dict()
data_content.append(d)
elif isinstance(comp, (Node, Nodes)):
elif isinstance(comp, Node | Nodes):
# For Node segments, we recursively convert them to dict
d = await comp.to_dict()
data_content.append(d)
Expand Down
4 changes: 2 additions & 2 deletions astrbot/core/pipeline/context_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def call_handler(
# 这里逐步执行异步生成器, 对于每个 yield 返回的 ret, 执行下面的代码
# 返回值只能是 MessageEventResult 或者 None(无返回值)
_has_yielded = True
if isinstance(ret, (MessageEventResult, CommandResult)):
if isinstance(ret, MessageEventResult | CommandResult):
# 如果返回值是 MessageEventResult, 设置结果并继续
event.set_result(ret)
yield
Expand All @@ -65,7 +65,7 @@ async def call_handler(
elif inspect.iscoroutine(ready_to_call):
# 如果只是一个协程, 直接执行
ret = await ready_to_call
if isinstance(ret, (MessageEventResult, CommandResult)):
if isinstance(ret, MessageEventResult | CommandResult):
event.set_result(ret)
yield
else:
Expand Down
2 changes: 1 addition & 1 deletion astrbot/core/pipeline/preprocess_stage/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def process(
message_chain = event.get_messages()

for idx, component in enumerate(message_chain):
if isinstance(component, (Record, Image)) and component.url:
if isinstance(component, Record | Image) and component.url:
for mapping in mappings:
from_, to_ = mapping.split(":")
from_ = from_.removesuffix("/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ async def process(
has_valid_message = bool(event.message_str and event.message_str.strip())
# 检查是否有图片或其他媒体内容
has_media_content = any(
isinstance(comp, (Image, File)) for comp in event.message_obj.message
isinstance(comp, Image | File) for comp in event.message_obj.message
)

if (
Expand Down
2 changes: 1 addition & 1 deletion astrbot/core/pipeline/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def execute(self, event: AstrMessageEvent):
await self._process_stages(event)

# 如果没有发送操作, 则发送一个空消息, 以便于后续的处理
if isinstance(event, (WebChatMessageEvent, WecomAIBotMessageEvent)):
if isinstance(event, WebChatMessageEvent | WecomAIBotMessageEvent):
await event.send(None)

logger.debug("pipeline 执行完毕。")
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
@staticmethod
async def _from_segment_to_dict(segment: BaseMessageComponent) -> dict:
"""修复部分字段"""
if isinstance(segment, (Image, Record)):
if isinstance(segment, Image | Record):
# For Image and Record segments, we convert them to base64
bs64 = await segment.convert_to_base64()
return {
Expand Down Expand Up @@ -110,7 +110,7 @@ async def send_message(
"""
# 转发消息、文件消息不能和普通消息混在一起发送
send_one_by_one = any(
isinstance(seg, (Node, Nodes, File)) for seg in message_chain.chain
isinstance(seg, Node | Nodes | File) for seg in message_chain.chain
)
if not send_one_by_one:
ret = await cls._parse_onebot_json(message_chain)
Expand All @@ -119,7 +119,7 @@ async def send_message(
await cls._dispatch_send(bot, event, is_group, session_id, ret)
return
for seg in message_chain.chain:
if isinstance(seg, (Node, Nodes)):
if isinstance(seg, Node | Nodes):
# 合并转发消息
if isinstance(seg, Node):
nodes = Nodes([seg])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,10 @@ async def _post_send(self, stream: dict | None = None):

if not isinstance(
source,
(
botpy.message.Message,
botpy.message.GroupMessage,
botpy.message.DirectMessage,
botpy.message.C2CMessage,
),
botpy.message.Message
| botpy.message.GroupMessage
| botpy.message.DirectMessage
| botpy.message.C2CMessage,
):
logger.warning(f"[QQOfficial] 不支持的消息源类型: {type(source)}")
return None
Expand All @@ -120,7 +118,7 @@ async def _post_send(self, stream: dict | None = None):
"msg_id": self.message_obj.message_id,
}

if not isinstance(source, (botpy.message.Message, botpy.message.DirectMessage)):
if not isinstance(source, botpy.message.Message | botpy.message.DirectMessage):
payload["msg_seq"] = random.randint(1, 10000)

ret = None
Expand Down
2 changes: 1 addition & 1 deletion astrbot/core/star/command_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def _locate_primary_filter(
handler: StarHandlerMetadata,
) -> CommandFilter | CommandGroupFilter | None:
for filter_ref in handler.event_filters:
if isinstance(filter_ref, (CommandFilter, CommandGroupFilter)):
if isinstance(filter_ref, CommandFilter | CommandGroupFilter):
return filter_ref
return None

Expand Down
2 changes: 1 addition & 1 deletion astrbot/core/star/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def put_config(namespace: str, name: str, key: str, value, description: str):
raise ValueError("namespace 不能以 internal_ 开头。")
if not isinstance(key, str):
raise ValueError("key 只支持 str 类型。")
if not isinstance(value, (str, int, float, bool, list)):
if not isinstance(value, str | int | float | bool | list):
raise ValueError("value 只支持 str, int, float, bool, list 类型。")

config_dir = os.path.join(get_astrbot_data_path(), "config")
Expand Down
2 changes: 1 addition & 1 deletion astrbot/core/star/filter/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def validate_and_convert_params(
# 没有 GreedyStr 的情况
if i >= len(params):
if (
isinstance(param_type_or_default_val, (type, types.UnionType))
isinstance(param_type_or_default_val, type | types.UnionType)
or typing.get_origin(param_type_or_default_val) is typing.Union
or param_type_or_default_val is inspect.Parameter.empty
):
Expand Down
4 changes: 2 additions & 2 deletions astrbot/core/star/filter/custom_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __and__(self, other):
class CustomFilterOr(CustomFilter):
def __init__(self, filter1: CustomFilter, filter2: CustomFilter):
super().__init__()
if not isinstance(filter1, (CustomFilter, CustomFilterAnd, CustomFilterOr)):
if not isinstance(filter1, CustomFilter | CustomFilterAnd | CustomFilterOr):
raise ValueError(
"CustomFilter lass can only operate with other CustomFilter.",
)
Expand All @@ -51,7 +51,7 @@ def filter(self, event: AstrMessageEvent, cfg: AstrBotConfig) -> bool:
class CustomFilterAnd(CustomFilter):
def __init__(self, filter1: CustomFilter, filter2: CustomFilter):
super().__init__()
if not isinstance(filter1, (CustomFilter, CustomFilterAnd, CustomFilterOr)):
if not isinstance(filter1, CustomFilter | CustomFilterAnd | CustomFilterOr):
raise ValueError(
"CustomFilter lass can only operate with other CustomFilter.",
)
Expand Down
2 changes: 1 addition & 1 deletion astrbot/core/star/register/star_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def register_custom_filter(custom_type_filter, *args, **kwargs):
if args:
raise_error = args[0]

if not isinstance(custom_filter, (CustomFilterAnd, CustomFilterOr)):
if not isinstance(custom_filter, CustomFilterAnd | CustomFilterOr):
custom_filter = custom_filter(raise_error)

def decorator(awaitable):
Expand Down
Loading