tangled
alpha
login
or
join now
dunkirk.sh
/
irc-slack-bridge
1
fork
atom
this repo has no description
1
fork
atom
overview
issues
pulls
pipelines
feat: add pfps for un mapped users
dunkirk.sh
3 months ago
1325701d
66238d72
verified
This commit was signed with the committer's
known signature
.
dunkirk.sh
SSH Key Fingerprint:
SHA256:DqcG0RXYExE26KiWo3VxJnsxswN1QNfTBvB+bdSpk80=
+24
-6
1 changed file
expand all
collapse all
unified
split
src
index.ts
+24
-6
src/index.ts
···
6
6
import { parseIRCFormatting, parseSlackMarkdown } from "./parser";
7
7
import type { CachetUser } from "./types";
8
8
9
9
+
// Default profile pictures for unmapped IRC users
10
10
+
const DEFAULT_AVATARS = [
11
11
+
"https://hc-cdn.hel1.your-objectstorage.com/s/v3/4183627c4d26c56c915e104a8a7374f43acd1733_pfp__1_.png",
12
12
+
"https://hc-cdn.hel1.your-objectstorage.com/s/v3/389b1e6bd4248a7e5dd88e14c1adb8eb01267080_pfp__2_.png",
13
13
+
"https://hc-cdn.hel1.your-objectstorage.com/s/v3/03011a5e59548191de058f33ccd1d1cb1d64f2a0_pfp__3_.png",
14
14
+
"https://hc-cdn.hel1.your-objectstorage.com/s/v3/f9c57b88fbd4633114c1864bcc2968db555dbd2a_pfp__4_.png",
15
15
+
"https://hc-cdn.hel1.your-objectstorage.com/s/v3/e61a8cabee5a749588125242747b65122fb94205_pfp.png",
16
16
+
];
17
17
+
18
18
+
// Hash function for stable avatar selection
19
19
+
function getAvatarForNick(nick: string): string {
20
20
+
let hash = 0;
21
21
+
for (let i = 0; i < nick.length; i++) {
22
22
+
hash = ((hash << 5) - hash) + nick.charCodeAt(i);
23
23
+
hash = hash & hash; // Convert to 32bit integer
24
24
+
}
25
25
+
return DEFAULT_AVATARS[Math.abs(hash) % DEFAULT_AVATARS.length];
26
26
+
}
27
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
99
-
let iconUrl: string | undefined;
118
118
+
let iconUrl: string;
100
119
101
120
if (userMapping) {
102
102
-
try {
103
103
-
iconUrl = `https://cachet.dunkirk.sh/users/${userMapping.slack_user_id}/r`;
104
104
-
} catch (error) {
105
105
-
console.error("Error fetching user info:", error);
106
106
-
}
121
121
+
iconUrl = `https://cachet.dunkirk.sh/users/${userMapping.slack_user_id}/r`;
122
122
+
} else {
123
123
+
// Use stable random avatar for unmapped users
124
124
+
iconUrl = getAvatarForNick(nick);
107
125
}
108
126
109
127
try {