1
0
Fork 0

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.
This commit is contained in:
Jason Fraley 2026-10-05 03:37:15 -04:00
parent c626ca3ccc
commit 9b6935314d
4 changed files with 17 additions and 2 deletions

View file

@ -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=

View file

@ -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/<username>`) 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.

View file

@ -46,8 +46,12 @@ const postAnnouncement = async (
channel: TextBasedChannelFields,
title: string,
message: string,
mentionRoleId?: string | null,
): Promise<void> => {
// 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}.`));

View file

@ -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),