Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

✨ 添加用户消息撤回命令 #1719

Merged
merged 1 commit into from
Nov 5, 2024
Merged

✨ 添加用户消息撤回命令 #1719

merged 1 commit into from
Nov 5, 2024

Conversation

HibiKier
Copy link
Owner

@HibiKier HibiKier commented Nov 5, 2024

Summary by Sourcery

添加一个新功能,允许用户通过命令撤回自己的消息,并通过附加链接和图像更新文档,以改善用户指导。

新功能:

  • 引入一个新命令,允许用户撤回自己的消息,防止撤回由他人触发的消息。

增强功能:

  • 通过添加外部资源链接和更新图像来源来增强文档,以提高清晰度。

文档:

  • 在文档的 WebUI 部分添加一张新图像,以便更好地说明。
Original summary in English

Summary by Sourcery

Add a new feature allowing users to retract their own messages with a command, and update the documentation with additional links and images for improved user guidance.

New Features:

  • Introduce a new command for users to retract their own messages, preventing the retraction of messages triggered by others.

Enhancements:

  • Enhance the documentation by adding links to external resources and updating image sources for better clarity.

Documentation:

  • Add a new image to the WebUI section in the documentation for better illustration.

Copy link
Contributor

sourcery-ai bot commented Nov 5, 2024

审核指南由 Sourcery 提供

此 PR 实现了一个消息撤回功能,允许用户撤回他们自己触发的机器人消息。该实现包括一个新的消息跟踪系统和一个命令处理器,在允许消息撤回之前检查权限。

MessageManager 的类图

classDiagram
    class MessageManager {
        +ClassVar data: dict[str, list[str]]
        +add(uid: str, msg_id: str)
        +check(uid: str, msg_id: str) bool
        +remove_check(uid: str)
        +get(uid: str) list[str]
    }
    note for MessageManager "管理消息撤回功能的消息跟踪"
Loading

新插件和钩子的类图

classDiagram
    class PluginMetadata {
        +name: str
        +description: str
        +usage: str
        +extra: dict
    }
    class CallHook {
        +handle_api_result(bot: Bot, exception: Exception | None, api: str, data: dict[str, Any], result: Any)
    }
    PluginMetadata <|-- CallHook
    note for PluginMetadata "新消息撤回插件的元数据"
    note for CallHook "处理 API 调用结果以跟踪消息"
Loading

文件级更改

更改 详情 文件
实现了消息撤回命令系统
  • 添加了一个新的命令处理器,响应“撤回”命令
  • 实现了权限检查,确保用户只能撤回自己的消息
  • 通过基于回复的交互添加了消息撤回支持
  • 包括过期消息的错误处理
zhenxun/builtin_plugins/withdraw.py
创建了一个消息跟踪系统来管理消息所有权
  • 实现了一个基于类的消息管理器来存储用户-消息关联
  • 添加了跟踪、检查和管理每个用户消息 ID 的方法
  • 实现了自动清理以防止内存溢出
zhenxun/utils/manager/message_manager.py
添加了用于消息跟踪的 API 调用钩子
  • 实现了一个钩子来在成功发送消息后捕获消息 ID
  • 为用户触发的消息添加了自动消息跟踪
  • 包括消息跟踪的错误处理和日志记录
zhenxun/builtin_plugins/hooks/call_hook.py
更新了文档和资源
  • 使用正确的引用更新了客户端连接链接
  • 添加了新的 WebUI 截图
  • 更新了捐赠图片路径
  • 添加了额外的贡献者信息
README.md

提示和命令

与 Sourcery 互动

  • 触发新审核: 在拉取请求上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审核评论。
  • 从审核评论生成 GitHub 问题: 通过回复审核评论请求 Sourcery 创建一个问题。
  • 生成拉取请求标题: 在拉取请求标题的任何地方写 @sourcery-ai 以随时生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任何地方写 @sourcery-ai summary 以随时生成 PR 摘要。您也可以使用此命令指定摘要应插入的位置。

自定义您的体验

访问您的仪表板以:

  • 启用或禁用审核功能,例如 Sourcery 生成的拉取请求摘要、审核指南等。
  • 更改审核语言。
  • 添加、删除或编辑自定义审核说明。
  • 调整其他审核设置。

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This PR implements a message withdrawal feature that allows users to recall their own bot-triggered messages. The implementation includes a new message tracking system and a command handler that checks permissions before allowing message withdrawal.

Class diagram for MessageManager

classDiagram
    class MessageManager {
        +ClassVar data: dict[str, list[str]]
        +add(uid: str, msg_id: str)
        +check(uid: str, msg_id: str) bool
        +remove_check(uid: str)
        +get(uid: str) list[str]
    }
    note for MessageManager "Manages message tracking for withdrawal feature"
Loading

Class diagram for new plugin and hook

