feat(groups): optional forge source label in message footers

- Group.forgeLabel (default off, editable per group in the console) shows the
  source forge on every message the group's routes dispatch
- Discord embed footer: forge name next to the repo + the site's favicon as
  icon_url (Gitea instance's own favicon from its origin)
- Telegram footer: hyperlinked site name (GitHub or Gitea hostname); custom
  webhooks render a plain 'Custom' label
- forgeInfo() derives branding from event.provider + repository.html_url;
  dispatch attaches it to the NeutralMessage like mentionRoleIds
- validateGroups accepts forgeLabel booleans; GroupEditor gains the toggle
- tests: forgeInfo unit, discord/telegram footer render, dispatch on/off
- docs: groups.md + message-format.md (en/zh), config.example.yaml, AGENTS.md
- fix: wrangler.jsonc compatibility_date was an incomplete '2026-'
This commit is contained in:
RhenCloud 2026-08-14 08:10:04 +08:00
parent a5324fb0ea
commit 3dce114cec
No known key found for this signature in database
GPG key ID: A574A617378C4E0B
19 changed files with 273 additions and 16 deletions

View file

@ -1,4 +1,4 @@
import type { NeutralMessage } from "../types";
import type { NeutralForge, NeutralMessage, WebhookEvent } from "../types";
import { t as translate } from "../lib/i18n";
import type { Translations } from "../lib/i18n";
@ -160,3 +160,29 @@ export function senderProfileUrl(repoUrl: string | undefined, login: string): st
}
return `https://github.com/${login}`;
}
/**
* Forge branding for an event (used when the group enables `forgeLabel`):
* GitHub gets its brand + favicon, Gitea the instance hostname + favicon
* derived from the repository URL, custom webhooks a plain "Custom" label.
*/
export function forgeInfo(event: WebhookEvent): NeutralForge | undefined {
const repoUrl = (event.payload.repository as { html_url?: string } | undefined)?.html_url;
switch (event.provider) {
case "github":
return { name: "GitHub", url: "https://github.com", iconUrl: "https://github.com/favicon.ico" };
case "gitea": {
if (!repoUrl) return undefined;
try {
const origin = new URL(repoUrl).origin;
return { name: new URL(origin).hostname, url: origin, iconUrl: `${origin}/favicon.ico` };
} catch {
return undefined;
}
}
case "custom":
return { name: "Custom" };
default:
return undefined;
}
}