feat: configure channel_id 1532999192601952266, webhook fallbacks, and safe role mentions

This commit is contained in:
Rosie Val 2026-09-24 18:44:53 -04:00
parent 4a65973d93
commit 8676075290
2 changed files with 37 additions and 21 deletions

View file

@ -54,10 +54,13 @@ jobs:
- name: Update - name: Update
env: env:
code_webhook: ${{ secrets.CODE_WEBHOOK }} code_webhook: ${{ secrets.CODE_WEBHOOK }}
color_webhook: ${{ secrets.COLOR_WEBHOOK }}
icons_webhook: ${{ secrets.ICONS_WEBHOOK }}
bot_token: ${{ secrets.BOT_TOKEN }} bot_token: ${{ secrets.BOT_TOKEN }}
channel_id: "1532999192601952266"
working-directory: main working-directory: main
run: | run: |
bun run src/update/index.ts ${{ github.event.inputs.force == 'true' && '--force' || '' }} ${{ github.event.inputs.quiet == 'true' && '--quiet' || '' }} bun run src/update/index.ts ${{ (inputs.force || github.event.inputs.force == 'true') && '--force' || '' }} ${{ (inputs.quiet || github.event.inputs.quiet == 'true') && '--quiet' || '' }}
- name: Publish changes - name: Publish changes
working-directory: data working-directory: data

View file

@ -103,7 +103,7 @@ interface WebhookEmbed {
key: string; key: string;
} }
async function sendWebhook(webhook: string, role: string, embeds: WebhookEmbed[], color?: number) { async function sendWebhook(webhook: string, role: string | undefined, embeds: WebhookEmbed[], color?: number) {
const body = new FormData(); const body = new FormData();
const images = new Map<number, string>(), const images = new Map<number, string>(),
diffs = new Map<number, string>(); diffs = new Map<number, string>();
@ -132,10 +132,14 @@ async function sendWebhook(webhook: string, role: string, embeds: WebhookEmbed[]
JSON.stringify({ JSON.stringify({
flags: MessageFlags.IsComponentsV2, flags: MessageFlags.IsComponentsV2,
components: [ components: [
{ ...(role
type: ComponentType.TextDisplay, ? [
content: `<@&${role}>`, {
}, type: ComponentType.TextDisplay,
content: `<@&${role}>`,
},
]
: []),
...embeds.map( ...embeds.map(
({ title, body, image, footer }, i) => ({ title, body, image, footer }, i) =>
({ ({
@ -177,7 +181,7 @@ async function sendWebhook(webhook: string, role: string, embeds: WebhookEmbed[]
}) as APIMessageTopLevelComponent, }) as APIMessageTopLevelComponent,
), ),
], ],
allowed_mentions: process.env.NODE_ENV === "test" ? { parse: [] } : { roles: [role] }, allowed_mentions: role && process.env.NODE_ENV !== "test" ? { roles: [role] } : { parse: [] },
} as RESTPostAPIWebhookWithTokenJSONBody), } as RESTPostAPIWebhookWithTokenJSONBody),
); );
@ -199,26 +203,37 @@ async function sendWebhook(webhook: string, role: string, embeds: WebhookEmbed[]
try { try {
const message = JSON.parse(data); const message = JSON.parse(data);
const targetChannelId = process.env.channel_id || message.channel_id || "1532999192601952266";
const messageId = message.id;
if (!targetChannelId || !messageId) return;
const route = `${RouteBases.api}/${Routes.channelMessageCrosspost(message.channel_id, message.id)}`; const route = `${RouteBases.api}/${Routes.channelMessageCrosspost(targetChannelId, messageId)}`;
await fetch(route, { await fetch(route, {
method: "POST", method: "POST",
headers: { headers: {
Authorization: discordToken, Authorization: discordToken.startsWith("Bot ") ? discordToken : `Bot ${discordToken}`,
}, },
}); });
} catch {} } catch {}
} }
export async function webhook(diffs: Differs) { export async function webhook(diffs: Differs) {
const defaultWebhook = process.env.code_webhook || process.env.color_webhook || process.env.icons_webhook;
const colorWh = process.env.color_webhook || defaultWebhook;
const iconsWh = process.env.icons_webhook || defaultWebhook;
const codeWh = process.env.code_webhook || defaultWebhook;
const colorRole = process.env.color_role;
const iconsRole = process.env.icons_role;
const codeRole = process.env.code_role;
if (diffs.raw.size || diffs.semantic.size) { if (diffs.raw.size || diffs.semantic.size) {
const wh = process.env.color_webhook; if (!colorWh) {
if (!wh) {
console.warn("Missing color_webhook, skipping color webhook"); console.warn("Missing color_webhook, skipping color webhook");
} else { } else {
await sendWebhook( await sendWebhook(
wh, colorWh,
"1227327297795657850", colorRole,
[ [
diffs.raw.size && { diffs.raw.size && {
title: "Raw colors", title: "Raw colors",
@ -241,13 +256,12 @@ export async function webhook(diffs: Differs) {
} }
if (diffs.icons.size) { if (diffs.icons.size) {
const wh = process.env.icons_webhook; if (!iconsWh) {
if (!wh) {
console.warn("Missing icons_webhook, skipping"); console.warn("Missing icons_webhook, skipping");
} else { } else {
await sendWebhook( await sendWebhook(
wh, iconsWh,
"1227327765079003217", iconsRole,
[ [
{ {
title: "Icons", title: "Icons",
@ -263,14 +277,13 @@ export async function webhook(diffs: Differs) {
} }
if (diffs.code.size) { if (diffs.code.size) {
const wh = process.env.code_webhook; if (!codeWh) {
if (!wh) {
console.warn("Missing code_webhook, skipping"); console.warn("Missing code_webhook, skipping");
return; return;
} }
await sendWebhook( await sendWebhook(
wh, codeWh,
"1233861867059941387", codeRole,
[ [
{ {
title: "Code", title: "Code",