-
-
Notifications
You must be signed in to change notification settings - Fork 677
feat:发送消息前的At和Reply改用概率添加,同时过滤掉不支持的组件 #1818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
文件级别更改
可能相关的 issue
提示和命令与 Sourcery 交互
自定义您的体验访问您的 仪表板 以:
获取帮助Original review guide in EnglishReviewer's GuideThis PR refactors the injection of At and Reply components to use configurable probability values, adds filtering to avoid unsupported or duplicate injections, updates default configuration and schema entries from booleans to floats, and provides backward-compatible conversion of legacy boolean settings to probabilities. Class Diagram: Configuration and Logic for Probabilistic RepliesclassDiagram
class PlatformSettingsConfig {
<<Configuration>>
reply_with_mention: float
reply_with_quote: float
%% Other settings like path_mapping, segmented_reply omitted for clarity
}
class AstrBotConfig {
<<Configuration Handler>>
+check_config_integrity(refer_conf: dict, conf: dict, path: str) : bool
%% Method updated to convert legacy boolean values for
%% reply_with_mention and reply_with_quote in 'platform_settings'
%% path to float probabilities (True->1.0, False->0.0).
}
class ResultDecorateStage {
<<Pipeline Stage>>
reply_with_mention: float // Initialized from PlatformSettingsConfig
reply_with_quote: float // Initialized from PlatformSettingsConfig
+process(event: Event, result: Result) : void
%% Method logic updated to use float probabilities for At/Reply injection
%% and new filtering conditions based on message content and type.
}
ResultDecorateStage ..> PlatformSettingsConfig : uses
AstrBotConfig ..> PlatformSettingsConfig : manages/validates
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嘿 @Zhalslar - 我已经查看了你的更改 - 这里有一些反馈:
- 引用插入过滤器仅检查文件组件,但你的描述还提到了记录和视频 - 考虑扩展过滤器以排除这些类型。
- 验证或限制加载时的
reply_with_mention
和reply_with_quote
会更安全,以确保它们保持在 [0.0, 1.0] 范围内,并避免因配置错误而导致的意外行为。
AI 代理的提示
请解决此代码审查中的评论:
## 总体评论
- 引用插入过滤器仅检查文件组件,但你的描述还提到了记录和视频 - 考虑扩展过滤器以排除这些类型。
- 验证或限制加载时的 `reply_with_mention` 和 `reply_with_quote` 会更安全,以确保它们保持在 [0.0, 1.0] 范围内,并避免因配置错误而导致的意外行为。
## 单独评论
### 评论 1
<location> `astrbot/core/pipeline/result_decorate/stage.py:282` </location>
<code_context>
# at 回复
if (
- self.reply_with_mention
+ random.random() < self.reply_with_mention
and event.get_message_type() != MessageType.FRIEND_MESSAGE
+ and not (
</code_context>
<issue_to_address>
考虑强制执行有效的概率范围
这些概率的无效浮点数值可能会导致意外行为。在加载时限制它们,或者验证配置以确保它们保持在 0.0–1.0 之间。
建议的实施方案:
```python
def __init__(self, ..., reply_with_mention, ...):
# Clamp reply_with_mention to [0.0, 1.0]
self.reply_with_mention = min(max(reply_with_mention, 0.0), 1.0)
...
```
如果在其他地方设置了 `self.reply_with_mention`(例如,通过配置加载器或 setter),则应在每次赋值时应用相同的限制逻辑。如果想在任何地方都强制执行此操作,请考虑将其设为具有 setter 的属性,该 setter 会限制该值。
</issue_to_address>
### 评论 2
<location> `astrbot/core/config/default.py:28` </location>
<code_context>
"wl_ignore_admin_on_friend": True,
- "reply_with_mention": False,
- "reply_with_quote": False,
+ "reply_with_mention": 0.0,
+ "reply_with_quote": 0.0,
"path_mapping": [],
"segmented_reply": {
</code_context>
<issue_to_address>
为浮点概率添加 JSON 模式范围约束
请将 `minimum: 0.0` 和 `maximum: 1.0` 添加到这些模式字段,以强制执行有效的概率值。
建议的实施方案:
```python
"reply_with_mention": {
"description": "回复时 @ 发送者",
"type": "float",
"minimum": 0.0,
"maximum": 1.0,
"hint": "启用后,机器人回复消息时会 @ 发送者。0.0-1.0 之间的概率值,0.0 表示从不,1.0 表示总是。实际效果以具体的平台适配器为准。",
},
"reply_with_quote": {
```
```python
"reply_with_quote": {
"description": "回复时引用消息",
"type": "float",
"minimum": 0.0,
"maximum": 1.0,
"hint": "启用后,机器人回复消息时会引用原消息。0.0-1.0 之间的概率值,0.0 表示从不,1.0 表示总是。实际效果以具体的平台适配器为准。",
},
```
</issue_to_address>
帮助我更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English
Hey @Zhalslar - I've reviewed your changes - here's some feedback:
- The quote‐insertion filter only checks for File components, but your description mentions also Record and Video—consider extending the filter to exclude those types too.
- It would be safer to validate or clamp
reply_with_mention
andreply_with_quote
on load to ensure they stay within [0.0, 1.0] and avoid unexpected behavior if misconfigured.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The quote‐insertion filter only checks for File components, but your description mentions also Record and Video—consider extending the filter to exclude those types too.
- It would be safer to validate or clamp `reply_with_mention` and `reply_with_quote` on load to ensure they stay within [0.0, 1.0] and avoid unexpected behavior if misconfigured.
## Individual Comments
### Comment 1
<location> `astrbot/core/pipeline/result_decorate/stage.py:282` </location>
<code_context>
# at 回复
if (
- self.reply_with_mention
+ random.random() < self.reply_with_mention
and event.get_message_type() != MessageType.FRIEND_MESSAGE
+ and not (
</code_context>
<issue_to_address>
Consider enforcing valid probability range
Invalid float values for these probabilities could cause unintended behavior. Clamp them at load time or validate the config to ensure they stay within 0.0–1.0.
Suggested implementation:
```python
def __init__(self, ..., reply_with_mention, ...):
# Clamp reply_with_mention to [0.0, 1.0]
self.reply_with_mention = min(max(reply_with_mention, 0.0), 1.0)
...
```
If `self.reply_with_mention` is set elsewhere (e.g., via a config loader or setter), you should apply the same clamping logic at every assignment. If you want to enforce this everywhere, consider making it a property with a setter that clamps the value.
</issue_to_address>
### Comment 2
<location> `astrbot/core/config/default.py:28` </location>
<code_context>
"wl_ignore_admin_on_friend": True,
- "reply_with_mention": False,
- "reply_with_quote": False,
+ "reply_with_mention": 0.0,
+ "reply_with_quote": 0.0,
"path_mapping": [],
"segmented_reply": {
</code_context>
<issue_to_address>
Add JSON schema range constraints for float probabilities
Please add `minimum: 0.0` and `maximum: 1.0` to these schema fields to enforce valid probability values.
Suggested implementation:
```python
"reply_with_mention": {
"description": "回复时 @ 发送者",
"type": "float",
"minimum": 0.0,
"maximum": 1.0,
"hint": "启用后,机器人回复消息时会 @ 发送者。0.0-1.0 之间的概率值,0.0 表示从不,1.0 表示总是。实际效果以具体的平台适配器为准。",
},
"reply_with_quote": {
```
```python
"reply_with_quote": {
"description": "回复时引用消息",
"type": "float",
"minimum": 0.0,
"maximum": 1.0,
"hint": "启用后,机器人回复消息时会引用原消息。0.0-1.0 之间的概率值,0.0 表示从不,1.0 表示总是。实际效果以具体的平台适配器为准。",
},
```
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
# at 回复 | ||
if ( | ||
self.reply_with_mention | ||
random.random() < self.reply_with_mention |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): 考虑强制执行有效的概率范围
这些概率的无效浮点数值可能会导致意外行为。在加载时限制它们,或者验证配置以确保它们保持在 0.0-1.0 之间。
建议的实施方案:
def __init__(self, ..., reply_with_mention, ...):
# Clamp reply_with_mention to [0.0, 1.0]
self.reply_with_mention = min(max(reply_with_mention, 0.0), 1.0)
...
如果在其他地方设置了 self.reply_with_mention
(例如,通过配置加载器或 setter),则应在每次赋值时应用相同的限制逻辑。如果想在任何地方都强制执行此操作,请考虑将其设为具有 setter 的属性,该 setter 会限制该值。
Original comment in English
suggestion (bug_risk): Consider enforcing valid probability range
Invalid float values for these probabilities could cause unintended behavior. Clamp them at load time or validate the config to ensure they stay within 0.0–1.0.
Suggested implementation:
def __init__(self, ..., reply_with_mention, ...):
# Clamp reply_with_mention to [0.0, 1.0]
self.reply_with_mention = min(max(reply_with_mention, 0.0), 1.0)
...
If self.reply_with_mention
is set elsewhere (e.g., via a config loader or setter), you should apply the same clamping logic at every assignment. If you want to enforce this everywhere, consider making it a property with a setter that clamps the value.
"reply_with_mention": 0.0, | ||
"reply_with_quote": 0.0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: 为浮点概率添加 JSON 模式范围约束
请将 minimum: 0.0
和 maximum: 1.0
添加到这些模式字段,以强制执行有效的概率值。
建议的实施方案:
"reply_with_mention": {
"description": "回复时 @ 发送者",
"type": "float",
"minimum": 0.0,
"maximum": 1.0,
"hint": "启用后,机器人回复消息时会 @ 发送者。0.0-1.0 之间的概率值,0.0 表示从不,1.0 表示总是。实际效果以具体的平台适配器为准。",
},
"reply_with_quote": {
"reply_with_quote": {
"description": "回复时引用消息",
"type": "float",
"minimum": 0.0,
"maximum": 1.0,
"hint": "启用后,机器人回复消息时会引用原消息。0.0-1.0 之间的概率值,0.0 表示从不,1.0 表示总是。实际效果以具体的平台适配器为准。",
},
Original comment in English
suggestion: Add JSON schema range constraints for float probabilities
Please add minimum: 0.0
and maximum: 1.0
to these schema fields to enforce valid probability values.
Suggested implementation:
"reply_with_mention": {
"description": "回复时 @ 发送者",
"type": "float",
"minimum": 0.0,
"maximum": 1.0,
"hint": "启用后,机器人回复消息时会 @ 发送者。0.0-1.0 之间的概率值,0.0 表示从不,1.0 表示总是。实际效果以具体的平台适配器为准。",
},
"reply_with_quote": {
"reply_with_quote": {
"description": "回复时引用消息",
"type": "float",
"minimum": 0.0,
"maximum": 1.0,
"hint": "启用后,机器人回复消息时会引用原消息。0.0-1.0 之间的概率值,0.0 表示从不,1.0 表示总是。实际效果以具体的平台适配器为准。",
},
if random.random() < 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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code-quality): 合并嵌套的 if 条件 (merge-nested-ifs
)
if random.random() < 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)) | |
if random.random() < self.reply_with_quote and not any(isinstance(item, File) for item in result.chain): | |
result.chain.insert(0, Reply(id=event.message_obj.message_id)) | |
Explanation
过多的嵌套会使代码难以理解,这在 Python 中尤其如此,因为没有括号来帮助区分不同的嵌套级别。阅读深度嵌套的代码令人困惑,因为您必须跟踪哪些条件与哪些级别相关。因此,我们努力尽可能减少嵌套,并且可以使用 and
组合两个 if
条件的情况很容易实现。
Original comment in English
suggestion (code-quality): Merge nested if conditions (merge-nested-ifs
)
if random.random() < 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)) | |
if random.random() < self.reply_with_quote and not any(isinstance(item, File) for item in result.chain): | |
result.chain.insert(0, Reply(id=event.message_obj.message_id)) | |
Explanation
Too much nesting can make code difficult to understand, and this is especiallytrue in Python, where there are no brackets to help out with the delineation of
different nesting levels.
Reading deeply nested code is confusing, since you have to keep track of which
conditions relate to which levels. We therefore strive to reduce nesting where
possible, and the situation where two if
conditions can be combined using
and
is an easy win.
关于AI提到的为浮点概率添加 JSON 模式范围约束,这个可以统一为所有这类浮点配置添加约束,考虑到保持一致性这里就不加约束了,实际上超出约束照样能达到预期效果。另外一删除多余的File组件判断 |
Motivation
Modifications
Check
requirements.txt
和pyproject.toml
文件相应位置。Sourcery 总结
启用概率性插入提及(At)和引用回复组件,并针对不支持的消息链进行过滤,以及向后兼容布尔配置。
新特性:
增强功能:
Original summary in English
Sourcery 总结
启用概率性插入提及和引用回复组件,过滤不支持的消息链,并保持与布尔配置的向后兼容性
新特性:
Bug 修复:
增强功能:
文档:
Original summary in English
Summary by Sourcery
Enable probabilistic insertion of mention and quote reply components, filter unsupported message chains, and maintain backward compatibility with boolean configs
New Features:
Bug Fixes:
Enhancements:
Documentation: