Skip to content
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

✨ 添加自动同意群组请求 #1848

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

HibiKier
Copy link
Owner

No description provided.

Copy link
Contributor

sourcery-ai bot commented Feb 11, 2025

Sourcery 审查者指南

此 PR 实现了自动群邀请批准功能,与现有的好友请求处理并行。这些更改更新了配置设置,添加了异步延迟,改进了机器人数据源的日志记录和错误处理,优化了请求管理以返回结果以供进一步处理,并引入了一个新的依赖项。

FgRequest 方法的更新类图

classDiagram
    class FgRequest {
      +approve(bot: Bot, id: int) Self
      +refused(bot: Bot, id: int) Self
      +ignore(id: int) Self
      -_handle_request(bot: Bot|None, id: int, handle_type: RequestHandleType) Self
    }

    note for FgRequest "Methods now return the request object for further processing"
Loading

文件级别更改

变更 详情 文件
添加了自动群邀请批准的配置
  • 为 AUTO_ADD_GROUP 添加了一个新的 RegisterConfig,默认值为 False 并带有帮助描述
  • 更新了 record_request 插件中的配置注册结构
zhenxun/builtin_plugins/record_request.py
实现了群邀请的自动处理
  • 在处理好友请求之前插入了一个异步延迟
  • 修改了群请求处理程序,以便为超级用户或启用 AUTO_ADD_GROUP 时自动批准群邀请
  • 添加了一个分支来处理非超级用户的群邀请,通过通知超级用户并向请求者发送私信
  • 更新了日志消息,以反映超级用户自动批准和自动添加群组的行为
zhenxun/builtin_plugins/record_request.py
引入了一个新的异步实用程序来检索登录用户记录
  • 在 SignUser 模型中添加了一个 get_user 方法,用于根据 user_id 和 platform 获取或创建用户记录
zhenxun/models/sign_user.py
增强了 Web UI 数据源的可靠性
  • 将好友列表和群组列表的检索包装在 try-except 块中,以处理潜在的异常
  • 将默认计数设置为 0,并在检索失败时记录警告
  • 确保了机器人统计数据的正确数据分配,例如 group_count、friend_count 和 connect_time
zhenxun/builtin_plugins/web_ui/api/tabs/main/data_source.py
zhenxun/builtin_plugins/web_ui/api/tabs/dashboard/data_source.py
改进了请求管理和消息传递
  • 修改了 FgRequest 的 approve、refused 和 ignore 方法以返回请求对象
  • 更新了超级用户请求处理程序以存储请求对象并将其用于发送通知
  • 将消息传递函数从使用 finish() 更改为 send() 以发送成功消息
  • 为批准的群邀请添加了额外的私信通知
zhenxun/builtin_plugins/superuser/request_manage.py
zhenxun/models/fg_request.py
优化了 HTTP 实用程序和小的样式更新
  • 修改了 HTTP 实用程序中的 get_content 以始终返回 res.content 作为字节
  • 在登录数据源中应用了小的样式更改(格式化字符串中的间距)
zhenxun/utils/http_utils.py
zhenxun/builtin_plugins/sign_in/_data_source.py
更新了项目依赖
  • 将 nonebot-plugin-waiter 依赖项添加到 pyproject.toml,并在 poetry.lock 中进行了相应的更改
pyproject.toml
poetry.lock

提示和命令

