Skip to content

Commit

Permalink
feat: 支持回复时 At 和引用发送者 #241
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulter committed Jan 18, 2025
1 parent c4e0563 commit 048004f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 12 additions & 0 deletions astrbot/core/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"id_whitelist_log": True,
"wl_ignore_admin_on_group": True,
"wl_ignore_admin_on_friend": True,
"reply_with_mention": False,
"reply_with_quote": False,
},
"provider": [],
"provider_settings": {
Expand Down Expand Up @@ -199,6 +201,16 @@
"description": "管理员私聊消息无视 ID 白名单",
"type": "bool",
},
"reply_with_mention": {
"description": "回复时 @ 发送者",
"type": "bool",
"hint": "启用后,机器人回复消息时会 @ 发送者。实际效果以具体的平台适配器为准。",
},
"reply_with_quote": {
"description": "回复时引用消息",
"type": "bool",
"hint": "启用后,机器人回复消息时会引用原消息。实际效果以具体的平台适配器为准。",
},
},
},
"content_safety": {
Expand Down
14 changes: 12 additions & 2 deletions astrbot/core/pipeline/result_decorate/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from ..stage import register_stage
from ..context import PipelineContext
from astrbot.core.platform.astr_message_event import AstrMessageEvent
from astrbot.core.platform.message_type import MessageType
from astrbot.core import logger
from astrbot.core.message.components import Plain, Image
from astrbot.core.message.components import Plain, Image, At, Reply
from astrbot.core import html_renderer
from astrbot.core.star.star_handler import star_handlers_registry, EventType

Expand All @@ -13,6 +14,8 @@ class ResultDecorateStage:
async def initialize(self, ctx: PipelineContext):
self.ctx = ctx
self.reply_prefix = ctx.astrbot_config['platform_settings']['reply_prefix']
self.reply_with_mention = ctx.astrbot_config['platform_settings']['reply_with_mention']
self.reply_with_quote = ctx.astrbot_config['platform_settings']['reply_with_quote']
self.t2i = ctx.astrbot_config['t2i']

async def process(self, event: AstrMessageEvent) -> Union[None, AsyncGenerator[None, None]]:
Expand Down Expand Up @@ -48,4 +51,11 @@ async def process(self, event: AstrMessageEvent) -> Union[None, AsyncGenerator[N
if time.time() - render_start > 3:
logger.warning("文本转图片耗时超过了 3 秒,如果觉得很慢可以使用 /t2i 关闭文本转图片模式。")
if url:
result.chain = [Image.fromURL(url)]
result.chain = [Image.fromURL(url)]

if self.reply_with_mention and event.get_message_type() != MessageType.FRIEND_MESSAGE:
result.chain.insert(0, Plain("\n"))
result.chain.insert(0, At(qq=event.get_sender_id()))

if self.reply_with_quote:
result.chain.insert(0, Reply(id=event.message_obj.message_id))

0 comments on commit 048004f

Please sign in to comment.