a fun bot for the hc slack

bug: fix bad time on the upload and approved messages

dunkirk.sh daa90739 77195d7c

verified
Changed files
+58 -18
src
features
takes
handlers
services
+2 -2
src/features/takes/handlers/stop.ts
···
elements: [
{
type: "mrkdwn",
-
text: `*Duration:* ${prettyPrintTime(elapsed)} ${notes ? `\n*Notes:* ${notes}` : ""}`,
},
],
},
···
elements: [
{
type: "mrkdwn",
-
text: `*Duration:* ${prettyPrintTime(elapsed)} ${notes ? `\n*Notes:* ${notes}` : ""}`,
},
],
},
···
elements: [
{
type: "mrkdwn",
+
text: `*Elapsed Time:* \`${prettyPrintTime(elapsed)}\`${pausedTakeToStop.description ? ` working on: *${pausedTakeToStop.description}*` : ""}`,
},
],
},
···
elements: [
{
type: "mrkdwn",
+
text: `\`${prettyPrintTime(elapsed)}\`${activeTakeToStop.description ? ` Working on: *${activeTakeToStop.description}*` : ""}`,
},
],
},
+49 -6
src/features/takes/services/notifications.ts
···
getPausedDuration,
getRemainingTime,
} from "../../../libs/time-periods";
// Check for paused sessions that have exceeded the max pause duration
export async function expirePausedSessions() {
···
}
}
// Auto-expire paused sessions that exceed the max pause duration
if (pausedDuration > TakesConfig.MAX_PAUSE_DURATION) {
let ts: string | undefined;
···
const res = await slackApp.client.chat.postMessage({
channel: take.userId,
text: `⏰ Your paused takes session has been automatically completed because it was paused for more than ${TakesConfig.MAX_PAUSE_DURATION} minutes.\n\nPlease upload your takes video in this thread within the next 24 hours!`,
});
ts = res.ts;
} catch (error) {
···
error,
);
}
-
-
// Calculate elapsed time
-
const elapsedTime = calculateElapsedTime(JSON.parse(take.periods));
await db
.update(takesTable)
···
}
}
if (endTime.remaining <= 0) {
let ts: string | undefined;
try {
const res = await slackApp.client.chat.postMessage({
channel: take.userId,
text: "⏰ Your takes session has automatically completed because the time is up. Please upload your takes video in this thread within the next 24 hours!",
});
ts = res.ts;
···
);
}
-
const elapsedTime = calculateElapsedTime(JSON.parse(take.periods));
-
await db
.update(takesTable)
.set({
status: "waitingUpload",
completedAt: now,
-
elapsedTimeMs: take.targetDurationMs,
ts,
notes: take.notes
? `${take.notes} (Automatically completed - time expired)`
···
getPausedDuration,
getRemainingTime,
} from "../../../libs/time-periods";
+
import { prettyPrintTime } from "../../../libs/time";
// Check for paused sessions that have exceeded the max pause duration
export async function expirePausedSessions() {
···
}
}
+
// Calculate elapsed time
+
const elapsedTime = calculateElapsedTime(JSON.parse(take.periods));
+
// Auto-expire paused sessions that exceed the max pause duration
if (pausedDuration > TakesConfig.MAX_PAUSE_DURATION) {
let ts: string | undefined;
···
const res = await slackApp.client.chat.postMessage({
channel: take.userId,
text: `⏰ Your paused takes session has been automatically completed because it was paused for more than ${TakesConfig.MAX_PAUSE_DURATION} minutes.\n\nPlease upload your takes video in this thread within the next 24 hours!`,
+
blocks: [
+
{
+
type: "section",
+
text: {
+
type: "mrkdwn",
+
text: `⏰ Your paused takes session has been automatically completed because it was paused for more than ${TakesConfig.MAX_PAUSE_DURATION} minutes.\n\nPlease upload your takes video in this thread within the next 24 hours!`,
+
},
+
},
+
{
+
type: "divider",
+
},
+
{
+
type: "context",
+
elements: [
+
{
+
type: "mrkdwn",
+
text: `\`${prettyPrintTime(elapsedTime)}\`${take.description ? ` working on: *${take.description}*` : ""}`,
+
},
+
],
+
},
+
],
});
ts = res.ts;
} catch (error) {
···
error,
);
}
await db
.update(takesTable)
···
}
}
+
const elapsedTime = calculateElapsedTime(JSON.parse(take.periods));
+
if (endTime.remaining <= 0) {
let ts: string | undefined;
try {
const res = await slackApp.client.chat.postMessage({
channel: take.userId,
text: "⏰ Your takes session has automatically completed because the time is up. Please upload your takes video in this thread within the next 24 hours!",
+
blocks: [
+
{
+
type: "section",
+
text: {
+
type: "mrkdwn",
+
text: "⏰ Your takes session has automatically completed because the time is up. Please upload your takes video in this thread within the next 24 hours!",
+
},
+
},
+
{
+
type: "divider",
+
},
+
{
+
type: "context",
+
elements: [
+
{
+
type: "mrkdwn",
+
text: `\`${prettyPrintTime(elapsedTime)}\`${take.description ? ` working on: *${take.description}*` : ""}`,
+
},
+
],
+
},
+
],
});
ts = res.ts;
···
);
}
await db
.update(takesTable)
.set({
status: "waitingUpload",
completedAt: now,
+
elapsedTimeMs: elapsedTime,
ts,
notes: take.notes
? `${take.notes} (Automatically completed - time expired)`
+7 -10
src/features/takes/services/upload.ts
···
name: "fire",
});
-
const takeDuration = calculateElapsedTime(JSON.parse(take.periods));
-
await slackClient.chat.postMessage({
channel: payload.channel,
thread_ts: payload.thread_ts,
···
elements: [
{
type: "mrkdwn",
-
text: `take by <@${user}> for \`${prettyPrintTime(takeDuration)}\` working on: *${take.description}*`,
},
],
},
···
type: "section",
text: {
type: "mrkdwn",
-
text: `:video_camera: new take uploaded by <@${user}> for \`${prettyPrintTime(takeDuration)}\` working on: *${take.description}*`,
},
},
{
···
elements: [
{
type: "mrkdwn",
-
text: `take by <@${user}> for \`${prettyPrintTime(takeDuration)}\` working on: *${take.description}*`,
},
],
},
···
if (take.length === 0) {
return;
}
await db
.update(takesTable)
.set({
···
})
.where(eq(takesTable.id, takeId));
-
const takeDuration = calculateElapsedTime(
-
JSON.parse(take[0]?.periods as string),
-
);
-
await slackClient.chat.postMessage({
channel: payload.user.id,
thread_ts: take[0]?.ts as string,
-
text: `take approved with multiplier \`${multiplier}\` so you have earned *${Number((takeDuration * Number(multiplier)) / 60).toFixed(1)} takes*!`,
});
// delete the message from the review channel
···
name: "fire",
});
await slackClient.chat.postMessage({
channel: payload.channel,
thread_ts: payload.thread_ts,
···
elements: [
{
type: "mrkdwn",
+
text: `take by <@${user}> for \`${prettyPrintTime(take.elapsedTimeMs)}\` working on: *${take.description}*`,
},
],
},
···
type: "section",
text: {
type: "mrkdwn",
+
text: `:video_camera: new take uploaded by <@${user}> for \`${prettyPrintTime(take.elapsedTimeMs)}\` working on: *${take.description}*`,
},
},
{
···
elements: [
{
type: "mrkdwn",
+
text: `take by <@${user}> for \`${prettyPrintTime(take.elapsedTimeMs)}\` working on: *${take.description}*`,
},
],
},
···
if (take.length === 0) {
return;
}
+
const takeToApprove = take[0];
+
if (!takeToApprove) return;
+
await db
.update(takesTable)
.set({
···
})
.where(eq(takesTable.id, takeId));
await slackClient.chat.postMessage({
channel: payload.user.id,
thread_ts: take[0]?.ts as string,
+
text: `take approved with multiplier \`${multiplier}\` so you have earned *${Number((takeToApprove.elapsedTimeMs * Number(multiplier)) / 60).toFixed(1)} takes*!`,
});
// delete the message from the review channel