Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
feat(discord): ping linked contributors in release announcements
leepokai1c73fa1b0539
diff --git a/.github/workflows/auto-tag.yml b/.github/workflows/auto-tag.ymlindex 5d99c206..dd71af9a 100644--- a/.github/workflows/auto-tag.yml+++ b/.github/workflows/auto-tag.yml@@ -30,6 +30,7 @@ jobs:env:GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}DISCORD_RELEASES_WEBHOOK: ${{ secrets.DISCORD_RELEASES_WEBHOOK }}+ DISCORD_MENTIONS_SECRET: ${{ secrets.DISCORD_MENTIONS_SECRET }}run: |TAG="v${{ steps.version.outputs.version }}"if git rev-parse "$TAG" >/dev/null 2>&1; then@@ -42,10 +43,17 @@ jobs:tools/release-notes.sh "$TAG" > notes.mdgh release create "$TAG" --verify-tag --title "$TAG" --notes-file notes.md --generate-notes# Announce it in the Discord server's #releases channel. A release created with- # GITHUB_TOKEN triggers no `release` workflow, so this happens here.- jq -n --arg tag "$TAG" --arg url "https://github.com/$GITHUB_REPOSITORY/releases/tag/$TAG" --rawfile notes notes.md \- '{embeds: [{title: "Codync \($tag)", url: $url, color: 16777215,- description: (if ($notes | test("\\S")) then $notes[0:4000] else "See the release notes." end)}]}' |+ # GITHUB_TOKEN triggers no `release` workflow, so this happens here. The Discord Worker turns+ # each @login linked to a member into a mention, which the message pings (discord/README.md).+ sig=$(openssl dgst -sha256 -hmac "$DISCORD_MENTIONS_SECRET" -r notes.md | cut -d' ' -f1) || true+ mentions=$(curl -fsS -X POST -H "X-Signature: $sig" --data-binary @notes.md https://discord.codync.dev/mentions) ||+ { echo "::warning::Couldn't look up Discord mentions"; mentions='{"users": []}'; }+ jq -n --arg tag "$TAG" --arg url "https://github.com/$GITHUB_REPOSITORY/releases/tag/$TAG" \+ --rawfile notes notes.md --argjson mentions "$mentions" \+ '($mentions.text // $notes) as $notes | $mentions.users as $users |+ {embeds: [{title: "Codync \($tag)", url: $url, color: 16777215,+ description: (if ($notes | test("\\S")) then $notes[0:4000] else "See the release notes." end)}]} ++ if ($users | length) > 0 then {content: ($users | map("<@\(.)>") | join(" ")), allowed_mentions: {users: $users}} else {} end' |curl -fsS -X POST -H "Content-Type: application/json" --data @- "$DISCORD_RELEASES_WEBHOOK" ||echo "::warning::Couldn't post $TAG to Discord"fidiff --git a/discord/README.md b/discord/README.mdindex 856395cb..250fca9f 100644--- a/discord/README.md+++ b/discord/README.md@@ -12,6 +12,9 @@ the GitHub roles.or role is posted to #moderator-only (no pings).4. `/webhook` takes the repo's `pull_request` and `issues` events: a linked member gets the role the momenttheir pull request merges or their issue opens.+5. `/mentions` takes release notes signed with `MENTIONS_SECRET` and turns each `@login` of a linked member into+ a Discord mention. Auto Tag (`.github/workflows/auto-tag.yml`) uses it so the #releases post pings the people+ it thanks; the links stay private.`.github/workflows/contributor.yml` comments the link on a contributor's first merged pull request and firstissue. The onboarding Server Guide has a "Link your GitHub" to-do that leads to the link in #welcome.@@ -36,6 +39,7 @@ npx wrangler secret put GITHUB_CLIENT_SECRET # the OAuth app'snpx wrangler secret put GITHUB_TOKEN # classic token, no scopes (public read only)npx wrangler secret put GITHUB_WEBHOOK_SECRET # the repo webhook'snpx wrangler secret put SESSION_SECRET # any random string (openssl rand -hex 32)+npx wrangler secret put MENTIONS_SECRET # same value as the repo secret DISCORD_MENTIONS_SECRETnpm run deploy```diff --git a/discord/src/guild.ts b/discord/src/guild.tsindex f797db23..4f51a375 100644--- a/discord/src/guild.ts+++ b/discord/src/guild.ts@@ -27,6 +27,14 @@ export async function githubLogin(env: Env, githubId: string): Promise<string> {return (await json<{ login: string }>(`https://api.github.com/user/${githubId}`, github(env))).login;}+/** The GitHub user id behind a login, or null when there's no such account. */+export async function githubId(env: Env, login: string): Promise<string | null> {+ const res = await fetch(`https://api.github.com/users/${login}`, github(env));+ if (res.status === 404) return null;+ if (!res.ok) throw new Error(`user ${login} ${res.status}: ${await res.text()}`);+ return String((await res.json<{ id: number }>()).id);+}+/** Roles the GitHub account has earned in the repo so far. */export async function earnedRoles(env: Env, login: string): Promise<Role[]> {const all = roles(env);diff --git a/discord/src/index.ts b/discord/src/index.tsindex 82e1635f..217f333d 100644--- a/discord/src/index.ts+++ b/discord/src/index.ts@@ -7,6 +7,7 @@import { DISCORD, earnedRoles, githubLogin, grant, join, names, notify, profile } from "./guild.ts";import { sign, verify } from "./hmac.ts";import { json, page } from "./http.ts";+import { mentions } from "./mentions.ts";import { webhook } from "./webhook.ts";export interface Env {@@ -18,6 +19,8 @@ export interface Env {GITHUB_TOKEN: string;GITHUB_WEBHOOK_SECRET: string;SESSION_SECRET: string;+ /** Signs the release notes Auto Tag sends to /mentions. */+ MENTIONS_SECRET: string;GUILD_ID: string;CONTRIBUTOR_ROLE_ID: string;REPORTER_ROLE_ID: string;@@ -36,6 +39,7 @@ export default {case "/callback": return await discordCallback(req, url, env);case "/github/callback": return await githubCallback(req, url, env);case "/webhook": return await webhook(req, env);+ case "/mentions": return await mentions(req, env);default: return page(404, "Not found", "");}} catch (e) {diff --git a/discord/src/mentions.ts b/discord/src/mentions.tsnew file mode 100644index 00000000..b2443adf--- /dev/null+++ b/discord/src/mentions.ts@@ -0,0 +1,30 @@+// Release notes for the #releases announcement: each `@login` whose GitHub account is linked becomes a Discord+// mention, so Auto Tag can ping the people it thanks. The links stay private: only notes signed with+// MENTIONS_SECRET are answered.++import { githubId } from "./guild.ts";+import { verify } from "./hmac.ts";+import type { Env } from "./index.ts";++// A GitHub login after a space, a line start or "(", so emails and paths don't match.+const LOGIN = /(?<=^|[\s(])@([A-Za-z0-9][A-Za-z0-9-]{0,38})(?![\w-])/gm;++export async function mentions(req: Request, env: Env): Promise<Response> {+ const text = await req.text();+ if (req.method !== "POST" || !(await verify(env.MENTIONS_SECRET, text, req.headers.get("X-Signature") ?? ""))) {+ return new Response("Bad signature", { status: 401 });+ }+ // GitHub logins ignore case.+ const logins = new Set(Array.from(text.matchAll(LOGIN), (m) => m[1].toLowerCase()));+ const ids = new Map<string, string>();+ await Promise.all([...logins].map(async (login) => {+ const github = await githubId(env, login);+ const discord = github && (await env.LINKS.get(`github:${github}`));+ if (discord) ids.set(login, discord);+ }));+ const linked = text.replace(LOGIN, (m, login: string) => {+ const id = ids.get(login.toLowerCase());+ return id ? `<@${id}>` : m;+ });+ return Response.json({ text: linked, users: [...new Set(ids.values())] });+}diff --git a/discord/test/claim.test.ts b/discord/test/claim.test.tsindex 71d53cb0..21b015ed 100644--- a/discord/test/claim.test.ts+++ b/discord/test/claim.test.ts@@ -9,7 +9,7 @@ const links = new Map<string, string>();const env = {DISCORD_CLIENT_ID: "app", DISCORD_CLIENT_SECRET: "secret", DISCORD_BOT_TOKEN: "bot",GITHUB_CLIENT_ID: "ghapp", GITHUB_CLIENT_SECRET: "ghsecret", GITHUB_TOKEN: "gh", GITHUB_WEBHOOK_SECRET: "hook",- SESSION_SECRET: "session", GUILD_ID: "guild", CONTRIBUTOR_ROLE_ID: "contributor", REPORTER_ROLE_ID: "reporter",+ SESSION_SECRET: "session", MENTIONS_SECRET: "notes", GUILD_ID: "guild", CONTRIBUTOR_ROLE_ID: "contributor", REPORTER_ROLE_ID: "reporter",STAFF_CHANNEL_ID: "staff", REPO: "leepokai/Codync",LINKS: { get: async (k: string) => links.get(k) ?? null, put: async (k: string, v: string) => void links.set(k, v) },} as never;@@ -151,4 +151,26 @@ assert.deepEqual(calls, []);calls = stub({ member: false });assert.equal(await hook("pull_request", pr(true)), 204);assert.deepEqual(calls, []);++// Release notes: linked logins become mentions, only for notes signed with the mentions secret.+links.clear();+links.set("github:7", "42");+globalThis.fetch = (async (input: string) => {+ const login = String(input).match(/\/users\/([^/]+)$/)?.[1];+ if (login === "octo") return Response.json({ id: 7 });+ if (login === "other") return Response.json({ id: 8 });+ if (login) return new Response(null, { status: 404 });+ throw new Error(`unexpected ${input}`);+}) as typeof fetch;+const notes = async (body: string, secret = "notes") => {+ const res = await worker.fetch(new Request("https://discord.test/mentions", {+ method: "POST", body, headers: { "X-Signature": await sign(secret, body) },+ }), env);+ return res.status === 200 ? res.json() : res.status;+};+assert.equal(await notes("Thanks @octo", "wrong"), 401);+assert.deepEqual(await notes("- Fast mode. Thanks @octo (#101).\n@Octo, @other, @nobody, [email protected], `@octo_x`"), {+ text: "- Fast mode. Thanks <@42> (#101).\n<@42>, @other, @nobody, [email protected], `@octo_x`",+ users: ["42"],+});console.log("claim tests ok");diff --git a/discord/wrangler.toml b/discord/wrangler.tomlindex b404e44e..fdec2552 100644--- a/discord/wrangler.toml+++ b/discord/wrangler.toml@@ -4,7 +4,7 @@ compatibility_date = "2026-09-01"routes = [{ pattern = "discord.codync.dev", custom_domain = true }]# Secrets: DISCORD_CLIENT_SECRET, DISCORD_BOT_TOKEN, GITHUB_CLIENT_SECRET, GITHUB_TOKEN, GITHUB_WEBHOOK_SECRET,-# SESSION_SECRET (see README.md).+# SESSION_SECRET, MENTIONS_SECRET (see README.md).[vars]DISCORD_CLIENT_ID = "1559877519933440084"GITHUB_CLIENT_ID = "Ov23lihjSv0zqUceCMcV"diff --git a/docs/guides/development.md b/docs/guides/development.mdindex 6e6b9521..a2dcf321 100644--- a/docs/guides/development.md+++ b/docs/guides/development.md@@ -111,7 +111,7 @@ Versions are defined in `apps/project.yml` (`MARKETING_VERSION`), `host/Cargo.to## GitHub releases-Auto Tag (`.github/workflows/auto-tag.yml`) creates each `v*` release right after pushing the tag, before the host and desktop jobs upload to it. Its description comes from `tools/release-notes.sh`: the `## Summary` of the PR that merged the version bump into `main` (or the PR's opening text without that heading), else the `feat`/`fix` commits since the previous tag, followed by GitHub's generated PR list and compare link. Write the release PR's Summary for people reading the release page. The same description is posted to the Discord server's #releases channel through the webhook in the `DISCORD_RELEASES_WEBHOOK` secret (a failed post only leaves a warning on the run).+Auto Tag (`.github/workflows/auto-tag.yml`) creates each `v*` release right after pushing the tag, before the host and desktop jobs upload to it. Its description comes from `tools/release-notes.sh`: the `## Summary` of the PR that merged the version bump into `main` (or the PR's opening text without that heading), else the `feat`/`fix` commits since the previous tag, followed by GitHub's generated PR list and compare link. Write the release PR's Summary for people reading the release page. The same description is posted to the Discord server's #releases channel through the webhook in the `DISCORD_RELEASES_WEBHOOK` secret (a failed post only leaves a warning on the run); each `@login` there whose GitHub account is linked on the Discord Worker becomes a mention that pings them (`DISCORD_MENTIONS_SECRET`, [discord/README.md](../../discord/README.md)).## iOS releases (Xcode Cloud)