Skip to content

[Feature] 为 event.send() 增加可选的消息装饰开关 #9038

Description

@QingFeng-awa

Description / 描述

希望能为 AstrMessageEvent.send() 方法新增一个可选的参数 decoration,用于控制是否为通过该方法发送的消息添加以下消息装饰:

# 触发转发消息
if event.get_platform_name() == "aiocqhttp":
word_cnt = 0
for comp in result.chain:
if isinstance(comp, Plain):
word_cnt += len(comp.text)
if word_cnt > self.forward_threshold:
node = Node(
uin=event.get_self_id(),
name="AstrBot",
content=[*result.chain],
)
result.chain = [node]
# at 回复 / 引用回复仅适用于纯文本或图文消息
can_decorate = all(
isinstance(item, (Plain, Image)) for item in result.chain
)
if can_decorate:
# at 回复
if (
self.reply_with_mention
and event.get_message_type() != MessageType.FRIEND_MESSAGE
):
result.chain.insert(
0,
At(qq=event.get_sender_id(), name=event.get_sender_name()),
)
if len(result.chain) > 1 and isinstance(result.chain[1], Plain):
result.chain[1].text = "\n" + result.chain[1].text
# 引用回复
if self.reply_with_quote:
result.chain.insert(0, Reply(id=event.message_obj.message_id))

新增参数默认为 False,以保证现有的调用不受影响。

Use Case / 使用场景

在无法使用 yield 的上下文(session_waiter、事件钩子等)中,使 event.send() 也能遵循用户在 AstrBot 中配置的回复装饰规则。

Willing to Submit PR? / 是否愿意提交PR?

  • Yes, I am willing to submit a PR. / 是的,我愿意提交 PR。

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreThe bug / feature is about astrbot's core, backendenhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions