Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/discord-bot/src/features/MentionRouter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ describe("today-recap slash command", () => {
expect(mentionRouterSource).toContain("buildTodayRecapPrompt");
expect(mentionRouterSource).toContain("local: true, plan: false, prompt: opened.prompt");
expect(mentionRouterSource).toContain('presentationMode: "final-only"');
expect(mentionRouterSource).toContain("rest.createThread(input.projectChannelId");
expect(mentionRouterSource).not.toContain("starterContent");
});
});

Expand Down
64 changes: 20 additions & 44 deletions apps/discord-bot/src/features/MentionRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ import {
} from "../presentation/slashCommands.ts";
import {
buildTodayRecapPrompt,
formatTodayRecapAck,
formatTodayRecapThreadTitle,
utcDateStamp,
} from "../presentation/todayRecap.ts";
Expand Down Expand Up @@ -2013,7 +2012,6 @@ const make = (botConfig: DiscordBotConfig) =>
const openTodayRecapThread = (input: {
readonly projectChannelId: string;
readonly shortName: string;
readonly starterContent: string;
readonly starterMessageId?: string;
}) =>
Effect.gen(function* () {
Expand All @@ -2023,15 +2021,16 @@ const make = (botConfig: DiscordBotConfig) =>
date,
parentChannelId: input.projectChannelId,
});
const starterId =
input.starterMessageId ??
(yield* rest.createMessage(input.projectChannelId, { content: input.starterContent })).id;
const discordThread = yield* openOrReuseThread(
input.projectChannelId,
starterId,
formatTodayRecapThreadTitle({ shortName: input.shortName, date }),
);
return { date, prompt, starterId, discordThread };
const title = formatTodayRecapThreadTitle({ shortName: input.shortName, date });
const discordThread =
input.starterMessageId === undefined
? yield* rest.createThread(input.projectChannelId, {
name: title,
auto_archive_duration: 1440,
type: 11,
})
: yield* openOrReuseThread(input.projectChannelId, input.starterMessageId, title);
return { date, prompt, discordThread };
});

const watchedDiscordLinkRequests = new Set<string>();
Expand Down Expand Up @@ -2631,16 +2630,9 @@ const make = (botConfig: DiscordBotConfig) =>
});
return;
}
const displayName = event.author?.global_name ?? event.author?.username ?? "Someone";
const ack = formatTodayRecapAck({
displayName,
shortName,
date: utcDateStamp(DateTime.formatIso(DateTime.nowUnsafe())),
});
const opened = yield* openTodayRecapThread({
projectChannelId: parentId,
shortName,
starterContent: ack,
});
const mentionMessage = discordMessageFromEvent({ ...event, content });
yield* startBridgedTurn({
Expand All @@ -2652,14 +2644,10 @@ const make = (botConfig: DiscordBotConfig) =>
topic,
parentChannelId: parentId,
presentationMode: "final-only",
mentionMessage: {
...mentionMessage,
id: opened.starterId,
content: ack,
},
mentionMessage,
}).pipe(Effect.catch((error) => reportError(opened.discordThread.id, error)));
yield* rest.createMessage(event.channel_id, {
content: `${ack}\n→ ${discordChannelUrl(event.guild_id, opened.discordThread.id)}`,
content: `→ ${discordChannelUrl(event.guild_id, opened.discordThread.id)}`,
message_reference: { message_id: event.id },
});
return;
Expand Down Expand Up @@ -2891,16 +2879,9 @@ const make = (botConfig: DiscordBotConfig) =>
});
return;
}
const displayName = event.author?.global_name ?? event.author?.username ?? "Someone";
const ack = formatTodayRecapAck({
displayName,
shortName,
date: utcDateStamp(DateTime.formatIso(DateTime.nowUnsafe())),
});
const opened = yield* openTodayRecapThread({
projectChannelId: event.channel_id,
shortName,
starterContent: ack,
starterMessageId: event.id,
});
const mentionMessage = discordMessageFromEvent({ ...event, content });
Expand Down Expand Up @@ -3540,21 +3521,16 @@ const make = (botConfig: DiscordBotConfig) =>

const projectChannelId = parentId ?? channelId;
const requester = interactionRequester(interaction);
const displayName =
requester.author?.displayName ?? requester.author?.username ?? "Someone";
const date = utcDateStamp(DateTime.formatIso(DateTime.nowUnsafe()));
const ack = formatTodayRecapAck({ displayName, shortName, date });
const opened = yield* openTodayRecapThread({
projectChannelId,
shortName,
starterContent: ack,
});

yield* Effect.logInfo("Slash /omegent today-recap: starting bridged turn", {
channelId: projectChannelId,
discordThreadId: opened.discordThread.id,
shortName,
date,
date: opened.date,
});
yield* forkSlashBackground(
startBridgedTurn({
Expand All @@ -3566,11 +3542,7 @@ const make = (botConfig: DiscordBotConfig) =>
topic,
parentChannelId: projectChannelId,
presentationMode: "final-only",
mentionMessage: {
...requester,
id: opened.starterId,
content: ack,
},
mentionMessage: requester,
}).pipe(
Effect.tap(() =>
Effect.logInfo("Slash /omegent today-recap: bridged turn started", {
Expand All @@ -3582,8 +3554,12 @@ const make = (botConfig: DiscordBotConfig) =>
),
);

const jump = discordChannelUrl(interaction.guild_id, opened.discordThread.id);
return slashReply(`${ack}\n→ ${jump}`);
return slashReply(
`→ ${discordChannelUrl(interaction.guild_id, opened.discordThread.id)}`,
{
ephemeral: true,
},
);
}).pipe(
Effect.catch((error: unknown) =>
Effect.succeed(
Expand Down
Loading