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?
Code of Conduct
Description / 描述
希望能为
AstrMessageEvent.send()方法新增一个可选的参数decoration,用于控制是否为通过该方法发送的消息添加以下消息装饰:AstrBot/astrbot/core/pipeline/result_decorate/stage.py
Lines 389 to 422 in b5e2951
新增参数默认为 False,以保证现有的调用不受影响。
Use Case / 使用场景
在无法使用
yield的上下文(session_waiter、事件钩子等)中,使event.send()也能遵循用户在 AstrBot 中配置的回复装饰规则。Willing to Submit PR? / 是否愿意提交PR?
Code of Conduct