Skip to content

feat(community): Discord 分享按 Discord id 归到本人账号 - #61

Merged
longsizhuo merged 2 commits into
mainfrom
feat/discord-share-attribution
Oct 18, 2026
Merged

longsizhuo merged 2 commits into
mainfrom
feat/discord-share-attribution

Conversation

@longsizhuo

Copy link
Copy Markdown
Member

为什么

机器人渠道以前只传分享人的 Discord 昵称,所有链接都挂在 discord-bridge 系统账号名下。昵称会改、会重名,所以对不上是谁分享的;绑定了 Discord 的人在「我的分享」里也看不到自己在群里分享的链接。

改了什么

  • shared_links 新增可空列 discord_user_id:schema.sql 里建表时就带上,再加一句 ADD COLUMN IF NOT EXISTS 兼容已有库;test-schema 同步;init.sql 本来就不建这张表。
  • InternalShareRequest 新增可选字段 discordUserId,controller 校验必须是纯数字且不超过 20 位,否则返回 400。
  • submitInternal:如果这个 Discord id 通过 user_identities 绑定到了一个可用账号,就记为 submitter;否则仍挂 discord-bridge。id 一律落库,没绑定的人以后绑定了,可以按 id 把链接改挂过去。
  • 网页每日限频(countBySubmitterSince)只数网页提交。机器人渠道本身就不限频,已绑定的人在群里分享不应该占网页配额。
  • 修正 controller 注释:这个接口其实公网可达(Caddy api 子域会兜底转发,前端也有 rewrite),唯一的防线是 X-Internal-Key。

兼容性

  • 旧版 bot 不传 discordUserId,行为和以前完全一样。
  • Jackson 默认忽略未知字段,所以新 bot 连旧后端也不会报错,两边先部署哪个都行。
  • 生产上目前只有 1 个 Discord 身份,上线后大部分分享仍会挂在 bridge 名下,但从此会把 id 存下来。

验证

  • ./mvnw -o test:353 个全部通过,其中新增 6 个集成测试,分别覆盖已绑定、未绑定、账号禁用、不传 id、id 非法、配额不受影响。
  • 按 AGENTS.md 的方法,用一次性 postgres:18 容器验证:空库依次执行 init.sql 和 schema.sql,schema.sql 连跑两遍都 exit 0;在旧版 schema 的库上执行新 schema.sql 也 exit 0,列补上了,已有行不受影响。

和 #57 只有一处文本冲突:两边在 UserIdentityService 的同一位置各加了一行 import,后合并的一方保留两行即可。

配套的 ChatBot PR:InvolutionHell/ChatBot(feat/discord-share-attribution)。

🤖 Generated with Claude Code

机器人渠道以前只传昵称,所有链接都挂在 discord-bridge 名下,昵称会改、会重名,
对不上是谁分享的,绑定了 Discord 的人也看不到自己的分享。

- shared_links 新增 discord_user_id(schema.sql 建表 + ADD COLUMN IF NOT EXISTS,
  test-schema 同步;init.sql 本来就不建这张表)
- InternalShareRequest 新增可选 discordUserId,controller 校验纯数字(≤20 位)
- submitInternal:Discord id 绑定到可用账号时记为 submitter,否则仍挂 discord-bridge;
  id 一律落库,没绑定的人日后可按 id 改挂
- 网页每日限频只数网页提交,Discord 里的分享不占配额
- 修正 controller 注释:这个接口其实公网可达,只靠 X-Internal-Key 把门

不传 discordUserId 的旧 bot 行为不变;Jackson 忽略未知字段,新 bot 配旧后端也不报错。
@longsizhuo
longsizhuo requested a balanced review from Copilot October 18, 2026 09:27

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@longsizhuo
longsizhuo merged commit 1d9ccab into main Oct 18, 2026
@longsizhuo
longsizhuo deleted the feat/discord-share-attribution branch October 18, 2026 18:39
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