-
-
Notifications
You must be signed in to change notification settings - Fork 930
fix: 修复 Misskey 适配器的通知和聊天消息处理,改进 @用户提及逻辑 #3075
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
Merged
Soulter
merged 1 commit into
AstrBotDevs:master
from
PaloMiku:feature/misskey-adapter-fix
Oct 19, 2025
Merged
fix: 修复 Misskey 适配器的通知和聊天消息处理,改进 @用户提及逻辑 #3075
Soulter
merged 1 commit into
AstrBotDevs:master
from
PaloMiku:feature/misskey-adapter-fix
Oct 19, 2025
+47
−25
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
你好 - 我已经审阅了你的更改 - 这里有一些反馈:
- 将
session_id
解析逻辑提取到一个共享的辅助函数中,以避免在send_by_session
和_upload_comp
中重复分割/验证代码。 - 考虑在使用后清除或使缓存的
reply_to_note_id
失效,以防止在后续消息中意外回复过时的笔记。
给AI代理的提示
请处理此代码审查中的评论:
## 总体评论
- 将 `session_id` 解析逻辑提取到一个共享的辅助函数中,以避免在 `send_by_session` 和 `_upload_comp` 中重复分割/验证代码。
- 考虑在使用后清除或使缓存的 `reply_to_note_id` 失效,以防止在后续消息中意外回复过时的笔记。
## 独立评论
### 评论 1
<location> `astrbot/core/platform/sources/misskey/misskey_utils.py:89-92` </location>
<code_context>
- return f"@{component.qq}"
+ # 优先使用name字段(用户名),如果没有则使用qq字段
+ # 这样可以避免在Misskey中生成 @<user_id> 这样的无效提及
+ if hasattr(component, "name") and component.name:
+ return f"@{component.name}"
+ else:
+ return f"@{component.qq}"
</code_context>
<issue_to_address>
**建议:** 考虑在使用 'name' 字段进行提及之前对其进行规范化或验证。
带有空格或特殊字符的名称可能导致无效提及。请确保 'name' 已正确规范化或验证以兼容 Misskey。
```suggestion
def normalize_misskey_name(name):
# Misskey usernames must be alphanumeric or underscores, no spaces or special chars
import re
# Remove leading/trailing whitespace, replace spaces with underscores, remove invalid chars
name = name.strip().replace(" ", "_")
name = re.sub(r"[^\\w_]", "", name)
return name
if hasattr(component, "name") and component.name:
normalized_name = normalize_misskey_name(component.name)
if normalized_name: # Only use if valid after normalization
return f"@{normalized_name}"
else:
return f"@{component.qq}"
else:
return f"@{component.qq}"
```
</issue_to_address>
帮助我更有用!请点击每个评论上的 👍 或 👎,我将利用这些反馈来改进你的评论。
Original comment in English
Hey there - I've reviewed your changes - here's some feedback:
- Extract the session_id parsing logic into a shared helper function to avoid duplicating split/validation code in both send_by_session and _upload_comp.
- Consider clearing or invalidating the cached reply_to_note_id after use to prevent accidentally replying to a stale note on subsequent messages.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Extract the session_id parsing logic into a shared helper function to avoid duplicating split/validation code in both send_by_session and _upload_comp.
- Consider clearing or invalidating the cached reply_to_note_id after use to prevent accidentally replying to a stale note on subsequent messages.
## Individual Comments
### Comment 1
<location> `astrbot/core/platform/sources/misskey/misskey_utils.py:89-92` </location>
<code_context>
- return f"@{component.qq}"
+ # 优先使用name字段(用户名),如果没有则使用qq字段
+ # 这样可以避免在Misskey中生成 @<user_id> 这样的无效提及
+ if hasattr(component, "name") and component.name:
+ return f"@{component.name}"
+ else:
+ return f"@{component.qq}"
</code_context>
<issue_to_address>
**suggestion:** Consider normalizing or validating the 'name' field before using it for mentions.
Names with spaces or special characters may lead to invalid mentions. Please ensure the 'name' is properly normalized or validated for Misskey compatibility.
```suggestion
def normalize_misskey_name(name):
# Misskey usernames must be alphanumeric or underscores, no spaces or special chars
import re
# Remove leading/trailing whitespace, replace spaces with underscores, remove invalid chars
name = name.strip().replace(" ", "_")
name = re.sub(r"[^\w_]", "", name)
return name
if hasattr(component, "name") and component.name:
normalized_name = normalize_misskey_name(component.name)
if normalized_name: # Only use if valid after normalization
return f"@{normalized_name}"
else:
return f"@{component.qq}"
else:
return f"@{component.qq}"
```
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Soulter
approved these changes
Oct 19, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / 动机
修复对最新 Astrbot 版本的 Misskey 适配器引用用户贴文回复问题问题
Screenshots or Test Results / 运行截图或测试结果
问题截图
修复后截图
Compatibility & Breaking Changes / 兼容性与破坏性变更
Checklist / 检查清单
requirements.txt
和pyproject.toml
文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txt
andpyproject.toml
.Sourcery 总结
优化 Misskey 适配器,通过改进日志记录、修复 @mention 行为、更准确地管理用户缓存,并添加 reply_id 支持以正确链接回复到原始帖子。
新功能:
错误修复:
增强功能:
Original summary in English
Summary by Sourcery
Optimize the Misskey adapter by refining logging, fixing @mention behavior, managing user cache more accurately, and adding reply_id support to properly link replies to original posts.
New Features:
Bug Fixes:
Enhancements: