Skip to content

✨ 支持使用对话批量操作 cookie 关联#741

Open
suyiiyii wants to merge 2 commits intomainfrom
feat/all-target
Open

✨ 支持使用对话批量操作 cookie 关联#741
suyiiyii wants to merge 2 commits intomainfrom
feat/all-target

Conversation

@suyiiyii
Copy link
Copy Markdown
Contributor

@suyiiyii suyiiyii commented Sep 24, 2025

支持批量关联

图片

支持批量取消关联

图片

This change is Reviewable

@netlify
Copy link
Copy Markdown

netlify Bot commented Sep 24, 2025

Deploy Preview for nonebot-bison ready!

Name Link
🔨 Latest commit c040bf2
🔍 Latest deploy log https://app.netlify.com/projects/nonebot-bison/deploys/68d54cfed0218000085788ea
😎 Deploy Preview https://deploy-preview-741--nonebot-bison.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@suyiiyii suyiiyii changed the title ✨ 绑定 cookie 到 target 时支持绑定全部 ✨ 支持使用对话批量操作 cookie 关联 Sep 25, 2025
@suyiiyii suyiiyii changed the title ✨ 支持使用对话批量操作 cookie 关联 WIP:: ✨ 支持使用对话批量操作 cookie 关联 Sep 25, 2025
@suyiiyii suyiiyii marked this pull request as draft September 25, 2025 08:11
@suyiiyii suyiiyii force-pushed the feat/all-target branch 3 times, most recently from cb9d87e to 118d4cb Compare September 25, 2025 08:33
@suyiiyii suyiiyii requested a review from Copilot September 25, 2025 08:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces batch operations for cookie associations, allowing users to associate or disassociate cookies for multiple subscriptions at once through conversational interactions. The changes enhance the user experience by adding platform-specific filtering and batch processing capabilities.

  • Add platform selection step before target selection for cookie operations
  • Implement batch cookie association/disassociation for multiple targets
  • Support "all" option to associate a cookie with all targets under a platform

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/sub_manager/test_add_cookie.py Updates test cases to reflect new multi-step workflow with platform selection
nonebot_bison/sub_manager/utils.py Adds utility functions for platform selection and batch operations support
nonebot_bison/sub_manager/del_cookie_target.py Refactors cookie deletion to support platform-based filtering and batch operations
nonebot_bison/sub_manager/add_cookie_target.py Implements platform selection and batch cookie association functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread nonebot_bison/sub_manager/utils.py
Comment thread nonebot_bison/sub_manager/utils.py Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 25, 2025

Codecov Report

❌ Patch coverage is 82.85714% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.19%. Comparing base (8d13d10) to head (c040bf2).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
nonebot_bison/sub_manager/del_cookie_target.py 65.00% 21 Missing ⚠️
nonebot_bison/sub_manager/add_cookie_target.py 91.07% 5 Missing ⚠️
nonebot_bison/sub_manager/utils.py 93.22% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #741      +/-   ##
==========================================
+ Coverage   85.07%   85.19%   +0.12%     
==========================================
  Files          99       99              
  Lines        5600     5742     +142     
==========================================
+ Hits         4764     4892     +128     
- Misses        836      850      +14     
Flag Coverage Δ
smoke-test 85.19% <82.85%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@suyiiyii suyiiyii force-pushed the feat/all-target branch 3 times, most recently from b03bbaa to 8c09215 Compare September 25, 2025 14:04
@suyiiyii suyiiyii changed the title WIP:: ✨ 支持使用对话批量操作 cookie 关联 ✨ 支持使用对话批量操作 cookie 关联 Sep 25, 2025
@suyiiyii suyiiyii marked this pull request as ready for review September 25, 2025 14:14
@felinae98 felinae98 requested a review from Copilot December 22, 2025 11:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 11 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +86 to +87
weibo_cookie = next(c for c in cookies if c.site_name == "weibo.com")
bilibili_cookie = next(c for c in cookies if c.site_name == "bilibili.com")
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The test uses next(c for c in cookies if c.site_name == "weibo.com") which will raise StopIteration if no cookie matches. While this shouldn't happen in this test, consider using next(..., None) with a None check or a more explicit filter for better error handling and clarity in case of test setup issues.

Suggested change
weibo_cookie = next(c for c in cookies if c.site_name == "weibo.com")
bilibili_cookie = next(c for c in cookies if c.site_name == "bilibili.com")
weibo_cookie = next((c for c in cookies if c.site_name == "weibo.com"), None)
bilibili_cookie = next((c for c in cookies if c.site_name == "bilibili.com"), None)
assert weibo_cookie is not None
assert bilibili_cookie is not None

