this repo has no description
1
fork

Configure Feed

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

feat: use irc nicks perfered over display names and cachet

+27 -15
+27 -15
src/index.ts
··· 235 235 userInfo.user?.name || 236 236 "Unknown"; 237 237 238 - // Parse Slack mentions and replace with display names 238 + // Parse Slack mentions and replace with IRC nicks or display names 239 239 let messageText = payload.text; 240 - const mentionRegex = /<@(U[A-Z0-9]+)>/g; 240 + const mentionRegex = /<@(U[A-Z0-9]+)(\|([^>]+))?>/g; 241 241 const mentions = Array.from(messageText.matchAll(mentionRegex)); 242 242 243 243 for (const match of mentions) { 244 244 const userId = match[1]; 245 - try { 246 - const response = await fetch( 247 - `https://cachet.dunkirk.sh/users/${userId}`, 248 - { 249 - // @ts-ignore - Bun specific option 250 - tls: { rejectUnauthorized: false }, 251 - }, 252 - ); 253 - if (response.ok) { 254 - const data = (await response.json()) as CachetUser; 255 - messageText = messageText.replace(match[0], `@${data.displayName}`); 245 + const displayName = match[3]; // The name part after | 246 + 247 + // Check if user has a mapped IRC nick 248 + const mentionedUserMapping = userMappings.getBySlackUser(userId); 249 + if (mentionedUserMapping) { 250 + messageText = messageText.replace(match[0], `@${mentionedUserMapping.irc_nick}`); 251 + } else if (displayName) { 252 + // Use the display name from the mention format <@U123|name> 253 + messageText = messageText.replace(match[0], `@${displayName}`); 254 + } else { 255 + // Fallback to Cachet lookup 256 + try { 257 + const response = await fetch( 258 + `https://cachet.dunkirk.sh/users/${userId}`, 259 + { 260 + // @ts-ignore - Bun specific option 261 + tls: { rejectUnauthorized: false }, 262 + }, 263 + ); 264 + if (response.ok) { 265 + const data = (await response.json()) as CachetUser; 266 + messageText = messageText.replace(match[0], `@${data.displayName}`); 267 + } 268 + } catch (error) { 269 + console.error(`Error fetching user ${userId} from cachet:`, error); 256 270 } 257 - } catch (error) { 258 - console.error(`Error fetching user ${userId} from cachet:`, error); 259 271 } 260 272 } 261 273