a fun bot for the hc slack

bug: stop spamming from working

dunkirk.sh 39287f5b d2c347cf

verified
+39 -1
+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 + // Track user ID at the top level so it's available in catch block 16 + const user = payload.user as string; 15 17 try { 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 + 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)); 71 94 72 95 // Add initial 'loading' reaction to indicate processing 73 96 await slackClient.reactions.add({ ··· 236 259 }, 237 260 ], 238 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)); 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 + 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 + } 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 + 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")