Copilot uses AI. Check for mistakes.
Comment on lines 68 to +69
except Exception:
await del_cookie_target.reject("删除错误")
await del_cookie_target.reject("输入格式错误,请输入数字序号(多个用空格分隔)")
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The outer except Exception block at line 68 catches any unexpected exception that wasn't handled by the inner try-except blocks. While the error message is generic, this is a reasonable safety net. However, this exception handler may never be reached in practice since all foreseeable exceptions (ValueError for invalid int parsing) are caught in the inner try-except. Consider whether this outer exception handler is necessary, or if it should log the unexpected exception for debugging purposes.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +2
from nonebug.app import App
import pytest
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The imports are not organized according to PEP 8 style guidelines. Standard library imports should come before third-party imports. Move import pytest above from nonebug.app import App to follow the convention: standard library, blank line, third-party, blank line, local imports.

Suggested change
from nonebug.app import App
import pytest
import pytest
from nonebug.app import App

Copilot uses AI. Check for mistakes.
Comment on lines 3 to 4
from nonebug.app import App
import pytest
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The imports are not organized according to PEP 8 style guidelines. Standard library imports should come before third-party imports. Move import pytest above from nonebug.app import App to follow the convention: standard library, blank line, third-party, blank line, local imports.

Suggested change
from nonebug.app import App
import pytest
import pytest
from nonebug.app import App

Copilot uses AI. Check for mistakes.

res = "请输入想要关联 Cookie 的平台,目前支持,请输入冒号左边的名称:\n"
state["platform_table"] = {}
for platform_name in platforms:
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The function iterates over platforms dict without sorting at line 166, while generate_cookie_target_platform_list_text uses sorted(platforms) at line 197. For consistency and better user experience, consider sorting the platforms in both functions to ensure a predictable and consistent display order.

Suggested change
for platform_name in platforms:
for platform_name in sorted(platforms):

Copilot uses AI. Check for mistakes.
Comment on lines 62 to 63
except Exception:
await add_cookie_target_matcher.reject("序号错误")
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The bare except Exception block catches all exceptions and provides a generic "序号错误" error message, which could hide other types of errors (e.g., KeyError when the index doesn't exist vs ValueError when converting to int). Consider catching specific exceptions separately to provide more helpful error messages. For instance, catch ValueError for invalid integer conversion and KeyError for missing index separately.

Suggested change
except Exception:
await add_cookie_target_matcher.reject("序号错误")
except ValueError:
# 用户输入的序号无法转换为整数
await add_cookie_target_matcher.reject("序号格式错误,请输入数字序号")
except KeyError:
# 用户输入的序号在订阅列表中不存在
await add_cookie_target_matcher.reject("序号不存在,请检查后重新输入")

Copilot uses AI. Check for mistakes.
Comment on lines +132 to +134
except Exception:
# 这里可以根据需要获取target_name,但需要额外查询
failed_targets.append(target_info["target"])
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The bare except Exception block at line 132 silently catches all exceptions during batch cookie target association. While failed targets are tracked, the specific error information is lost, making it difficult to diagnose why associations fail. Consider logging the exception or including error details in the failure report to aid debugging.

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +83
except Exception:
target_info = f"{cookie_target.target.target_name}({cookie_target.cookie.cookie_name})"
failed_targets.append(target_info)
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

Similar to the batch association code, the bare except Exception block at line 81 silently catches all exceptions during batch cookie target deletion. While failed targets are tracked, the specific error information is lost. Consider logging the exception or including error details in the failure report to aid debugging.

Copilot uses AI. Check for mistakes.
Comment on lines +117 to +119
# Values should match keys
for key, value in platforms.items():
assert key == value
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The test assertion at line 119 verifies that dictionary keys equal their values (key == value), which is testing the exact behavior noted as potentially redundant in the implementation. If the dictionary structure is intentional for future extensibility, this test is fine. However, if the dict with identical key-value pairs is not needed, this test assertion should be updated accordingly when the implementation changes.

Copilot uses AI. Check for mistakes.
return {ct.target.platform_name for ct in cookie_targets}


async def get_platform_cookie_targets(platform_name: str):
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

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

The function get_platform_cookie_targets is missing a return type annotation. Consider adding -> list or a more specific type annotation to maintain consistency with the rest of the codebase and improve code documentation.

Suggested change
async def get_platform_cookie_targets(platform_name: str):
async def get_platform_cookie_targets(platform_name: str) -> list:

Copilot uses AI. Check for mistakes.
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.

2 participants