与 Sourcery 互动

  • 触发新的审查: 在 pull request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 通过回复审查评论,要求 Sourcery 从审查评论创建一个 issue。您也可以回复带有 @sourcery-ai issue 的审查评论来从中创建一个 issue。
  • 生成 pull request 标题: 在 pull request 标题中的任何位置写入 @sourcery-ai 以随时生成标题。您也可以在 pull request 上评论 @sourcery-ai title 以随时(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文中的任何位置写入 @sourcery-ai summary 以随时在您想要的位置生成 PR 摘要。您也可以在 pull request 上评论 @sourcery-ai summary 以随时(重新)生成摘要。
  • 生成审查者指南: 在 pull request 上评论 @sourcery-ai guide 以随时(重新)生成审查者指南。
  • 解决所有 Sourcery 评论: 在 pull request 上评论 @sourcery-ai resolve 以解决所有 Sourcery 评论。如果您已经解决了所有评论并且不想再看到它们,这将非常有用。
  • 驳回所有 Sourcery 审查: 在 pull request 上评论 @sourcery-ai dismiss 以驳回所有现有的 Sourcery 审查。如果您想从新的审查开始,这将特别有用 - 不要忘记评论 @sourcery-ai review 以触发新的审查!
  • 为 issue 生成行动计划: 在 issue 上评论 @sourcery-ai plan 以为其生成行动计划。

自定义您的体验

访问您的 仪表板 以:

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

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This PR implements automatic group invite approval alongside existing friend request handling. The changes update configuration settings, add asynchronous delays, improve logging and error handling for bot data sources, refine request management to return results for further processing, and introduce a new dependency.

Updated class diagram for FgRequest methods

classDiagram
    class FgRequest {
      +approve(bot: Bot, id: int) Self
      +refused(bot: Bot, id: int) Self
      +ignore(id: int) Self
      -_handle_request(bot: Bot|None, id: int, handle_type: RequestHandleType) Self
    }

    note for FgRequest "Methods now return the request object for further processing"
Loading

File-Level Changes

Change Details Files
Added configuration for automatic group invite approval
  • Added a new RegisterConfig for AUTO_ADD_GROUP with default False and help description
  • Updated configuration registration structure in the record_request plugin
zhenxun/builtin_plugins/record_request.py
Implemented automatic handling for group invitations
  • Inserted an asynchronous delay before processing friend requests
  • Modified group request handler to auto-approve group invites for superusers or when AUTO_ADD_GROUP is enabled
  • Added a branch to handle non-superuser group invites by notifying superusers and sending a private message to the requester
  • Updated log messages to reflect both superuser auto-approval and auto-add group behavior
zhenxun/builtin_plugins/record_request.py
Introduced a new asynchronous utility to retrieve sign-in user records
  • Added a get_user method in the SignUser model to obtain or create a user record based on user_id and platform
zhenxun/models/sign_user.py
Enhanced reliability in web UI data sources
  • Wrapped friend list and group list retrievals in try-except blocks to handle potential exceptions
  • Set default counts to 0 and logged a warning when retrieval fails
  • Ensured correct data assignment for bot statistics such as group_count, friend_count, and connect_time
zhenxun/builtin_plugins/web_ui/api/tabs/main/data_source.py
zhenxun/builtin_plugins/web_ui/api/tabs/dashboard/data_source.py
Improved request management and messaging
  • Modified the FgRequest approve, refused, and ignore methods to return the request object
  • Updated the superuser request handler to store the request object and use it for sending notifications
  • Changed the messaging function from using finish() to send() for success messages
  • Included additional private message notifications for approved group invites
zhenxun/builtin_plugins/superuser/request_manage.py
zhenxun/models/fg_request.py
Refined HTTP utilities and minor style updates
  • Modified get_content in HTTP utilities to always return res.content as bytes
  • Applied minor style changes in the sign-in data source (spacing in formatted strings)
zhenxun/utils/http_utils.py
zhenxun/builtin_plugins/sign_in/_data_source.py
Updated project dependency
  • Added nonebot-plugin-waiter dependency to pyproject.toml, with corresponding changes in poetry.lock
pyproject.toml
poetry.lock

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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 dependencies Tracks issues related to external dependencies or library updates. enhancement New feature or request labels Feb 11, 2025
@HibiKier HibiKier marked this pull request as ready for review February 11, 2025 02:53
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 - 我已经查看了你的更改 - 这里有一些反馈:

总体评论

  • 考虑添加一条注释,解释为什么在 record_request.py 中需要 asyncio.sleep 调用。
  • fg_request.py 中,即使发生异常,_handle_request 方法也应该始终如一地返回值。
以下是我在审查期间查看的内容
  • 🟢 一般问题:一切看起来都很好
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

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

Hey @HibiKier - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a comment explaining why the asyncio.sleep call is necessary in record_request.py.
  • In fg_request.py, the _handle_request method should consistently return a value, even when an exception occurs.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 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.

)
try:
select_bot.group_count = len(
(await PlatformUtils.get_group_list(select_bot.bot, True))[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

使用asyncio.gather获取

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Tracks issues related to external dependencies or library updates. enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants