Compare commits
No commits in common. "716c87bb8748d628073973f09cc3e4d9d59d2c47" and "fc6fec4a453a61e56b59ba7ae7905b6d3cde2c64" have entirely different histories.
716c87bb87
...
fc6fec4a45
9 changed files with 35 additions and 121 deletions
13
CHANGELOG.md
13
CHANGELOG.md
|
|
@ -1,18 +1,5 @@
|
|||
# Changelog
|
||||
|
||||
# v0.16.3
|
||||
|
||||
Relations and ratings read the right way round now, and the weekly Discord op notice shows the correct day.
|
||||
|
||||
### Fixes
|
||||
|
||||
- **Faction relations.** On a faction's page a negative attitude now grows its meter to the left of the zero line and a positive one to the right, so the bar matches the number beside it. The two readings are labelled "How they see us" and "How we see them" as well, so there is no doubt which way round they go.
|
||||
- **Mission ratings.** The note on an op page now says exactly why rating is unavailable: rating is closed, you need a YES RSVP, or authors cannot rate their own op, which is shown as a warning.
|
||||
- **Weekly op notice.** The Discord message that offers the Friday op slot now shows that Friday's date for every member. People west of Eastern time were being shown the day before.
|
||||
- Various bug fixes and improvements.
|
||||
|
||||
---
|
||||
|
||||
# v0.16.2
|
||||
|
||||
Faction relations can now be read as a map instead of a table.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "polaris-task-force",
|
||||
"version": "0.16.3",
|
||||
"version": "0.16.2",
|
||||
"description": "Web app for the Arma 3 unit Polaris Task Force. Uses Next.js for client- and server-side rendering, with a Postgres database and some other neat libraries.",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ function RelationMeter({ label, value }: { label: string; value: number }) {
|
|||
<div className="relative h-1.5 w-full overflow-hidden rounded-full bg-muted">
|
||||
<div
|
||||
className={`absolute top-0 h-full ${tone.bar}`}
|
||||
style={{ left: value < 0 ? `${50 - width}%` : "50%", width: `${width}%` }}
|
||||
style={{ left: value < 0 ? "50%" : `${50 - width}%`, width: `${width}%` }}
|
||||
/>
|
||||
<div className="absolute left-1/2 top-0 h-full w-px bg-border" />
|
||||
</div>
|
||||
|
|
@ -376,8 +376,8 @@ export default async function FactionDetailPage({ params }: FactionDetailPagePro
|
|||
<span>{other.name}</span>
|
||||
</Link>
|
||||
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||
<RelationMeter label="How they see us" value={inbound} />
|
||||
<RelationMeter label="How we see them" value={outbound} />
|
||||
<RelationMeter label="They see us" value={inbound} />
|
||||
<RelationMeter label="We see them" value={outbound} />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
|
|
|||
|
|
@ -753,7 +753,7 @@ export default async function MissionDetailPage({ params }: MissionDetailPagePro
|
|||
>
|
||||
<Link
|
||||
href={`/intelligence/campaigns/${campaign.id}`}
|
||||
className="min-w-0 flex flex-col gap-1.5 p-4 transition-colors group hover:bg-muted/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
|
||||
className="block min-w-0 flex-1 flex-col gap-2 p-4 transition-colors group hover:bg-muted/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
|
|
@ -763,7 +763,7 @@ export default async function MissionDetailPage({ params }: MissionDetailPagePro
|
|||
</span>
|
||||
</div>
|
||||
<span className="inline-flex shrink-0 items-center gap-2">
|
||||
<span className={`self-start inline-block text-[10px] leading-4 font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded ${campaign.status === "concept" ? "bg-emerald-500/20 text-emerald-400" : campaign.status === "inProgress" ? "bg-blue-500/20 text-blue-400" : campaign.status === "onHold" ? "bg-amber-500/20 text-amber-400" : "bg-emerald-500/20 text-emerald-400"}`}>
|
||||
<span className={`self-start inline-block text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded ${campaign.status === "concept" ? "bg-emerald-500/20 text-emerald-400" : campaign.status === "inProgress" ? "bg-blue-500/20 text-blue-400" : campaign.status === "onHold" ? "bg-amber-500/20 text-amber-400" : "bg-emerald-500/20 text-emerald-400"}`}>
|
||||
{campaign.status === "concept" ? "Planning" : campaign.status === "inProgress" ? "Active Deployment" : campaign.status === "onHold" ? "On Hold" : "Concluded"}
|
||||
</span>
|
||||
<ChevronRightIcon className="size-3 text-white/50 opacity-0 group-hover:opacity-100 transition-opacity" />
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ Once a mission is evaluable (`Completed`, or `Scheduled`/`Active` past its start
|
|||
|
||||
## Feature flow: Friday open-slot notice
|
||||
|
||||
At 8 PM Eastern on Wednesday (`America/New_York`, evaluated via `isNoticeDue` in `src/lib/intelligence/fridayOpsNotice.ts`; catch-up until ET midnight, a fully missed Wednesday skips to next week), if no non-cancelled mission starts on that week's upcoming Friday, `fridayOpsNotice` posts once in #side-ops pinging the Community Zeus role: the slot is open, hosting is welcome, and if nobody picks it up the slot stays empty or Jason hosts it himself. The slot window is Friday 00:00–23:59:59.999 **America/New_York** computed from the Eastern calendar date, never the server clock (the UTC deploy container once treated Wed 8 PM ET as Thursday and missed Friday-evening ops entirely); when it is already Friday Eastern, that day itself is the slot, so the dedup token stays stable from Wednesday through the op day and late claims still credit. When a non-superuser creator later claims the slot (`getFridayClaimant`, earliest-created mission wins; superuser/staff-created missions never claim), the notice is edited to append "This slot was claimed by \<user\>. Thank you for hosting for our community!"; if that op is later cancelled or deleted, the claim line is stripped and the notice reverts to the open-slot state (a between-polls claim swap re-credits the new claimant). Role: `DISCORD_COMMUNITY_ZEUS_ROLE_ID` or resolved by name in the guild; channel: `DISCORD_SIDE_OPS_CHANNEL_ID`. Dedup without DB state: the message embeds a stable per-Friday Eastern date label (e.g. `January 15, 2027`) and the service scans recent channel messages for it (claim idempotency via a marker in the message content). Never use Discord's `<t:epoch:D>` for this date: it renders in each viewer's timezone, so an epoch at Friday 00:00 Eastern displayed as Thursday for members in Central/Mountain/Pacific/Hawaii. Notices still carrying the old `<t:epoch:D>` token are matched and rewritten in place to the Eastern label. Drafts (Concept) count as the slot being taken.
|
||||
At 8 PM Eastern on Wednesday (`America/New_York`, evaluated via `isNoticeDue` in `src/lib/intelligence/fridayOpsNotice.ts`; catch-up until ET midnight, a fully missed Wednesday skips to next week), if no non-cancelled mission starts on that week's upcoming Friday, `fridayOpsNotice` posts once in #side-ops pinging the Community Zeus role: the slot is open, hosting is welcome, and if nobody picks it up the slot stays empty or Jason hosts it himself. The slot window is Friday 00:00–23:59:59.999 **America/New_York** computed from the Eastern calendar date, never the server clock (the UTC deploy container once treated Wed 8 PM ET as Thursday and missed Friday-evening ops entirely); when it is already Friday Eastern, that day itself is the slot, so the dedup token stays stable from Wednesday through the op day and late claims still credit. When a non-superuser creator later claims the slot (`getFridayClaimant`, earliest-created mission wins; superuser/staff-created missions never claim), the notice is edited to append "This slot was claimed by \<user\>. Thank you for hosting for our community!"; if that op is later cancelled or deleted, the claim line is stripped and the notice reverts to the open-slot state (a between-polls claim swap re-credits the new claimant). Role: `DISCORD_COMMUNITY_ZEUS_ROLE_ID` or resolved by name in the guild; channel: `DISCORD_SIDE_OPS_CHANNEL_ID`. Dedup without DB state: the message embeds a stable per-Friday `<t:epoch:D>` token and the service scans recent channel messages for it (claim idempotency via a marker in the message content). Drafts (Concept) count as the slot being taken.
|
||||
|
||||
## Feature flow: assignment transfers
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,13 @@
|
|||
import {
|
||||
type Client,
|
||||
type Collection,
|
||||
type Message,
|
||||
type TextBasedChannelFields,
|
||||
} from "discord.js";
|
||||
import { type Client, type Collection, type Message, type TextBasedChannelFields } from "discord.js";
|
||||
import type { Payload } from "payload";
|
||||
import { botConfig } from "@/bot/config";
|
||||
import {
|
||||
SIDE_OPS_NOTICE_ROLE_NAME,
|
||||
fridayDateLabel,
|
||||
getFridayClaimant,
|
||||
hasMissionOnFriday,
|
||||
isNoticeDue,
|
||||
legacyNoticeToken,
|
||||
noticeToken,
|
||||
upcomingFridayRange,
|
||||
} from "@/lib/intelligence/fridayOpsNotice";
|
||||
|
||||
/**
|
||||
|
|
@ -24,7 +18,7 @@ import {
|
|||
* When a non-superuser (a community zeus) later claims the slot, the notice
|
||||
* is edited to credit them instead; if that claim op is later cancelled (or
|
||||
* deleted), the notice reverts to the open-slot state. Dedup needs no DB
|
||||
* state: the notice embeds a stable per-Friday Eastern date label and the
|
||||
* state: the notice embeds a stable per-Friday timestamp token and the
|
||||
* service scans recent channel messages for it (and for the claim line)
|
||||
* before posting or editing, so bot restarts never double-post or re-credit.
|
||||
*/
|
||||
|
|
@ -61,8 +55,9 @@ export const resolveZeusRoleId = async (client: Client): Promise<string | null>
|
|||
|
||||
export const renderNotice = (zeusRoleId: string | null, now = new Date()): string => {
|
||||
const mention = zeusRoleId ? `<@&${zeusRoleId}> ` : "";
|
||||
const { epoch } = upcomingFridayRange(now);
|
||||
return (
|
||||
`${mention}The Friday op slot (${fridayDateLabel(now)}) is still open, and you are welcome to host an op: ` +
|
||||
`${mention}The Friday op slot (<t:${epoch}:D>) is still open, and you are welcome to host an op: ` +
|
||||
`schedule one via the Friday Ops calendar at ${botConfig.appUrl}/intelligence/missions/calendar. ` +
|
||||
"If nobody picks it up, the slot will either stay empty (no op that Friday) or Jason will host it himself."
|
||||
);
|
||||
|
|
@ -75,25 +70,12 @@ const CLAIM_LINE_PATTERN =
|
|||
const creditedNameOf = (content: string): string | null =>
|
||||
content.match(CLAIM_LINE_PATTERN)?.[1] ?? null;
|
||||
|
||||
/**
|
||||
* The notice is found by content token, and only among the bot's own messages:
|
||||
* the token is a plain date now, so a member typing the same date in the
|
||||
* channel must not be mistaken for the notice (the bot cannot edit it anyway).
|
||||
*/
|
||||
export const findNoticeMessage = async (
|
||||
channel: SideOpsChannel,
|
||||
tokens: string | string[],
|
||||
botUserId?: string,
|
||||
token: string,
|
||||
): Promise<Message | null> => {
|
||||
const wanted = Array.isArray(tokens) ? tokens : [tokens];
|
||||
const recent = await channel.messages.fetch({ limit: MESSAGE_SCAN_LIMIT });
|
||||
return (
|
||||
recent.find(
|
||||
(message) =>
|
||||
(botUserId == null || message.author.id === botUserId) &&
|
||||
wanted.some((token) => message.content.includes(token)),
|
||||
) ?? null
|
||||
);
|
||||
return recent.find((message) => message.content.includes(token)) ?? null;
|
||||
};
|
||||
|
||||
const processNotice = async (
|
||||
|
|
@ -108,8 +90,7 @@ const processNotice = async (
|
|||
|
||||
const channel = await getSideOpsChannel(client, channelId);
|
||||
const token = noticeToken(now);
|
||||
const legacyToken = legacyNoticeToken(now);
|
||||
const notice = await findNoticeMessage(channel, [token, legacyToken], client.user?.id);
|
||||
const notice = await findNoticeMessage(channel, token);
|
||||
|
||||
if (!notice) {
|
||||
const slotTaken = claim != null || (await hasMissionOnFriday(payload, now));
|
||||
|
|
@ -128,32 +109,18 @@ const processNotice = async (
|
|||
return "posted";
|
||||
}
|
||||
|
||||
// A notice posted before the Eastern label existed still carries the old
|
||||
// `<t:epoch:D>` token (which reads as Thursday west of Eastern). Upgrade it
|
||||
// in place so the visible date is correct for everyone.
|
||||
let content = notice.content;
|
||||
if (!content.includes(token) && content.includes(legacyToken)) {
|
||||
content = content.replace(legacyToken, token);
|
||||
await notice.edit(content);
|
||||
payload.logger.info(
|
||||
`[Bot] Friday open-slot notice for ${token}: upgraded the legacy date token to the Eastern label.`,
|
||||
);
|
||||
}
|
||||
|
||||
const credited = creditedNameOf(content);
|
||||
const credited = creditedNameOf(notice.content);
|
||||
if (!claim) {
|
||||
if (!credited) return "idle";
|
||||
await notice.edit(content.replace(CLAIM_LINE_PATTERN, ""));
|
||||
await notice.edit(notice.content.replace(CLAIM_LINE_PATTERN, ""));
|
||||
payload.logger.info(
|
||||
`[Bot] Friday open-slot notice for ${token}: claim by ${credited} was cancelled; notice reverted to the open-slot state.`,
|
||||
);
|
||||
return "edited";
|
||||
}
|
||||
if (credited !== claim.userName) {
|
||||
const base = credited ? content.replace(CLAIM_LINE_PATTERN, "") : content;
|
||||
await notice.edit(
|
||||
`${base}\n\n${CLAIM_MARKER} ${claim.userName}. Thank you for hosting for our community!`,
|
||||
);
|
||||
const base = credited ? notice.content.replace(CLAIM_LINE_PATTERN, "") : notice.content;
|
||||
await notice.edit(`${base}\n\n${CLAIM_MARKER} ${claim.userName}. Thank you for hosting for our community!`);
|
||||
payload.logger.info(
|
||||
`[Bot] Friday open-slot notice for ${token} claimed by ${claim.userName}; notice updated.`,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import {
|
|||
} from "@/lib/missionRatings/factors";
|
||||
import type { MissionRatingAggregate, MissionRatingState } from "@/lib/missionRatings";
|
||||
import { submitMissionRating } from "@/app/(frontend)/intelligence/missions/actions";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
|
||||
interface MissionRatingProps {
|
||||
readonly missionId: number;
|
||||
|
|
@ -310,7 +309,9 @@ export function MissionRating({
|
|||
const notEligible = !state.isEligible;
|
||||
|
||||
return (
|
||||
<section className="flex min-w-0 flex-col gap-3 px-4 py-4">
|
||||
<section
|
||||
className="flex min-w-0 flex-col gap-3 px-4 py-4"
|
||||
>
|
||||
<Item variant="outline" className="py-4">
|
||||
<ItemHeader>
|
||||
<ItemTitle>Rate this mission</ItemTitle>
|
||||
|
|
@ -327,17 +328,19 @@ export function MissionRating({
|
|||
)}
|
||||
{ratingLocked && <YouRatedState state={state} factors={factors} />}
|
||||
{!showForm && !ratingLocked && windowClosed && (
|
||||
<p className="text-sm text-muted-foreground">Rating is closed for this mission.</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
The rating window for this mission is closed.
|
||||
</p>
|
||||
)}
|
||||
{!showForm && !ratingLocked && !windowClosed && notEligible && !state.isAuthor && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
You need a <span className="text-green-500 font-bold">YES</span> RSVP for this mission to rate it.
|
||||
You need a Yes RSVP for this mission to rate it.
|
||||
</p>
|
||||
)}
|
||||
{!showForm && !ratingLocked && state.isAuthor && (
|
||||
<Alert variant="destructive">
|
||||
<AlertDescription>Mission authors cannot rate their own mission.</AlertDescription>
|
||||
</Alert>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Mission authors cannot rate their own mission.
|
||||
</p>
|
||||
)}
|
||||
</ItemContent>
|
||||
</Item>
|
||||
|
|
|
|||
|
|
@ -120,8 +120,7 @@ const etMidnightUtc = (year: number, month: number, day: number): number => {
|
|||
* evening Eastern once fell outside the old server-local window). When `now`
|
||||
* is already Friday Eastern, that day itself is the slot, keeping the dedup
|
||||
* token stable from Wednesday through the op day so late claims still credit.
|
||||
* Used for the mission-existence query, the per-Friday notice token, and the
|
||||
* legacy `<t:epoch:D>` token still recognized from older notices.
|
||||
* Used both for the mission-existence query and for the per-Friday token.
|
||||
*/
|
||||
export const upcomingFridayRange = (now: Date): { start: Date; end: Date; epoch: number } => {
|
||||
const et = etDate(now);
|
||||
|
|
@ -205,30 +204,8 @@ export const getFridayClaimant = async (
|
|||
};
|
||||
|
||||
/**
|
||||
* The upcoming Friday's calendar date as seen in America/New_York, e.g.
|
||||
* "January 15, 2027". Discord's `<t:epoch:D>` markup renders in the VIEWER's
|
||||
* timezone, so an epoch at Friday 00:00 Eastern showed up as Thursday for
|
||||
* members in Central, Mountain, Pacific, and Hawaii time; a pinned Eastern
|
||||
* label reads the same for everyone.
|
||||
* Stable per-Friday token embedded in the notice message (renders as the
|
||||
* Friday's date) so the bot can detect an existing notice by scanning recent
|
||||
* channel messages, surviving restarts without any DB state.
|
||||
*/
|
||||
export const fridayDateLabel = (now: Date): string =>
|
||||
new Intl.DateTimeFormat("en-US", {
|
||||
timeZone: ET_TIME_ZONE,
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
year: "numeric",
|
||||
}).format(upcomingFridayRange(now).start);
|
||||
|
||||
/**
|
||||
* Stable per-Friday token embedded in the notice message (the Eastern date
|
||||
* label) so the bot can detect an existing notice by scanning recent channel
|
||||
* messages, surviving restarts without any DB state.
|
||||
*/
|
||||
export const noticeToken = (now: Date): string => fridayDateLabel(now);
|
||||
|
||||
/**
|
||||
* The `<t:epoch:D>` token older builds embedded. Kept so a notice posted by
|
||||
* the previous build on a deploy evening is still recognized instead of
|
||||
* re-posted as a duplicate for the same Friday.
|
||||
*/
|
||||
export const legacyNoticeToken = (now: Date): string => `<t:${upcomingFridayRange(now).epoch}:D>`;
|
||||
export const noticeToken = (now: Date): string => `<t:${upcomingFridayRange(now).epoch}:D>`;
|
||||
|
|
|
|||
|
|
@ -4,11 +4,9 @@ import { Payload } from "payload";
|
|||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import type { Campaign, Map as MissionMap, Mission, User } from "@/payload-types";
|
||||
import {
|
||||
fridayDateLabel,
|
||||
getFridayClaimant,
|
||||
hasMissionOnFriday,
|
||||
isNoticeDue,
|
||||
legacyNoticeToken,
|
||||
noticeToken,
|
||||
upcomingFridayRange,
|
||||
} from "@/lib/intelligence/fridayOpsNotice";
|
||||
|
|
@ -258,33 +256,15 @@ describe("Friday open-slot notice", () => {
|
|||
expect(upcomingFridayRange(SATURDAY).start.toISOString()).toBe("2027-01-22T05:00:00.000Z");
|
||||
});
|
||||
|
||||
it("labels the upcoming Friday in Eastern time so every viewer sees the same day", () => {
|
||||
// The slot instant is Friday 00:00 Eastern. Rendered as Discord's
|
||||
// `<t:epoch:D>` that reads as Thursday for viewers west of Eastern, so the
|
||||
// notice carries a pinned Eastern label instead.
|
||||
expect(fridayDateLabel(WEDNESDAY)).toBe("January 15, 2027");
|
||||
expect(fridayDateLabel(WEDNESDAY_EVENING)).toBe("January 15, 2027");
|
||||
expect(fridayDateLabel(FRIDAY)).toBe("January 15, 2027");
|
||||
expect(fridayDateLabel(SATURDAY)).toBe("January 22, 2027");
|
||||
});
|
||||
|
||||
it("builds a stable per-Friday dedup token", () => {
|
||||
expect(noticeToken(WEDNESDAY)).toBe(noticeToken(TUESDAY));
|
||||
expect(noticeToken(WEDNESDAY)).toBe(fridayDateLabel(WEDNESDAY));
|
||||
expect(noticeToken(WEDNESDAY)).not.toContain("<t:");
|
||||
expect(noticeToken(WEDNESDAY)).toBe(`<t:${upcomingFridayRange(WEDNESDAY).epoch}:D>`);
|
||||
// Stable through the op day, so claims made after Thursday ET midnight
|
||||
// still match the notice posted on Wednesday.
|
||||
expect(noticeToken(FRIDAY)).toBe(noticeToken(WEDNESDAY));
|
||||
expect(noticeToken(SATURDAY)).not.toBe(noticeToken(WEDNESDAY));
|
||||
});
|
||||
|
||||
it("keeps recognizing the legacy Discord timestamp token", () => {
|
||||
// Notices posted by older builds embed `<t:epoch:D>`; the service still
|
||||
// matches it (and rewrites it to the Eastern label) instead of reposting.
|
||||
expect(legacyNoticeToken(WEDNESDAY)).toBe(`<t:${upcomingFridayRange(WEDNESDAY).epoch}:D>`);
|
||||
expect(legacyNoticeToken(WEDNESDAY)).toBe(legacyNoticeToken(FRIDAY));
|
||||
});
|
||||
|
||||
it("treats the Friday slot as open only when a non-cancelled mission starts that Friday", async () => {
|
||||
await expect(hasMissionOnFriday(payload, WEDNESDAY)).resolves.toBe(false);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue