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
13
export default async function upload() {
14
slackApp.anyMessage(async ({ payload, context }) => {
0
0
15
try {
16
-
const user = payload.user as string;
17
18
if (
19
payload.subtype === "bot_message" ||
···
68
});
69
return;
70
}
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
71
72
// Add initial 'loading' reaction to indicate processing
73
await slackClient.reactions.add({
···
236
},
237
],
238
});
0
0
0
0
0
239
} catch (error) {
240
console.error("Error handling file message:", error);
241
await slackClient.chat.postMessage({
···
261
timestamp: payload.ts,
262
name: "nukeboom",
263
});
0
0
0
0
0
0
0
0
0
264
265
Sentry.captureException(error, {
266
extra: {
···
12
13
export default async function upload() {
14
slackApp.anyMessage(async ({ payload, context }) => {
15
+
// Track user ID at the top level so it's available in catch block
16
+
const user = payload.user as string;
17
try {
0
18
19
if (
20
payload.subtype === "bot_message" ||
···
69
});
70
return;
71
}
72
+
73
+
// Check if the user is already uploading - prevent multiple simultaneous uploads
74
+
if (userInDB.isUploading) {
75
+
await slackClient.chat.postMessage({
76
+
channel: payload.channel,
77
+
thread_ts: payload.ts,
78
+
text: "You already have an upload in progress. Please wait for it to complete before sending another one.",
79
+
});
80
+
81
+
await slackClient.reactions.add({
82
+
channel: payload.channel,
83
+
timestamp: payload.ts,
84
+
name: "hourglass_flowing_sand",
85
+
});
86
+
87
+
return;
88
+
}
89
+
90
+
// Set the upload lock
91
+
await db.update(usersTable)
92
+
.set({ isUploading: true })
93
+
.where(eq(usersTable.id, user));
94
95
// Add initial 'loading' reaction to indicate processing
96
await slackClient.reactions.add({
···
259
},
260
],
261
});
262
+
263
+
// Release the upload lock after successful processing
264
+
await db.update(usersTable)
265
+
.set({ isUploading: false })
266
+
.where(eq(usersTable.id, user));
267
} catch (error) {
268
console.error("Error handling file message:", error);
269
await slackClient.chat.postMessage({
···
289
timestamp: payload.ts,
290
name: "nukeboom",
291
});
292
+
293
+
// Release the upload lock in case of error
294
+
try {
295
+
await db.update(usersTable)
296
+
.set({ isUploading: false })
297
+
.where(eq(usersTable.id, user)); // Now user is in scope
298
+
} catch (lockError) {
299
+
console.error("Error releasing upload lock:", lockError);
300
+
}
301
302
Sentry.captureException(error, {
303
extra: {
+1
src/libs/schema.ts
···
32
lastTakeUploadDate: text("last_take_upload_date")
33
.notNull()
34
.default(TakesConfig.START_DATE.toISOString()),
0
35
repoLink: text("repo_link"),
36
demoLink: text("demo_link"),
37
createdAt: text("created_at")
···
32
lastTakeUploadDate: text("last_take_upload_date")
33
.notNull()
34
.default(TakesConfig.START_DATE.toISOString()),
35
+
isUploading: boolean("is_uploading").default(false).notNull(),
36
repoLink: text("repo_link"),
37
demoLink: text("demo_link"),
38
createdAt: text("created_at")