From 9b6935314d7c9a0f1913b9041da61b33dc2764bc Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Mon, 5 Oct 2026 03:37:15 -0400 Subject: [PATCH] feat(bot): auto-mention a role in /announce when unset Adds DISCORD_ANNOUNCE_MENTION_ROLE_ID; when set, /announce without a message (compose dialog) posts the announcement with that role mentioned. Documented in config, env example and the bot design guide. --- .env.example | 3 +++ docs/bot/design.md | 3 ++- src/bot/commands/announce.ts | 11 ++++++++++- src/bot/config.ts | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 98c56e0f..092018c9 100644 --- a/.env.example +++ b/.env.example @@ -67,6 +67,9 @@ APP_PORT=3000 # App updates: where /announce posts when no channel is given; also the # channel preselected in the /announce compose dialog. # DISCORD_ANNOUNCE_CHANNEL_ID= +# Optional: when set, /announce (no message, compose dialog) automatically +# mentions this role in the posted announcement. Leave unset to disable. +# DISCORD_ANNOUNCE_MENTION_ROLE_ID= # DISCORD_STAFF_ROLE_IDS= # DISCORD_ATTENDANCE_POLL_MS= # DISCORD_NOTIFICATION_POLL_MS= diff --git a/docs/bot/design.md b/docs/bot/design.md index f11f1b26..a0acd067 100644 --- a/docs/bot/design.md +++ b/docs/bot/design.md @@ -123,7 +123,7 @@ Dependency: `discord.js` ^14 (add to root `package.json`). Script: `"bot": "bun ### D. Evaluation reminders (post-mission) -- **Trigger**: a mission becomes evaluable (status `Completed`, or `Scheduled`/`Active` whose `classification.startDateTime` has fully passed — same rule as `isMissionEvaluable` in `src/lib/evaluations`). Poll loop every `DISCORD_EVALUATION_POLL_MS` (default 60s) queries evaluable missions with no `evaluationRemindersSentAt` marker (one-shot, same pattern as `discordAttendanceSentAt`). +- **Trigger**: a mission becomes evaluable (status `Completed`, or `Scheduled`/`Active` whose scheduled window (`classification.startDateTime` + `classification.estimatedDuration`, default 240 min) has fully passed — same rule as `isMissionEvaluable` in `src/lib/evaluations`). Poll loop every `DISCORD_EVALUATION_POLL_MS` (default 60s) queries evaluable missions with no `evaluationRemindersSentAt` marker (one-shot, same pattern as `discordAttendanceSentAt`). - **Recipients** (`computeEvaluationReminderPlan` in `src/lib/evaluations/reminders.ts`): participants = users with a "yes" RSVP. Each participant is reminded to rate their direct leader(s); each leader of an assignment containing a participant is reminded to rate that participant (subordinate kind needs no RSVP). Self-pairs skipped; a user who is both gets one merged DM. - **DM**: embed with "Rate your leadership" / "Rate your subordinates" sections, each line linking to the ratee's profile page (`APP_URL + /profile/`) where the rating dialog lives. Best-effort: DM failures are logged and skipped, marker is set after the pass (cap 40 DMs/tick, 300ms between sends; overflow retries next tick before the marker is set). - **Deliberate exception**: these DMs ignore `preferences.discord.enabled` (defaults false, not yet exposed in the web UI — honoring it would DM nobody). Dedicated unit-admin flow, not notification-stream forwarding. @@ -162,6 +162,7 @@ Dependency: `discord.js` ^14 (add to root `package.json`). Script: `"bot": "bun | `DISCORD_IMMINENT_POLL_MS` | no | default 60000 | | `DISCORD_SIDE_OPS_CHANNEL_ID` | no | #side-ops channel for the Friday open-slot notice | | `DISCORD_COMMUNITY_ZEUS_ROLE_ID` | no | Community Zeus role ping (falls back to resolving the role by name) | +| `DISCORD_ANNOUNCE_MENTION_ROLE_ID` | no | Role auto-mentioned in `/announce` when called without a message (compose dialog). Unset disables it | | `DISCORD_SIDE_OPS_POLL_MS` | no | default 1800000 (30 min) | `APP_URL` already exists — used for login links in DMs. diff --git a/src/bot/commands/announce.ts b/src/bot/commands/announce.ts index 9f6f81c9..b8dd9a7c 100644 --- a/src/bot/commands/announce.ts +++ b/src/bot/commands/announce.ts @@ -46,8 +46,12 @@ const postAnnouncement = async ( channel: TextBasedChannelFields, title: string, message: string, + mentionRoleId?: string | null, ): Promise => { + // The role mention has to live in `content`, not the embed description: + // Discord only pings on a mention in the message content, never inside an embed. await channel.send({ + content: mentionRoleId ? `<@&${mentionRoleId}>` : undefined, embeds: [ new EmbedBuilder() .setTitle(title || "Announcement") @@ -187,7 +191,12 @@ export const handleAnnounceModal = async ( return; } - await postAnnouncement(channel as TextBasedChannelFields, title, message); + await postAnnouncement( + channel as TextBasedChannelFields, + title, + message, + botConfig.announceMentionRoleId, + ); const name = (channel as unknown as { name?: string | null }).name ?? resolvedId; await interaction.reply(ephemeral(`Announcement posted to #${name}.`)); diff --git a/src/bot/config.ts b/src/bot/config.ts index 0309ae02..94be64ee 100644 --- a/src/bot/config.ts +++ b/src/bot/config.ts @@ -7,6 +7,7 @@ export interface BotConfig { staffRoleIds: string[]; sideOpsChannelId: string | null; communityZeusRoleId: string | null; + announceMentionRoleId: string | null; attendancePollMs: number; notificationPollMs: number; evaluationPollMs: number; @@ -52,6 +53,7 @@ export const botConfig: BotConfig = { .filter((id) => id.length > 0), sideOpsChannelId: optional("DISCORD_SIDE_OPS_CHANNEL_ID"), communityZeusRoleId: optional("DISCORD_COMMUNITY_ZEUS_ROLE_ID"), + announceMentionRoleId: optional("DISCORD_ANNOUNCE_MENTION_ROLE_ID"), attendancePollMs: pollMs("DISCORD_ATTENDANCE_POLL_MS", 60_000), notificationPollMs: pollMs("DISCORD_NOTIFICATION_POLL_MS", 20_000), evaluationPollMs: pollMs("DISCORD_EVALUATION_POLL_MS", 60_000),