a fun bot for the hc slack
at main 1.6 kB view raw
1import type { MessageResponse } from "../types"; 2import { db } from "../../../libs/db"; 3import { takes as takesTable, users as usersTable } from "../../../libs/schema"; 4import { eq, and, desc } from "drizzle-orm"; 5import { prettyPrintTime } from "../../../libs/time"; 6 7export default async function handleHome( 8 userId: string, 9): Promise<MessageResponse> { 10 const userFromDB = ( 11 await db 12 .select({ totalTakesTime: usersTable.totalTakesTime }) 13 .from(usersTable) 14 .where(eq(usersTable.id, userId)) 15 )[0]; 16 17 const takeTime = prettyPrintTime((userFromDB?.totalTakesTime ?? 0) * 1000); 18 19 return { 20 text: `You have logged ${takeTime} of takes!`, 21 response_type: "ephemeral", 22 blocks: [ 23 { 24 type: "section", 25 text: { 26 type: "mrkdwn", 27 text: "*Takes Stats*", 28 }, 29 }, 30 { 31 type: "section", 32 text: { 33 type: "mrkdwn", 34 text: `You have logged \`${takeTime}\` of takes!`, 35 }, 36 }, 37 { 38 type: "actions", 39 elements: [ 40 { 41 type: "button", 42 text: { 43 type: "plain_text", 44 text: "📋 History", 45 emoji: true, 46 }, 47 value: "history", 48 action_id: "takes_history", 49 }, 50 { 51 type: "button", 52 text: { 53 type: "plain_text", 54 text: "⚙️ Settings", 55 emoji: true, 56 }, 57 value: "settings", 58 action_id: "takes_settings", 59 }, 60 { 61 type: "button", 62 text: { 63 type: "plain_text", 64 text: "🔄 Refresh", 65 emoji: true, 66 }, 67 value: "status", 68 action_id: "takes_home", 69 }, 70 ], 71 }, 72 ], 73 }; 74}