providing password reset services for a long while: circa 2025
at main 3.1 kB view raw
1import { slackApp } from "../index"; 2import { fetchUserData } from "./unfurl"; 3 4const summary = async () => { 5 slackApp.action("share-summary", async ({ context, payload }) => { 6 if (!context?.respond) return; 7 8 // @ts-expect-error 9 const interval = payload.actions[0].value; 10 const userData = await fetchUserData(context.userId, interval); 11 if (!userData) { 12 return; 13 } 14 15 const projectTotal = userData.projects.reduce((total, project) => { 16 return total + project.total; 17 }, 0); 18 userData.projects.sort((a, b) => b.total - a.total); 19 20 await context.respond({ 21 text: "sent to channel :3c:", 22 blocks: [ 23 { 24 type: "context", 25 elements: [ 26 { 27 type: "mrkdwn", 28 text: "sent to channel :3c:", 29 }, 30 ], 31 }, 32 ], 33 }); 34 35 await context.client.chat.postMessage({ 36 channel: context.channelId as string, 37 text: `here's a new hackatime summary for <@${context.userId}>!`, 38 blocks: [ 39 { 40 type: "section", 41 text: { 42 type: "mrkdwn", 43 text: `here's a new hackatime summary for <@${context.userId}>! :roo-yay:`, 44 }, 45 }, 46 { 47 type: "divider", 48 }, 49 { 50 type: "context", 51 elements: [ 52 { 53 type: "mrkdwn", 54 text: `they have spent ${Math.floor(projectTotal / 3600)} hours, ${Math.floor((projectTotal % 3600) / 60)} minutes, and ${projectTotal % 60} seconds coding in the ${interval.replaceAll("_", " ")}${interval.includes("days") || interval.includes("month") ? "" : " interval"}`, 55 }, 56 ], 57 }, 58 { 59 type: "divider", 60 }, 61 { 62 type: "context", 63 elements: [ 64 { 65 type: "mrkdwn", 66 text: `their most active project was \`${userData.projects[0].key}\`, where you spent ${Math.floor(userData.projects[0].total / 3600)} hours, ${Math.floor((userData.projects[0].total % 3600) / 60)} minutes, and ${userData.projects[0].total % 60} seconds`, 67 }, 68 ], 69 }, 70 { 71 type: "divider", 72 }, 73 { 74 type: "context", 75 elements: [ 76 { 77 type: "mrkdwn", 78 text: `here's a list of the rest of their projects:\n\n${userData.projects 79 .slice(1) 80 .map( 81 (project) => 82 `\`${project.key}\`: ${Math.floor(project.total / 3600)} hours, ${Math.floor((project.total % 3600) / 60)} minutes, and ${project.total % 60} seconds`, 83 ) 84 .join("\n")}`, 85 }, 86 ], 87 }, 88 { 89 type: "divider", 90 }, 91 { 92 type: "context", 93 elements: [ 94 { 95 type: "mrkdwn", 96 text: "get your own summary by running `/hackatime summary`!", 97 }, 98 ], 99 }, 100 ], 101 }); 102 }); 103}; 104 105export default summary;