diff --git a/README.md b/README.md index ca306c0..abdd267 100644 --- a/README.md +++ b/README.md @@ -167,10 +167,10 @@ Add the bot to your server with the `bot` scope and the following permissions: Combined permission integer: `274877910016` -Invite URL (replace `CLIENT_ID` with your bot's client ID): +Invite URL (replace `CLIENT_ID` with your bot's client ID). The `applications.commands` scope is required so the slash / context-menu commands can be registered: ``` -https://discord.com/oauth2/authorize?client_id=YOUR_BOT_CLIENT_ID&permissions=274877910016&scope=bot +https://discord.com/oauth2/authorize?client_id=YOUR_BOT_CLIENT_ID&permissions=274877910016&scope=bot+applications.commands ``` ### Intents @@ -184,24 +184,38 @@ The Discord Gateway connection only keeps the bot showing as **online** — it i - `DISCORD_GATEWAY_ENABLED=false` (default): messages are sent directly via REST; the Gateway is not connected. - `DISCORD_GATEWAY_ENABLED=true`: the Durable Object connects to the Gateway to keep the bot online; messages are still sent via REST. -### Bot Command (`!gh`) +### Bot Commands (comment on GitHub as yourself) -When the Gateway is enabled, reply (quote) a bot-issued issue / PR notification and type: +When the Gateway is enabled, the bot registers native **slash** and **message context-menu** commands per guild on connect. Comments are posted using **your own** linked GitHub account (OAuth), and permission is delegated to GitHub — if GitHub rejects the action (e.g. editing someone else's comment) the bot tells you so. All replies are ephemeral (only you see them). + +**1. Link your account** (once): ``` -!gh +/gh login → returns an ephemeral link to authorize your GitHub account +/gh logout → unlink your GitHub account ``` -The bot posts the text as a GitHub comment on that issue / PR (authenticated as the GitHub App). +**2. Add / edit / delete a comment** — two equivalent ways: -**Extra requirements:** +- **Right-click a notification** (recommended): right-click a bot-issued issue / PR / comment notification → **Apps** → **GitHub: 添加评论 / 编辑评论 / 删除评论**. The target is auto-extracted from the notification embed; no link needed. +- **Slash command with a link**: -| Item | How | -| ----------------- | ----------------------------------------------------------------------------------------- | -| Gateway enabled | `DISCORD_GATEWAY_ENABLED=true` | -| Privileged intent | Enable **Message Content** in Discord Developer Portal → Bot → Privileged Gateway Intents | -| Permissions | **Read Message History** (to read the quoted message) in addition to sending | -| GitHub App | Installed on the repo with **Issues (write)** permission | + ``` + /gh comment add link: e.g. https://github.com/owner/repo/issues/123 + /gh comment edit link: url must contain #issuecomment- + /gh comment del link: url must contain #issuecomment- + ``` + + For `edit` / `del`, copy the specific comment link on GitHub (comment ⋯ menu → **Copy link**). `add` / `edit` open a modal to enter/adjust the comment body (prefilled for edit). + +**Requirements:** + +| Item | How | +| --------------- | --------------------------------------------------------------------- | +| Gateway enabled | `DISCORD_GATEWAY_ENABLED=true` (interactions arrive over the Gateway) | +| Invite scope | Bot invited with `applications.commands` (see invite URL above) | +| OAuth | `GITHUB_CLIENT_ID` / `GITHUB_CLIENT_SECRET` and `BASE_URL` configured | +| User linked | Each user runs `/gh login` first | ## Deployment diff --git a/README.zh.md b/README.zh.md index a446268..e0b2110 100644 --- a/README.zh.md +++ b/README.zh.md @@ -166,10 +166,10 @@ npx wrangler dev # 启动本地开发服务器 权限组合整数值:`274877910016` -邀请链接(将 `CLIENT_ID` 替换为机器人的 Client ID): +邀请链接(将 `CLIENT_ID` 替换为机器人的 Client ID)。需要 `applications.commands` scope,否则无法注册斜杠 / 右键菜单命令: ``` -https://discord.com/oauth2/authorize?client_id=你的机器人CLIENT_ID&permissions=274877910016&scope=bot +https://discord.com/oauth2/authorize?client_id=你的机器人CLIENT_ID&permissions=274877910016&scope=bot+applications.commands ``` ### Intents @@ -183,24 +183,38 @@ Discord Gateway 连接仅用于让 bot 显示为**在线**——发送消息** - `DISCORD_GATEWAY_ENABLED=false`(默认):直接通过 REST 发送消息,不建立 Gateway 连接。 - `DISCORD_GATEWAY_ENABLED=true`:由 Durable Object 连接 Gateway 以维持 bot 在线状态;消息仍走 REST。 -### Bot 指令(`!gh`) +### Bot 指令(以本人身份评论 GitHub) -启用 Gateway 后,**引用(回复)**一条 bot 推送的 issue / PR 通知,然后输入: +启用 Gateway 后,bot 会在连接时为每个服务器注册原生的**斜杠命令**与**消息右键菜单命令**。评论以**你本人**绑定的 GitHub 账号(OAuth)发出,权限交由 GitHub 判定——若 GitHub 拒绝(例如去修改他人评论),bot 会提示你无权限。所有回复均为 ephemeral(仅你可见)。 + +**1. 绑定账号**(一次即可): ``` -!gh <评论内容> +/gh login → 返回一个 ephemeral 授权链接,用于绑定你的 GitHub 账号 +/gh logout → 解除绑定 ``` -bot 会以 GitHub App 的身份把内容发为对该 issue / PR 的评论。 +**2. 添加 / 编辑 / 删除评论** —— 两种等价方式: -**额外要求:** +- **右键点击通知**(推荐):右键一条 bot 推送的 issue / PR / 评论通知 → **应用(Apps)** → **GitHub: 添加评论 / 编辑评论 / 删除评论**。目标会从通知 embed 中自动提取,无需粘贴链接。 +- **斜杠命令 + 链接**: -| 项目 | 说明 | -| ------------ | --------------------------------------------------------------------------------------- | -| 启用 Gateway | `DISCORD_GATEWAY_ENABLED=true` | -| 特权 intent | 在 Discord Developer Portal → Bot → Privileged Gateway Intents 开启 **Message Content** | -| 权限 | 除发送外还需 **Read Message History**(读取被引用的消息) | -| GitHub App | 已安装到该仓库且有 **Issues (write)** 权限 | + ``` + /gh comment add link: 例如 https://github.com/owner/repo/issues/123 + /gh comment edit link:<评论链接> 链接需包含 #issuecomment- + /gh comment del link:<评论链接> 链接需包含 #issuecomment- + ``` + + `edit` / `del` 需要具体的评论链接(在 GitHub 上:评论 ⋯ 菜单 → **Copy link**)。`add` / `edit` 会弹出 modal 让你输入 / 修改评论内容(编辑时预填原文)。 + +**要求:** + +| 项目 | 说明 | +| ------------ | ---------------------------------------------------------------- | +| 启用 Gateway | `DISCORD_GATEWAY_ENABLED=true`(交互通过 Gateway 送达) | +| 邀请 scope | 邀请时带上 `applications.commands`(见上方邀请链接) | +| OAuth | 已配置 `GITHUB_CLIENT_ID` / `GITHUB_CLIENT_SECRET` 与 `BASE_URL` | +| 用户绑定 | 每个用户先执行 `/gh login` | ## 部署