classDiagram
    class PluginMetadata {
        +name: str
        +description: str
        +usage: str
        +extra: dict
    }
    class CallHook {
        +handle_api_result(bot: Bot, exception: Exception | None, api: str, data: dict[str, Any], result: Any)
    }
    PluginMetadata <|-- CallHook
    note for PluginMetadata "Metadata for the new message withdrawal plugin"
    note for CallHook "Handles API call results to track messages"
Loading

File-Level Changes

Change Details Files
Implemented a message withdrawal command system
  • Added a new command handler that responds to '撤回' (withdraw) command
  • Implemented permission checking to ensure users can only withdraw their own messages
  • Added support for message withdrawal through reply-based interaction
  • Included error handling for expired messages
zhenxun/builtin_plugins/withdraw.py
Created a message tracking system to manage message ownership
  • Implemented a class-based message manager to store user-message associations
  • Added methods to track, check, and manage message IDs per user
  • Implemented automatic cleanup to prevent memory overflow
zhenxun/utils/manager/message_manager.py
Added API call hook for message tracking
  • Implemented a hook to capture message IDs after successful message sending
  • Added automatic message tracking for user-triggered messages
  • Included error handling and logging for message tracking
zhenxun/builtin_plugins/hooks/call_hook.py
Updated documentation and resources
  • Updated client connection links with proper references
  • Added new WebUI screenshot
  • Updated donation image path
  • Added additional contributor information
README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@AkashiCoin AkashiCoin added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 5, 2024
@HibiKier HibiKier merged commit abd8b9b into dev Nov 5, 2024
2 checks passed
@HibiKier HibiKier deleted the feature/msg-withdraw branch November 5, 2024 07:34
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HibiKier - 我已经审查了你的更改,发现了一些需要解决的问题。

阻塞问题

  • 添加线程安全机制以保护共享类状态 (link)

总体评论

  • 考虑在多实例部署中使用类变量进行消息存储是否会导致问题。根据你的扩展需求,更持久的存储解决方案可能更合适。
这是我在审查期间查看的内容
  • 🟡 一般问题:发现1个问题
  • 🔴 安全性:1个阻塞问题
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

Sourcery对开源项目免费 - 如果你喜欢我们的评论,请考虑分享它们 ✨
帮助我变得更有用!请点击每条评论上的👍或👎,我将使用反馈来改进你的评论。
Original comment in English

Hey @HibiKier - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Add thread safety mechanisms to protect shared class state (link)

Overall Comments:

  • Consider whether using class variables for message storage in MessageManager could cause issues in multi-instance deployments. A more persistent storage solution might be more appropriate depending on your scaling needs.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🔴 Security: 1 blocking issue
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.



class MessageManager:
data: ClassVar[dict[str, list[str]]] = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议(性能): 考虑为不活跃用户实现清理机制以防止内存泄漏

当前的实现仅在添加新消息时进行清理。考虑为不活跃用户的消息历史添加定期清理任务或过期机制。

    data: ClassVar[dict[str, list[str]]] = {}
    _last_access: ClassVar[dict[str, float]] = {}
    CLEANUP_THRESHOLD: ClassVar[float] = 3600  # seconds
Original comment in English

suggestion (performance): Consider implementing a cleanup mechanism for inactive users to prevent memory leaks

The current implementation only cleans up when new messages are added. Consider adding a periodic cleanup task or an expiration mechanism for inactive users' message histories.

    data: ClassVar[dict[str, list[str]]] = {}
    _last_access: ClassVar[dict[str, float]] = {}
    CLEANUP_THRESHOLD: ClassVar[float] = 3600  # seconds

from typing import ClassVar


class MessageManager:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 建议(安全性): 添加线程安全机制以保护共享类状态

该类在没有同步的情况下使用共享状态。考虑使用锁或使类线程安全,以防止并发操作中的潜在竞争条件。

from typing import ClassVar
from threading import Lock


class MessageManager:
    _lock: ClassVar[Lock] = Lock()
    data: ClassVar[dict[str, list[str]]] = {}
Original comment in English

🚨 suggestion (security): Add thread safety mechanisms to protect shared class state

The class uses shared state without synchronization. Consider using locks or making the class thread-safe to prevent potential race conditions in concurrent operations.

from typing import ClassVar
from threading import Lock


class MessageManager:
    _lock: ClassVar[Lock] = Lock()
    data: ClassVar[dict[str, list[str]]] = {}

Comment on lines +25 to +27
if uid in cls.data:
return cls.data[uid]
return []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议(代码质量): 我们发现了这些问题:

Suggested change
if uid in cls.data:
return cls.data[uid]
return []
return cls.data[uid] if uid in cls.data else []
Original comment in English

suggestion (code-quality): We've found these issues:

Suggested change
if uid in cls.data:
return cls.data[uid]
return []
return cls.data[uid] if uid in cls.data else []

@HibiKier HibiKier mentioned this pull request Nov 5, 2024
HibiKier added a commit that referenced this pull request Nov 5, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants