diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 17ee27949..a70831bab 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -32,7 +32,8 @@ DEFAULT_CONFIG = { "interval": "1.5,3.5", "log_base": 2.6, "words_count_threshold": 150, - "regex": ".*?[。?!~…]+|.+$" + "regex": ".*?[。?!~…]+|.+$", + "content_cleanup_rule": "", }, "no_permission_reply": True, }, @@ -271,6 +272,12 @@ CONFIG_METADATA_2 = { "obvious_hint": True, "hint": "用于分隔一段消息。默认情况下会根据句号、问号等标点符号分隔。re.findall(r'', text)", }, + "content_cleanup_rule": { + "description": "过滤分段后的内容", + "type": "string", + "obvious_hint": True, + "hint": "移除分段后的内容中的指定的内容。支持正则表达式。如填写 `[。?!]` 将移除所有的句号、问号、感叹号。re.sub(r'', '', text)", + }, }, }, "reply_prefix": { diff --git a/astrbot/core/pipeline/result_decorate/stage.py b/astrbot/core/pipeline/result_decorate/stage.py index 03a8d7cdc..32afcb86a 100644 --- a/astrbot/core/pipeline/result_decorate/stage.py +++ b/astrbot/core/pipeline/result_decorate/stage.py @@ -31,6 +31,8 @@ class ResultDecorateStage(Stage): self.enable_segmented_reply = ctx.astrbot_config['platform_settings']['segmented_reply']['enable'] self.only_llm_result = ctx.astrbot_config['platform_settings']['segmented_reply']['only_llm_result'] self.regex = ctx.astrbot_config['platform_settings']['segmented_reply']['regex'] + self.content_cleanup_rule = ctx.astrbot_config['platform_settings']['segmented_reply']['content_cleanup_rule'] + # exception self.content_safe_check_reply = ctx.astrbot_config['content_safety']['also_use_in_response'] @@ -89,6 +91,8 @@ class ResultDecorateStage(Stage): new_chain.append(comp) continue for seg in split_response: + if self.content_cleanup_rule: + seg = re.sub(self.content_cleanup_rule, "", seg) if seg.strip(): new_chain.append(Plain(seg)) else: @@ -148,4 +152,4 @@ class ResultDecorateStage(Stage): # 引用回复 if self.reply_with_quote: if not any(isinstance(item, File) for item in result.chain): - result.chain.insert(0, Reply(id=event.message_obj.message_id)) \ No newline at end of file + result.chain.insert(0, Reply(id=event.message_obj.message_id)) diff --git a/astrbot/core/star/register/star_handler.py b/astrbot/core/star/register/star_handler.py index e9fecab3a..e6bc45900 100644 --- a/astrbot/core/star/register/star_handler.py +++ b/astrbot/core/star/register/star_handler.py @@ -81,6 +81,7 @@ def register_command(command_name: str = None, sub_command: str = None, alias: s return decorator + def register_custom_filter(custom_type_filter, *args, **kwargs): '''注册一个自定义的 CustomFilter