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
import { parseIRCFormatting, parseSlackMarkdown } from "./parser";
7
import type { CachetUser } from "./types";
8
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
9
const missingEnvVars = [];
10
if (!process.env.SLACK_BOT_TOKEN) missingEnvVars.push("SLACK_BOT_TOKEN");
11
if (!process.env.SLACK_SIGNING_SECRET)
···
96
const userMapping = userMappings.getByIrcNick(nick);
97
98
const displayName = `${nick} <irc>`;
99
-
let iconUrl: string | undefined;
100
101
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
-
}
107
}
108
109
try {
···
6
import { parseIRCFormatting, parseSlackMarkdown } from "./parser";
7
import type { CachetUser } from "./types";
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
+
28
const missingEnvVars = [];
29
if (!process.env.SLACK_BOT_TOKEN) missingEnvVars.push("SLACK_BOT_TOKEN");
30
if (!process.env.SLACK_SIGNING_SECRET)
···
115
const userMapping = userMappings.getByIrcNick(nick);
116
117
const displayName = `${nick} <irc>`;
118
+
let iconUrl: string;
119
120
if (userMapping) {
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);
0
125
}
126
127
try {