···
import { takes as takesTable } from "../../../libs/schema";
import { eq, and } from "drizzle-orm";
import { prettyPrintTime } from "../../../libs/time";
6
-
import { calculateElapsedTime } from "../../../libs/time-periods";
6
+
import * as Sentry from "@sentry/bun";
export default async function upload() {
slackApp.anyMessage(async ({ payload }) => {
···
console.error("Error handling file message:", error);
227
+
await slackClient.chat.postMessage({
228
+
channel: payload.channel,
229
+
thread_ts: payload.thread_ts,
230
+
text: ":warning: there was an error processing your upload",
233
+
Sentry.captureException(error, {
235
+
channel: payload.channel,
236
+
user: payload.user,
237
+
thread_ts: payload.thread_ts,
240
+
type: "file_upload_error",
slackApp.action("select_multiplier", async () => {});
slackApp.action("approve", async ({ payload, context }) => {
233
-
const multiplier = Object.values(payload.state.values)[0]
234
-
?.select_multiplier?.selected_option?.value;
235
-
// @ts-expect-error
236
-
const takeId = payload.actions[0]?.value;
250
+
const multiplier = Object.values(payload.state.values)[0]
251
+
?.select_multiplier?.selected_option?.value;
252
+
// @ts-expect-error
253
+
const takeId = payload.actions[0]?.value;
238
-
const take = await db
241
-
.where(eq(takesTable.id, takeId));
242
-
if (take.length === 0) {
245
-
const takeToApprove = take[0];
246
-
if (!takeToApprove) return;
255
+
const take = await db
258
+
.where(eq(takesTable.id, takeId));
259
+
if (take.length === 0) {
262
+
const takeToApprove = take[0];
263
+
if (!takeToApprove) return;
266
+
.update(takesTable)
268
+
status: "approved",
269
+
multiplier: multiplier,
271
+
.where(eq(takesTable.id, takeId));
249
-
.update(takesTable)
251
-
status: "approved",
252
-
multiplier: multiplier,
254
-
.where(eq(takesTable.id, takeId));
273
+
await slackClient.chat.postMessage({
274
+
channel: payload.user.id,
275
+
thread_ts: take[0]?.ts as string,
276
+
text: `take approved with multiplier \`${multiplier}\` so you have earned *${Number((takeToApprove.elapsedTimeMs * Number(multiplier)) / 60).toFixed(1)} takes*!`,
256
-
await slackClient.chat.postMessage({
257
-
channel: payload.user.id,
258
-
thread_ts: take[0]?.ts as string,
259
-
text: `take approved with multiplier \`${multiplier}\` so you have earned *${Number((takeToApprove.elapsedTimeMs * Number(multiplier)) / 60).toFixed(1)} takes*!`,
279
+
// delete the message from the review channel
280
+
if (context.respond)
281
+
await context.respond({
282
+
delete_original: true,
285
+
console.error("Error approving take:", error);
262
-
// delete the message from the review channel
263
-
if (context.respond)
264
-
await context.respond({
265
-
delete_original: true,
287
+
await slackClient.chat.postEphemeral({
288
+
channel: process.env.SLACK_REVIEW_CHANNEL || "",
289
+
user: payload.user.id,
290
+
text: ":warning: there was an error approving the take",
293
+
Sentry.captureException(error, {
295
+
// @ts-expect-error
296
+
take: payload.actions[0]?.value,
297
+
userApproving: payload.user,
300
+
type: "take_approve_error",
slackApp.action("reject", async ({ payload, context }) => {
270
-
// @ts-expect-error
271
-
const takeId = payload.actions[0]?.value;
308
+
// @ts-expect-error
309
+
const takeId = payload.actions[0]?.value;
273
-
const take = await db
276
-
.where(eq(takesTable.id, takeId));
277
-
if (take.length === 0) {
281
-
.update(takesTable)
283
-
status: "rejected",
286
-
.where(eq(takesTable.id, takeId));
311
+
const take = await db
314
+
.where(eq(takesTable.id, takeId));
315
+
if (take.length === 0) {
319
+
.update(takesTable)
321
+
status: "rejected",
324
+
.where(eq(takesTable.id, takeId));
326
+
await slackClient.chat.postMessage({
327
+
channel: payload.user.id,
328
+
thread_ts: take[0]?.ts as string,
329
+
text: "take rejected :(",
332
+
// delete the message from the review channel
333
+
if (context.respond)
334
+
await context.respond({
335
+
delete_original: true,
338
+
console.error("Error rejecting take:", error);
288
-
await slackClient.chat.postMessage({
289
-
channel: payload.user.id,
290
-
thread_ts: take[0]?.ts as string,
291
-
text: "take rejected :(",
340
+
await slackClient.chat.postEphemeral({
341
+
channel: process.env.SLACK_REVIEW_CHANNEL || "",
342
+
user: payload.user.id,
343
+
text: ":warning: there was an error rejecting the take",
294
-
// delete the message from the review channel
295
-
if (context.respond)
296
-
await context.respond({
297
-
delete_original: true,
346
+
Sentry.captureException(error, {
348
+
// @ts-expect-error
349
+
take: payload.actions[0]?.value,
350
+
userRejecting: payload.user,
353
+
type: "take_reject_error",