···
238
-
// Parse Slack mentions and replace with display names
238
+
// Parse Slack mentions and replace with IRC nicks or display names
let messageText = payload.text;
240
-
const mentionRegex = /<@(U[A-Z0-9]+)>/g;
240
+
const mentionRegex = /<@(U[A-Z0-9]+)(\|([^>]+))?>/g;
const mentions = Array.from(messageText.matchAll(mentionRegex));
for (const match of mentions) {
246
-
const response = await fetch(
247
-
`https://cachet.dunkirk.sh/users/${userId}`,
249
-
// @ts-ignore - Bun specific option
250
-
tls: { rejectUnauthorized: false },
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 |
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}`);
255
+
// Fallback to Cachet lookup
257
+
const response = await fetch(
258
+
`https://cachet.dunkirk.sh/users/${userId}`,
260
+
// @ts-ignore - Bun specific option
261
+
tls: { rejectUnauthorized: false },
265
+
const data = (await response.json()) as CachetUser;
266
+
messageText = messageText.replace(match[0], `@${data.displayName}`);
269
+
console.error(`Error fetching user ${userId} from cachet:`, error);
258
-
console.error(`Error fetching user ${userId} from cachet:`, error);