Skip to content

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.

feat(discord): celebrate download milestones and ping everyone

leepokaic645f3a1e960
diff --git a/discord/README.md b/discord/README.md
index 64a0cf58..bc87fac1 100644
--- a/discord/README.md
+++ b/discord/README.md
@@ -15,9 +15,12 @@ the GitHub roles.
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.
-6. `/webhook` also takes the repo's `star` events: each 100th star posts once in #milestones, with progress
- toward `STAR_GOAL` and one-click links to share Codync on X, Threads, Reddit and LinkedIn. The last milestone
- posted is kept in KV (`stars:milestone`), so unstarring and starring again doesn't repeat it.
+6. Milestones go to #milestones, each once and with `@everyone`, with progress toward the goal and one-click
+ links to share Codync on X, Threads, Reddit and LinkedIn: every 100th star (`/webhook` takes the repo's
+ `star` events; goal `STAR_GOAL`) and every 1,000th desktop app download (GitHub has no download event, so a
+ daily cron sums the installer downloads of every release: `.dmg`, `.exe`, `.AppImage`, `.deb`, `.rpm`,
+ desktop Linux `.tar.gz`; goal `DOWNLOAD_GOAL`). The last milestone posted is kept in KV (`stars:milestone`,
+ `downloads:milestone`), so a count that dips and climbs back doesn't repeat it.
`.github/workflows/contributor.yml` comments the link on a contributor's first merged pull request and first
issue. The onboarding Server Guide has a "Link your GitHub" to-do that leads to the link in #welcome.
@@ -26,13 +29,14 @@ issue. The onboarding Server Guide has a "Link your GitHub" to-do that leads to
- Discord application **Codync** (Developer Portal): OAuth2 redirect `https://discord.codync.dev/callback`; bot
not public. In the server, its role keeps Manage Roles and Create Invite (`guilds.join` needs it), sits above
- Contributor and Reporter, and can view and send in #moderator-only and #milestones (read-only for everyone else).
+ Contributor and Reporter, and can view and send in #moderator-only and #milestones (read-only for everyone
+ else), where it may also mention @everyone.
- GitHub OAuth app **Codync Discord** (leepokai's developer settings): callback
`https://discord.codync.dev/github/callback`, no scopes requested.
- Repo webhook: `https://discord.codync.dev/webhook`, JSON, events `pull_request`, `issues` and `star`, secret =
`GITHUB_WEBHOOK_SECRET`.
-- `wrangler.toml` holds the public values (client ids, guild, role and channel ids, star goal, repo) and the `LINKS` KV
- namespace.
+- `wrangler.toml` holds the public values (client ids, guild, role and channel ids, milestone goals, repo), the
+ daily cron and the `LINKS` KV namespace.
```bash
npm ci
diff --git a/discord/src/guild.ts b/discord/src/guild.ts
index 3f3541a3..ac72731f 100644
--- a/discord/src/guild.ts
+++ b/discord/src/guild.ts
@@ -20,7 +20,7 @@ export const names = (list: Role[]) => list.map((r) => r.name).join(" and ");
export const profile = (login: string) => `[${login}](https://github.com/${login})`;
const bot = (env: Env) => ({ Authorization: `Bot ${env.DISCORD_BOT_TOKEN}` });
-const github = (env: Env) => ({ headers: { Authorization: `Bearer ${env.GITHUB_TOKEN}`, "User-Agent": "codync-discord" } });
+export const github = (env: Env) => ({ headers: { Authorization: `Bearer ${env.GITHUB_TOKEN}`, "User-Agent": "codync-discord" } });
/** The account's current login; names in connections go stale after a rename, ids don't. */
export async function githubLogin(env: Env, githubId: string): Promise<string> {
@@ -71,13 +71,16 @@ export async function grant(env: Env, discordId: string, earned: Role[], reason:
return missing;
}
-/** Posts to a channel and says whether it went out. A failure is logged and never fails the caller's flow. */
-export async function send(env: Env, channelId: string, content: string): Promise<boolean> {
+/**
+ * Posts to a channel and says whether it went out. A failure is logged and never fails the caller's flow.
+ * Only the mention kinds in `pings` notify anyone (none by default).
+ */
+export async function send(env: Env, channelId: string, content: string, pings: "everyone"[] = []): Promise<boolean> {
const res = await fetch(`${DISCORD}/channels/${channelId}/messages`, {
method: "POST",
headers: { ...bot(env), "Content-Type": "application/json" },
- // No pings; flag 4 drops link previews.
- body: JSON.stringify({ content, allowed_mentions: { parse: [] }, flags: 4 }),
+ // Flag 4 drops link previews.
+ body: JSON.stringify({ content, allowed_mentions: { parse: pings }, flags: 4 }),
});
if (!res.ok) console.error("send failed", { channel: channelId, status: res.status, body: await res.text() });
return res.ok;
diff --git a/discord/src/index.ts b/discord/src/index.ts
index 03b02b0b..0c8d8950 100644
--- a/discord/src/index.ts
+++ b/discord/src/index.ts
@@ -2,12 +2,13 @@
// their GitHub account comes from their Discord connections (verified by Discord) or, when they have none, from
// signing in with GitHub, so nobody can claim someone else's. A merged pull request on the repo earns the
// Contributor role, an opened issue the Reporter role. The link is remembered, so later ones arrive on their
-// own (webhook.ts).
+// own (webhook.ts). Star and download milestones are posted in #milestones (milestones.ts).
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 { celebrate, downloads } from "./milestones.ts";
import { webhook } from "./webhook.ts";
export interface Env {
@@ -26,10 +27,11 @@ export interface Env {
REPORTER_ROLE_ID: string;
STAFF_CHANNEL_ID: string;
MILESTONES_CHANNEL_ID: string;
- /** The star count the #milestones posts count toward. */
+ /** The counts the #milestones posts count toward. */
STAR_GOAL: string;
+ DOWNLOAD_GOAL: string;
REPO: string;
- /** `github:<GitHub user id>` → Discord user id; `stars:milestone` → the last star milestone posted. */
+ /** `github:<GitHub user id>` → Discord user id; `<stars|downloads>:milestone` → the last milestone posted. */
LINKS: KVNamespace;
}
@@ -50,6 +52,11 @@ export default {
return page(502, "Something went wrong", "Try again in a minute.");
}
},
+
+ // Daily (wrangler.toml): GitHub has no download event, so the count is polled.
+ async scheduled(_controller: ScheduledController, env: Env): Promise<void> {
+ await celebrate(env, "downloads", await downloads(env));
+ },
};
const expired = () => page(400, "This link expired", "Open discord.codync.dev again.");
diff --git a/discord/src/milestones.ts b/discord/src/milestones.ts
new file mode 100644
index 00000000..6109fb51
--- /dev/null
+++ b/discord/src/milestones.ts
@@ -0,0 +1,82 @@
+// Milestones in #milestones, each posted once with @everyone and the way left to the goal: every 100th GitHub
+// star (from the repo webhook) and every 1,000th download of the desktop app (counted once a day).
+
+import { github, send } from "./guild.ts";
+import { json } from "./http.ts";
+import type { Env } from "./index.ts";
+
+export type Kind = "stars" | "downloads";
+
+const KINDS: Record<Kind, { step: number; goal: (env: Env) => string; emoji: string; label: string; thanks: (repo: string) => string }> = {
+ stars: {
+ step: 100,
+ goal: (env) => env.STAR_GOAL,
+ emoji: "⭐",
+ label: "stars on GitHub",
+ thanks: (repo) => `Thanks to everyone who starred [${repo}](https://github.com/${repo}) 💛`,
+ },
+ downloads: {
+ step: 1000,
+ goal: (env) => env.DOWNLOAD_GOAL,
+ emoji: "📦",
+ label: "downloads",
+ thanks: () => "Thanks to everyone who gave it a try 💛",
+ },
+};
+const BAR = 20;
+
+/** Posts the milestone the count has reached, once: a count that dips and climbs back (an unstar) doesn't repeat it. */
+export async function celebrate(env: Env, kind: Kind, count: number): Promise<void> {
+ const { step } = KINDS[kind];
+ const milestone = Math.floor(count / step) * step;
+ const key = `${kind}:milestone`;
+ const last = Number((await env.LINKS.get(key)) ?? 0);
+ if (milestone <= last) return;
+ // ponytail: KV isn't atomic, so two stars delivered at the same instant on a new milestone could post it twice.
+ if (await send(env, env.MILESTONES_CHANNEL_ID, milestoneMessage(kind, milestone, Number(KINDS[kind].goal(env)), env.REPO), ["everyone"])) {
+ await env.LINKS.put(key, String(milestone));
+ console.log("milestone", { kind, milestone });
+ }
+}
+
+// Installers people download from the site or the releases page; updater files, checksums and host tarballs
+// aren't someone new trying Codync.
+const INSTALLER = /\.(dmg|exe|appimage|deb|rpm)$|^codync-linux-.*\.tar\.gz$/i;
+
+/** Desktop app downloads across every release. */
+export async function downloads(env: Env): Promise<number> {
+ let total = 0;
+ for (let page = 1; ; page++) {
+ const releases = await json<{ assets: { name: string; download_count: number }[] }[]>(
+ `https://api.github.com/repos/${env.REPO}/releases?per_page=100&page=${page}`, github(env));
+ for (const { assets } of releases) {
+ total += assets.filter((a) => INSTALLER.test(a.name)).reduce((sum, a) => sum + a.download_count, 0);
+ }
+ if (releases.length < 100) return total;
+ }
+}
+
+const PITCH = "Codync: your coding agents, as teammates you can message. Free and open source.";
+
+/** One-click posts about Codync on the usual social platforms, linking the repo. */
+function shareLinks(url: string): string {
+ const q = (params: Record<string, string>) => new URLSearchParams(params).toString().replaceAll("+", "%20");
+ return [
+ `[X](https://x.com/intent/post?${q({ text: PITCH, url })})`,
+ `[Threads](https://www.threads.net/intent/post?${q({ text: `${PITCH} ${url}` })})`,
+ `[Reddit](https://www.reddit.com/submit?${q({ url, title: PITCH })})`,
+ `[LinkedIn](https://www.linkedin.com/sharing/share-offsite/?${q({ url })})`,
+ ].join(" · ");
+}
+
+export function milestoneMessage(kind: Kind, count: number, goal: number, repo: string): string {
+ const { step, emoji, label, thanks } = KINDS[kind];
+ const n = (x: number) => x.toLocaleString("en-US");
+ const head = count >= goal && count - step < goal
+ ? `🎉 **Codync hit ${n(count)} ${label}, goal reached!**`
+ : `${emoji} **Codync just hit ${n(count)} ${label}!**`;
+ const filled = Math.round((count / goal) * BAR);
+ const progress = count < goal ? `\n\`${"█".repeat(filled)}${"░".repeat(BAR - filled)}\` ${n(count)} / ${n(goal)}` : "";
+ const ask = count < goal ? `Help us reach ${n(goal)}: tell people about Codync` : "Keep spreading the word";
+ return `@everyone ${head}${progress}\n${thanks(repo)}\n\n📣 ${ask} on ${shareLinks(`https://github.com/${repo}`)}, or wherever you hang out.`;
+}
diff --git a/discord/src/stars.ts b/discord/src/stars.ts
deleted file mode 100644
index b090ece8..00000000
--- a/discord/src/stars.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-// Star milestones: every 100th star on the repo gets one post in #milestones, with the way left to the goal.
-
-import { send } from "./guild.ts";
-import type { Env } from "./index.ts";
-
-const STEP = 100;
-const BAR = 20;
-const KEY = "stars:milestone";
-
-/** Posts the milestone the star count has reached, once: unstarring and starring again doesn't repeat it. */
-export async function celebrate(env: Env, stars: number): Promise<void> {
- const milestone = Math.floor(stars / STEP) * STEP;
- const last = Number((await env.LINKS.get(KEY)) ?? 0);
- if (milestone <= last) return;
- // ponytail: KV isn't atomic, so two stars delivered at the same instant on a new milestone could post it twice.
- if (await send(env, env.MILESTONES_CHANNEL_ID, milestoneMessage(milestone, Number(env.STAR_GOAL), env.REPO))) {
- await env.LINKS.put(KEY, String(milestone));
- console.log("star milestone", { stars: milestone });
- }
-}
-
-const PITCH = "Codync: your coding agents, as teammates you can message. Free and open source.";
-
-/** One-click posts about Codync on the usual social platforms, linking the repo. */
-function shareLinks(url: string): string {
- const q = (params: Record<string, string>) => new URLSearchParams(params).toString().replaceAll("+", "%20");
- return [
- `[X](https://x.com/intent/post?${q({ text: PITCH, url })})`,
- `[Threads](https://www.threads.net/intent/post?${q({ text: `${PITCH} ${url}` })})`,
- `[Reddit](https://www.reddit.com/submit?${q({ url, title: PITCH })})`,
- `[LinkedIn](https://www.linkedin.com/sharing/share-offsite/?${q({ url })})`,
- ].join(" · ");
-}
-
-export function milestoneMessage(stars: number, goal: number, repo: string): string {
- const n = (x: number) => x.toLocaleString("en-US");
- const url = `https://github.com/${repo}`;
- const head = stars >= goal && stars - STEP < goal
- ? `🎉 **Codync hit ${n(stars)} stars on GitHub, goal reached!**`
- : `⭐ **Codync just hit ${n(stars)} stars on GitHub!**`;
- const filled = Math.round((stars / goal) * BAR);
- const progress = stars < goal ? `\n\`${"█".repeat(filled)}${"░".repeat(BAR - filled)}\` ${n(stars)} / ${n(goal)}` : "";
- const ask = stars < goal ? `Help us reach ${n(goal)}: tell people about Codync` : "Keep spreading the word";
- return `${head}${progress}\nThanks to everyone who starred [${repo}](${url}) 💛\n\n📣 ${ask} on ${shareLinks(url)}, or wherever you hang out.`;
-}
diff --git a/discord/src/webhook.ts b/discord/src/webhook.ts
index 56bed2a9..36cd468c 100644
--- a/discord/src/webhook.ts
+++ b/discord/src/webhook.ts
@@ -4,7 +4,7 @@
import { grant, notify, profile, roles, type Role } from "./guild.ts";
import { verify } from "./hmac.ts";
import type { Env } from "./index.ts";
-import { celebrate } from "./stars.ts";
+import { celebrate } from "./milestones.ts";
interface Item {
number: number;
@@ -30,7 +30,7 @@ export async function webhook(req: Request, env: Env): Promise<Response> {
const event = req.headers.get("X-GitHub-Event");
const payload = JSON.parse(body) as Payload;
if (event === "star" && payload.action === "created" && payload.repository) {
- await celebrate(env, payload.repository.stargazers_count);
+ await celebrate(env, "stars", payload.repository.stargazers_count);
return done();
}
const earned = earnedBy(event, payload, env);
diff --git a/discord/test/claim.test.ts b/discord/test/claim.test.ts
index 9b351881..43d2fbac 100644
--- a/discord/test/claim.test.ts
+++ b/discord/test/claim.test.ts
@@ -10,7 +10,7 @@ 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", MENTIONS_SECRET: "notes", GUILD_ID: "guild", CONTRIBUTOR_ROLE_ID: "contributor", REPORTER_ROLE_ID: "reporter",
- STAFF_CHANNEL_ID: "staff", MILESTONES_CHANNEL_ID: "milestones", STAR_GOAL: "1000", REPO: "leepokai/Codync",
+ STAFF_CHANNEL_ID: "staff", MILESTONES_CHANNEL_ID: "milestones", STAR_GOAL: "1000", DOWNLOAD_GOAL: "10000", 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;
@@ -173,13 +173,20 @@ assert.deepEqual(await notes("- Fast mode. Thanks @octo (#101).\n@Octo, @other,
text: "- Fast mode. Thanks <@42> (#101).\n<@42>, @other, @nobody, [email protected], `@octo_x`",
users: ["42"],
});
-// Stars: each 100th star posts once in #milestones, with progress toward the goal until it's reached.
+// Milestones: each 100th star and 1,000th download posts once in #milestones and pings everyone, with progress
+// toward the goal until it's reached.
const posts: string[] = [];
let up = true;
+let releases: object[][] = [];
globalThis.fetch = (async (input: string, init?: RequestInit) => {
- assert.equal(String(input), "https://discord.com/api/v10/channels/milestones/messages");
+ const url = String(input);
+ const page = url.match(/^https:\/\/api\.github\.com\/repos\/leepokai\/Codync\/releases\?per_page=100&page=(\d+)$/)?.[1];
+ if (page) return Response.json(releases[Number(page) - 1] ?? []);
+ assert.equal(url, "https://discord.com/api/v10/channels/milestones/messages");
if (!up) return new Response("down", { status: 503 });
- posts.push(JSON.parse(String(init?.body)).content);
+ const body = JSON.parse(String(init?.body));
+ assert.deepEqual(body.allowed_mentions, { parse: ["everyone"] });
+ posts.push(body.content);
return Response.json({});
}) as typeof fetch;
const star = (count: number, action = "created") => hook("star", { action, repository: { stargazers_count: count } });
@@ -193,9 +200,28 @@ up = true;
for (const count of [402, 401, 400, 450, 1000, 1000, 1104]) assert.equal(await star(count), 204);
const thanks = "Thanks to everyone who starred [leepokai/Codync](https://github.com/leepokai/Codync) 💛\n\n📣 ";
assert.equal(posts.length, 3);
-assert.ok(posts[0].startsWith(`⭐ **Codync just hit 400 stars on GitHub!**\n\`████████░░░░░░░░░░░░\` 400 / 1,000\n${thanks}Help us reach 1,000: tell people about Codync on [X](https://x.com/intent/post?text=Codync%3A%20`));
-assert.ok(posts[1].startsWith(`🎉 **Codync hit 1,000 stars on GitHub, goal reached!**\n${thanks}Keep spreading the word on [X](`));
-assert.ok(posts[2].startsWith(`⭐ **Codync just hit 1,100 stars on GitHub!**\n${thanks}Keep spreading the word on [X](`));
+assert.ok(posts[0].startsWith(`@everyone ⭐ **Codync just hit 400 stars on GitHub!**\n\`████████░░░░░░░░░░░░\` 400 / 1,000\n${thanks}Help us reach 1,000: tell people about Codync on [X](https://x.com/intent/post?text=Codync%3A%20`));
+assert.ok(posts[1].startsWith(`@everyone 🎉 **Codync hit 1,000 stars on GitHub, goal reached!**\n${thanks}Keep spreading the word on [X](`));
+assert.ok(posts[2].startsWith(`@everyone ⭐ **Codync just hit 1,100 stars on GitHub!**\n${thanks}Keep spreading the word on [X](`));
assert.match(posts[0], /\[Threads\]\(.+\) · \[Reddit\]\(.+url=https%3A%2F%2Fgithub.com%2Fleepokai%2FCodync.+\) · \[LinkedIn\]\(.+\), or wherever you hang out\.$/);
assert.equal(links.get("stars:milestone"), "1100");
+
+// Downloads count installers across every release page, not updater files, checksums or host tarballs.
+posts.length = 0;
+const asset = (name: string, download_count: number) => ({ name, download_count });
+const release = (...assets: object[]) => ({ assets });
+releases = [
+ Array.from({ length: 100 }, (_, i) => release(asset("codync-macos.dmg", i === 0 ? 900 : 0), asset("latest-mac.yml", 5000))),
+ [release(asset("codync-windows-x64.exe", 80), asset("codync-windows-x64.exe.blockmap", 999), asset("codync-linux-x86_64.AppImage", 15),
+ asset("codync-linux-arm64.tar.gz", 4), asset("codync-host-linux-x86_64.tar.gz", 999), asset("codync-macos.zip", 999))],
+];
+const cron = () => worker.scheduled({} as ScheduledController, env);
+await cron();
+assert.deepEqual(posts, []);
+releases[1].push(release(asset("codync-linux-x86_64.deb", 1)));
+await cron();
+await cron();
+assert.equal(posts.length, 1);
+assert.ok(posts[0].startsWith("@everyone 📦 **Codync just hit 1,000 downloads!**\n`██░░░░░░░░░░░░░░░░░░` 1,000 / 10,000\nThanks to everyone who gave it a try 💛\n\n📣 Help us reach 10,000:"));
+assert.equal(links.get("downloads:milestone"), "1000");
console.log("claim tests ok");
diff --git a/discord/wrangler.toml b/discord/wrangler.toml
index 9bf10df0..60293f3e 100644
--- a/discord/wrangler.toml
+++ b/discord/wrangler.toml
@@ -3,6 +3,10 @@ main = "src/index.ts"
compatibility_date = "2026-09-01"
routes = [{ pattern = "discord.codync.dev", custom_domain = true }]
+# Daily download count for the #milestones posts (01:00 UTC, 09:00 in Taiwan).
+[triggers]
+crons = ["0 1 * * *"]
+
# Secrets: DISCORD_CLIENT_SECRET, DISCORD_BOT_TOKEN, GITHUB_CLIENT_SECRET, GITHUB_TOKEN, GITHUB_WEBHOOK_SECRET,
# SESSION_SECRET, MENTIONS_SECRET (see README.md).
[vars]
@@ -14,6 +18,7 @@ REPORTER_ROLE_ID = "1559885097535148133"
STAFF_CHANNEL_ID = "1559451211860672512"
MILESTONES_CHANNEL_ID = "1560254402168758403"
STAR_GOAL = "1000"
+DOWNLOAD_GOAL = "10000"
REPO = "leepokai/Codync"
[[kv_namespaces]]