Skip to content

Fix rate#108

Open
JohnRichard4096 wants to merge 7 commits intomainfrom
fix-rate
Open

Fix rate#108
JohnRichard4096 wants to merge 7 commits intomainfrom
fix-rate

Conversation

@JohnRichard4096
Copy link
Copy Markdown
Member

@JohnRichard4096 JohnRichard4096 commented Sep 30, 2025

Sourcery 总结

优化 bad_words 插件,以改进词语过滤和命令处理,并通过移除回复消息和预过滤不相关消息来简化限速器(rate limiter)行为。

改进点:

  • 优化 check_bad_words 函数,使其返回一个布尔值,并使用正确的 jieba.cut 参数,同时改进触发过滤器的群成员角色检查
  • 改进 bad_words 命令处理程序,以使用 CommandArg,在未提供参数时提供当前状态,强制执行单参数验证,并标准化敏感词列表模式
  • 在管理员响应中,为 Base64 编码的自定义敏感词添加逗号,以提高可读性
Original summary in English

Summary by Sourcery

Refine bad_words plugin to improve word filtering and command handling, and streamline rate limiter behavior by removing reply messages and pre-filtering irrelevant messages.

Enhancements:

  • Optimize check_bad_words to return a boolean with the correct jieba.cut parameters and refine group member role checks for triggering filters
  • Revamp bad_words command handlers to use CommandArg, provide current status when no arguments are given, enforce single-argument validation, and standardize bad word list modes
  • Append commas to base64-encoded custom bad words in admin responses for readability

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Sep 30, 2025

🧙 Sourcery 已完成对您的拉取请求的审查!


提示和命令

与 Sourcery 互动

  • 触发新审查: 在拉取请求上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 通过回复审查评论,要求 Sourcery 从中创建一个 issue。您也可以回复审查评论并带上 @sourcery-ai issue 来从中创建一个 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai 即可随时生成标题。您也可以在拉取请求上评论 @sourcery-ai title 来随时(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任意位置写入 @sourcery-ai summary 即可随时在您想要的位置生成 PR 摘要。您也可以在拉取请求上评论 @sourcery-ai summary 来随时(重新)生成摘要。
  • 生成审阅者指南: 在拉取请求上评论 @sourcery-ai guide 即可随时(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求上评论 @sourcery-ai resolve 以解决所有 Sourcery 评论。如果您已处理所有评论并且不想再看到它们,这会很有用。
  • 驳回所有 Sourcery 审查: 在拉取请求上评论 @sourcery-ai dismiss 以驳回所有现有的 Sourcery 审查。如果您想从头开始进行新审查,这会特别有用——别忘了评论 @sourcery-ai review 来触发新审查!

自定义您的体验

访问您的 仪表盘 以:

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

获取帮助

Original review guide in English

🧙 Sourcery has finished reviewing your pull request!


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!

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

Copy link
Copy Markdown
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.

你好 - 我已审阅了你的更改 - 这里有一些反馈:

  • check_bad_words 中,你直接将 True 传递给 jieba.cut,这会降低可读性——考虑使用关键字参数(例如 cut_all=True)或切换到 jieba.lcut 以提高清晰度。
  • 角色检查使用了 or 并且在发送者角色为真时短路,因此机器人的角色从未实际验证——如果你打算要求两个角色都是 'member',请使用 and
  • 限速器现在默默地丢弃消息而不提供反馈;如果这是有意的,它应该是一个可配置的模式,或者至少进行日志记录以帮助调试。
供AI代理的提示
请处理此代码审查中的评论:

## 总体评论
-`check_bad_words` 中,你直接将 `True` 传递给 `jieba.cut`,这会降低可读性——考虑使用关键字参数(例如 `cut_all=True`)或切换到 `jieba.lcut` 以提高清晰度。
- 角色检查使用了 `or` 并且在发送者角色为真时短路,因此机器人的角色从未实际验证——如果你打算要求两个角色都是 'member',请使用 `and`- 限速器现在默默地丢弃消息而不提供反馈;如果这是有意的,它应该是一个可配置的模式,或者至少进行日志记录以帮助调试。

## 单独评论

### 评论 1
<location> `src/plugins/group/bad_words.py:45-47` </location>
<code_context>
def check_bad_words(
    text: str, extra_words: Iterable[str] = [], words: Iterable[str] = BAD_WORDS
) -> bool:
    return bool(set(jieba.cut(text, True)) & set(tuple(words) + tuple(extra_words)))

</code_context>

<issue_to_address>
**建议 (代码质量):** 将可变默认参数替换为 `None` ([`default-mutable-arg`](https://docs.sourcery.ai/Reference/Default-Rules/suggestions/default-mutable-arg/))

```suggestion
def check_bad_words(text: str, extra_words: Iterable[str] = None, words: Iterable[str] = BAD_WORDS) -> bool:
    if extra_words is None:
        extra_words = []
```
</issue_to_address>

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

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

  • In check_bad_words you pass a bare True to jieba.cut, which hurts readability—consider using a keyword argument (e.g. cut_all=True) or switching to jieba.lcut for clarity.
  • The role-check uses or and short-circuits on a truthy sender role so the bot’s role is never actually validated—use and if you intend to require both roles to be 'member'.
  • The rate limiter now silently drops messages without feedback; if this is intentional it should be a configurable mode or at least logged to help with debugging.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In check_bad_words you pass a bare True to jieba.cut, which hurts readability—consider using a keyword argument (e.g. cut_all=True) or switching to jieba.lcut for clarity.
- The role-check uses `or` and short-circuits on a truthy sender role so the bot’s role is never actually validated—use `and` if you intend to require both roles to be 'member'.
- The rate limiter now silently drops messages without feedback; if this is intentional it should be a configurable mode or at least logged to help with debugging.

## Individual Comments

### Comment 1
<location> `src/plugins/group/bad_words.py:45-47` </location>
<code_context>
def check_bad_words(
    text: str, extra_words: Iterable[str] = [], words: Iterable[str] = BAD_WORDS
) -> bool:
    return bool(set(jieba.cut(text, True)) & set(tuple(words) + tuple(extra_words)))

</code_context>

<issue_to_address>
**suggestion (code-quality):** Replace mutable default arguments with None ([`default-mutable-arg`](https://docs.sourcery.ai/Reference/Default-Rules/suggestions/default-mutable-arg/))

```suggestion
def check_bad_words(text: str, extra_words: Iterable[str] = None, words: Iterable[str] = BAD_WORDS) -> bool:
    if extra_words is None:
        extra_words = []
```
</issue_to_address>

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.

Comment on lines 45 to 47
def check_bad_words(
text: str, extra_words: Iterable[str] = [], words: Iterable[str] = BAD_WORDS
) -> bool:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

建议 (代码质量): 将可变默认参数替换为 None (default-mutable-arg)

Suggested change
def check_bad_words(
text: str, extra_words: Iterable[str] = [], words: Iterable[str] = BAD_WORDS
) -> bool:
def check_bad_words(text: str, extra_words: Iterable[str] = None, words: Iterable[str] = BAD_WORDS) -> bool:
if extra_words is None:
extra_words = []
Original comment in English

suggestion (code-quality): Replace mutable default arguments with None (default-mutable-arg)

Suggested change
def check_bad_words(
text: str, extra_words: Iterable[str] = [], words: Iterable[str] = BAD_WORDS
) -> bool:
def check_bad_words(text: str, extra_words: Iterable[str] = None, words: Iterable[str] = BAD_WORDS) -> bool:
if extra_words is None:
extra_words = []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant