fancy live pfps
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add second slack

+17 -11
+17 -11
index.ts
··· 1 1 const ATPROTO_STATUS_URI = 2 2 "at://did:plc:krxbvxvis5skq7jj6eot23ul/fm.teal.alpha.actor.status/self"; 3 - const SLACK_TOKEN = process.env.SLACK_TOKEN; 3 + const SLACK_TOKENS = [ 4 + process.env.SLACK_TOKEN, 5 + process.env.SLACK_TOKEN_2, 6 + ].filter(Boolean) as string[]; 4 7 const POLL_INTERVAL = 30_000; // 30s 5 8 const PORT = parseInt(process.env.PORT || "3000", 10); 6 9 ··· 38 41 type PfpState = "default" | "headphones" | "zz"; 39 42 40 43 let currentState: PfpState = "default"; 41 - let lastSlackUpdate: string | null = null; 44 + const lastSlackUpdate = new Map<string, string>(); 42 45 43 46 // --- Music detection --- 44 47 ··· 47 50 const data = await fetchAtUriRecord(ATPROTO_STATUS_URI); 48 51 if (!data?.value?.item) return false; 49 52 const expiry = new Date(data.value.expiry).getTime(); 50 - return Date.now() <= expiry; 53 + return Date.now() <= expiry + 5 * 60_000; 51 54 } catch { 52 55 return false; 53 56 } ··· 74 77 75 78 // --- Slack --- 76 79 77 - async function updateSlackPfp(imagePath: string) { 78 - if (!SLACK_TOKEN) return; 79 - if (lastSlackUpdate === imagePath) return; 80 + async function updateSlackPfp(token: string, label: string, imagePath: string) { 81 + if (lastSlackUpdate.get(token) === imagePath) return; 80 82 81 83 const file = Bun.file(imagePath); 82 84 const blob = await file.arrayBuffer(); ··· 86 88 87 89 const res = await fetch("https://slack.com/api/users.setPhoto", { 88 90 method: "POST", 89 - headers: { Authorization: `Bearer ${SLACK_TOKEN}` }, 91 + headers: { Authorization: `Bearer ${token}` }, 90 92 body: form, 91 93 }); 92 94 93 95 const data = await res.json(); 94 96 if (data.ok) { 95 - lastSlackUpdate = imagePath; 96 - console.log(`[slack] updated pfp to ${imagePath}`); 97 + lastSlackUpdate.set(token, imagePath); 98 + console.log(`[slack:${label}] updated pfp to ${imagePath}`); 97 99 } else { 98 - console.error(`[slack] failed to update pfp:`, data.error); 100 + console.error(`[slack:${label}] failed to update pfp:`, data.error); 99 101 } 100 102 } 101 103 ··· 109 111 110 112 currentState = state; 111 113 112 - await updateSlackPfp(imagePath); 114 + await Promise.all( 115 + SLACK_TOKENS.map((token, i) => 116 + updateSlackPfp(token, i === 0 ? "primary" : `workspace-${i + 1}`, imagePath) 117 + ) 118 + ); 113 119 } 114 120 115 121 tick();