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
4 changes: 2 additions & 2 deletions src/features/rte/end-session-pop-button-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export class EndRtePopButtonCommand extends ButtonCommand {

public getButtonBuilder(sessionId: number): ButtonBuilder {
return new ButtonBuilder()
.setCustomId(`rte_end_pop_${sessionId}`)
.setCustomId(`rte_pop_end_${sessionId}`)
.setLabel("End Session (pop)")
.setStyle(ButtonStyle.Danger);
}
}

export const endRtePopButtonCommand = new EndRtePopButtonCommand("rte_end_pop");
export const endRtePopButtonCommand = new EndRtePopButtonCommand("rte_pop_end");
35 changes: 17 additions & 18 deletions src/features/rte/status-embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,33 @@ const typeIcon = (type: RteType) => {
};

export const refreshRteStatusEmbed = async () => {
const openTargets = await rteService.getOpenTargets();
const activeSessions = await rteService.getActiveSessions();

const embed = new EmbedBuilder({
title: `RTE Status — last updated ${moment().format("h:mm:ss A")}`,
description:
openTargets.length === 0
? "No targets are currently open for RTE."
activeSessions.length === 0
? "No active RTE sessions."
: undefined,
});

for (const target of openTargets) {
const sessions = activeSessions.filter((s) => s.target === target.target);
let value: string;
if (sessions.length === 0) {
value = "*No active sessions*";
} else {
value = sessions
.map((s) => {
const elapsed = moment.duration(moment().diff(s.startTime));
const elapsedStr = `${Math.floor(elapsed.asHours())}h ${elapsed.minutes()}m`;
return `${typeIcon(s.type)} **${s.characterName}**${s.class ? ' - ' + s.class : ''} (<@${s.discordId}>) — ${elapsedStr}`;
})
.join("\n");
}
// Get all unique targets that have active sessions
const activeTargets = Array.from(
new Set(activeSessions.map((s) => s.target))
).sort();

for (const targetName of activeTargets) {
const sessions = activeSessions.filter((s) => s.target === targetName);
const value = sessions
.map((s) => {
const elapsed = moment.duration(moment().diff(s.startTime));
const elapsedStr = `${Math.floor(elapsed.asHours())}h ${elapsed.minutes()}m`;
return `${typeIcon(s.type)} **${s.characterName}**${s.class ? ' - ' + s.class : ''} (<@${s.discordId}>) — ${elapsedStr}`;
})
.join("\n");

embed.addFields({
name: target.target,
name: targetName,
value,
inline: false,
});
Expand Down
4 changes: 2 additions & 2 deletions src/services/rteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const rteService = {
.setStyle(ButtonStyle.Danger);

const popButton = new ButtonBuilder()
.setCustomId(`rte_end_pop_${session.id}`)
.setCustomId(`rte_pop_end_${session.id}`)
.setLabel("End Session (pop)")
.setStyle(ButtonStyle.Danger);

Expand Down Expand Up @@ -122,7 +122,7 @@ export const rteService = {
// If this fails, the session remains active so the user can retry.
const user = await client.users.fetch(session.discordId);
await user.send({
content: `Your **${formatType(session.type)}** session for **${session.target}** has ended.\n\n**Summary:**\n- Character: ${session.characterName}\n- Duration: ${formatDuration(summary.elapsedMinutes)}\n- Rounded Duration: ${formatDuration(summary.roundedMinutes)}\n- Hourly Rate: ${summary.hourlyRate} DKP\n- **DKP Earned: ${summary.dkpEarned.toFixed(2)}**`,
content: `Your **${formatType(session.type)}** session for **${session.target}** has ended${roundUp ? " (rounded up due to pop)" : ""}.\n\n**Summary:**\n- Character: ${session.characterName}\n- Duration: ${formatDuration(summary.elapsedMinutes)}\n- Rounded Duration: ${formatDuration(summary.roundedMinutes)}\n- Hourly Rate: ${summary.hourlyRate} DKP\n- **DKP Earned: ${summary.dkpEarned.toFixed(2)}**`,
});

await prismaClient.rte.update({
Expand Down
Loading