Skip to content

feat(platform): 支持扫码创建时自定义机器人ID#9067

Open
NayukiChiba wants to merge 2 commits into
AstrBotDevs:masterfrom
NayukiChiba:feat/custom-scan-platform-id
Open

feat(platform): 支持扫码创建时自定义机器人ID#9067
NayukiChiba wants to merge 2 commits into
AstrBotDevs:masterfrom
NayukiChiba:feat/custom-scan-platform-id

Conversation

@NayukiChiba

@NayukiChiba NayukiChiba commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Modifications / 改动点

  • 在扫码创建平台机器人时新增机器人 ID 输入框,允许用户在创建前自定义平台 ID。
  • 输入框展示在二维码上方,并对空值、空格、冒号和感叹号进行校验。
  • 用户手动填写 ID 后,扫码结果不会再自动覆盖该值。
  • 同时补充中英俄三语言文案。

refs #9057

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

image image

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Add customizable platform ID input when creating bots via QR-code scanning and prevent auto-overwriting once manually set.

New Features:

  • Allow users to specify a custom platform ID via a text field when creating platform bots using scan-based registration for multiple platforms.

Enhancements:

  • Validate scanned platform IDs for emptiness and disallowed characters and adjust the registration UI layout to accommodate the new input field.
  • Preserve user-entered platform IDs by skipping automatic ID updates from scan results once the ID has been customized.

Documentation:

  • Add localized labels and validation messages for the platform ID field in English, Chinese, and Russian.

- 在扫码创建平台机器人时新增机器人 ID 输入框,允许用户在创建前自定义平台 ID。
- 输入框展示在二维码上方,并对空值、空格、冒号和感叹号进行校验。
- 用户手动填写 ID 后,扫码结果不会再自动覆盖该值。
- 同时补充中英俄三语言文案。
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. labels Jun 28, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces a customizable Bot ID input field for Lark, DingTalk, QQ Official, and WeChat OC platforms during QR setup. The feedback highlights several improvement opportunities: removing .trim() from the input handler to prevent cursor jumps and allow validation of trailing spaces, reusing the existing isPlatformIdValid helper instead of duplicating the validation regex, and consolidating the duplicate CSS classes .weixin-oc-registration-inline and .registration-inline to reduce redundancy.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +1528 to +1534
setScanPlatformId(value) {
if (!this.selectedPlatformConfig) {
return;
}
this.scanPlatformIdCustomized = true;
this.selectedPlatformConfig.id = String(value || "").trim();
},

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.

medium

在用户输入过程中,使用 .trim() 会导致无法在输入框末尾输入空格(输入空格会被立即清除,从而可能导致光标跳转或无法触发“不能包含空格”的校验提示)。建议移除 .trim(),让校验器(scanPlatformIdError)来处理空格校验,或者仅在保存时进行 trim 处理。

    setScanPlatformId(value) {
      if (!this.selectedPlatformConfig) {
        return;
      }
      this.scanPlatformIdCustomized = true;
      this.selectedPlatformConfig.id = String(value || "");
    },

Comment on lines +1097 to +1106
scanPlatformIdError() {
const platformId = String(this.selectedPlatformConfig?.id || "");
if (!platformId) {
return this.tm("registrationAction.platformIdRequired");
}
if (/[!:\s]/.test(platformId)) {
return this.tm("registrationAction.platformIdInvalid");
}
return "";
},

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.

medium

建议复用已有的 isPlatformIdValid 方法来进行格式校验,避免重复编写 /[!:\s]/ 正则表达式,提高代码的可维护性。

    scanPlatformIdError() {
      const platformId = String(this.selectedPlatformConfig?.id || "");
      if (!platformId) {
        return this.tm("registrationAction.platformIdRequired");
      }
      if (!this.isPlatformIdValid(platformId)) {
        return this.tm("registrationAction.platformIdInvalid");
      }
      return "";
    },

@@ -230,6 +263,17 @@
v-else-if="isWeixinOcPlatform"
class="weixin-oc-registration-inline mt-4"

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.

medium

由于 .weixin-oc-registration-inline.registration-inline 的样式完全相同,建议直接复用 .registration-inline,以减少冗余的 CSS 定义。

                    class="registration-inline mt-4"

Comment on lines +2041 to +2049

.weixin-oc-registration-inline {
display: flex;
flex-direction: column;
align-items: flex-start;
width: 320px;
gap: 8px;
}

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.

medium

由于 .weixin-oc-registration-inline 的样式与 .registration-inline 完全一致,且在模板中已统一替换为 .registration-inline,因此可以安全地删除此处的冗余样式定义。



@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've left some high level feedback:

  • The platform ID input field markup is duplicated across multiple scan blocks; consider extracting it into a small reusable component or a shared template fragment to keep the template DRY and easier to maintain.
  • The CSS for .registration-inline and .weixin-oc-registration-inline is almost identical; consolidating these into a single shared class (with modifiers if needed) would reduce style duplication and make layout changes simpler.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The platform ID input field markup is duplicated across multiple scan blocks; consider extracting it into a small reusable component or a shared template fragment to keep the template DRY and easier to maintain.
- The CSS for `.registration-inline` and `.weixin-oc-registration-inline` is almost identical; consolidating these into a single shared class (with modifiers if needed) would reduce style duplication and make layout changes simpler.

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.

- 将平台专属CSS类名改为通用名称registration-inline
- 使用统一的isPlatformIdValid方法校验ID格式,替代分散的正则判断
- 移除setter中对platform ID的trim操作,交由校验逻辑处理
- 删除不再使用的.weixin-oc-registration-inline样式定义
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant