tangled
alpha
login
or
join now
dunkirk.sh
/
smokie
1
fork
atom
a fun bot for the hc slack
1
fork
atom
overview
issues
pulls
pipelines
bug: stop spamming from working
dunkirk.sh
9 months ago
39287f5b
d2c347cf
verified
This commit was signed with the committer's
known signature
.
dunkirk.sh
SSH Key Fingerprint:
SHA256:DqcG0RXYExE26KiWo3VxJnsxswN1QNfTBvB+bdSpk80=
+39
-1
2 changed files
expand all
collapse all
unified
split
src
features
takes
handlers
upload.ts
libs
schema.ts
+38
-1
src/features/takes/handlers/upload.ts
···
12
12
13
13
export default async function upload() {
14
14
slackApp.anyMessage(async ({ payload, context }) => {
15
15
+
// Track user ID at the top level so it's available in catch block
16
16
+
const user = payload.user as string;
15
17
try {
16
16
-
const user = payload.user as string;
17
18
18
19
if (
19
20
payload.subtype === "bot_message" ||
···
68
69
});
69
70
return;
70
71
}
72
72
+
73
73
+
// Check if the user is already uploading - prevent multiple simultaneous uploads
74
74
+
if (userInDB.isUploading) {
75
75
+
await slackClient.chat.postMessage({
76
76
+
channel: payload.channel,
77
77
+
thread_ts: payload.ts,
78
78
+
text: "You already have an upload in progress. Please wait for it to complete before sending another one.",
79
79
+
});
80
80
+
81
81
+
await slackClient.reactions.add({
82
82
+
channel: payload.channel,
83
83
+
timestamp: payload.ts,
84
84
+
name: "hourglass_flowing_sand",
85
85
+
});
86
86
+
87
87
+
return;
88
88
+
}
89
89
+
90
90
+
// Set the upload lock
91
91
+
await db.update(usersTable)
92
92
+
.set({ isUploading: true })
93
93
+
.where(eq(usersTable.id, user));
71
94
72
95
// Add initial 'loading' reaction to indicate processing
73
96
await slackClient.reactions.add({
···
236
259
},
237
260
],
238
261
});
262
262
+
263
263
+
// Release the upload lock after successful processing
264
264
+
await db.update(usersTable)
265
265
+
.set({ isUploading: false })
266
266
+
.where(eq(usersTable.id, user));
239
267
} catch (error) {
240
268
console.error("Error handling file message:", error);
241
269
await slackClient.chat.postMessage({
···
261
289
timestamp: payload.ts,
262
290
name: "nukeboom",
263
291
});
292
292
+
293
293
+
// Release the upload lock in case of error
294
294
+
try {
295
295
+
await db.update(usersTable)
296
296
+
.set({ isUploading: false })
297
297
+
.where(eq(usersTable.id, user)); // Now user is in scope
298
298
+
} catch (lockError) {
299
299
+
console.error("Error releasing upload lock:", lockError);
300
300
+
}
264
301
265
302
Sentry.captureException(error, {
266
303
extra: {
+1
src/libs/schema.ts
···
32
32
lastTakeUploadDate: text("last_take_upload_date")
33
33
.notNull()
34
34
.default(TakesConfig.START_DATE.toISOString()),
35
35
+
isUploading: boolean("is_uploading").default(false).notNull(),
35
36
repoLink: text("repo_link"),
36
37
demoLink: text("demo_link"),
37
38
createdAt: text("created_at")