this repo has no description

feat: add pfps for un mapped users

dunkirk.sh 1325701d 66238d72

verified
+24 -6
+24 -6
src/index.ts
··· 6 6 import { parseIRCFormatting, parseSlackMarkdown } from "./parser"; 7 7 import type { CachetUser } from "./types"; 8 8 9 + // Default profile pictures for unmapped IRC users 10 + const DEFAULT_AVATARS = [ 11 + "https://hc-cdn.hel1.your-objectstorage.com/s/v3/4183627c4d26c56c915e104a8a7374f43acd1733_pfp__1_.png", 12 + "https://hc-cdn.hel1.your-objectstorage.com/s/v3/389b1e6bd4248a7e5dd88e14c1adb8eb01267080_pfp__2_.png", 13 + "https://hc-cdn.hel1.your-objectstorage.com/s/v3/03011a5e59548191de058f33ccd1d1cb1d64f2a0_pfp__3_.png", 14 + "https://hc-cdn.hel1.your-objectstorage.com/s/v3/f9c57b88fbd4633114c1864bcc2968db555dbd2a_pfp__4_.png", 15 + "https://hc-cdn.hel1.your-objectstorage.com/s/v3/e61a8cabee5a749588125242747b65122fb94205_pfp.png", 16 + ]; 17 + 18 + // Hash function for stable avatar selection 19 + function getAvatarForNick(nick: string): string { 20 + let hash = 0; 21 + for (let i = 0; i < nick.length; i++) { 22 + hash = ((hash << 5) - hash) + nick.charCodeAt(i); 23 + hash = hash & hash; // Convert to 32bit integer 24 + } 25 + return DEFAULT_AVATARS[Math.abs(hash) % DEFAULT_AVATARS.length]; 26 + } 27 + 9 28 const missingEnvVars = []; 10 29 if (!process.env.SLACK_BOT_TOKEN) missingEnvVars.push("SLACK_BOT_TOKEN"); 11 30 if (!process.env.SLACK_SIGNING_SECRET) ··· 96 115 const userMapping = userMappings.getByIrcNick(nick); 97 116 98 117 const displayName = `${nick} <irc>`; 99 - let iconUrl: string | undefined; 118 + let iconUrl: string; 100 119 101 120 if (userMapping) { 102 - try { 103 - iconUrl = `https://cachet.dunkirk.sh/users/${userMapping.slack_user_id}/r`; 104 - } catch (error) { 105 - console.error("Error fetching user info:", error); 106 - } 121 + iconUrl = `https://cachet.dunkirk.sh/users/${userMapping.slack_user_id}/r`; 122 + } else { 123 + // Use stable random avatar for unmapped users 124 + iconUrl = getAvatarForNick(nick); 107 125 } 108 126 109 127 try {