Created
January 6, 2024 21:24
-
-
Save jeffangelion/207b2af3dd4a7e3d0bebff7bb10367af to your computer and use it in GitHub Desktop.
Get empty userpic color by Telegram ID as an official client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/telegramdesktop/tdesktop/blob/2ef8136308e31e07988ee4654b73ae2a5ab495dc/Telegram/SourceFiles/ui/empty_userpic.cpp#L257 | |
// https://github.com/telegramdesktop/tdesktop/blob/dev/Telegram/SourceFiles/ui/chat/chat_style.cpp#L1033 | |
struct Color { | |
red u8 | |
green u8 | |
blue u8 | |
} | |
fn (c Color) str() string { | |
return '#${c.red.hex()}${c.green.hex()}${c.blue.hex()}'.to_upper() | |
} | |
fn pick_color(id u64) Color { | |
colors := { | |
// historyPeer1UserpicBg — ff845e | |
// red | |
0: Color { | |
red: 255 | |
green: 132 | |
blue: 94 | |
} | |
// historyPeer2UserpicBg — 9ad164 | |
// green | |
1: Color { | |
red: 154 | |
green: 209 | |
blue: 100 | |
} | |
// historyPeer3UserpicBg — e5ca77 (unused) | |
// yellow (unused) | |
2: Color { | |
red: 229 | |
green: 202 | |
blue: 119 | |
} | |
// historyPeer4UserpicBg — 5caffa | |
// blue | |
3: Color { | |
red: 92 | |
green: 175 | |
blue: 250 | |
} | |
// historyPeer5UserpicBg — b694f9 | |
// purple | |
4: Color { | |
red: 182 | |
green: 148 | |
blue: 249 | |
} | |
// historyPeer6UserpicBg — ff8aac | |
// pink | |
5: Color { | |
red: 255 | |
green: 138 | |
blue: 172 | |
} | |
// historyPeer7UserpicBg — 5bcbe3 | |
// sea | |
6: Color { | |
red: 91 | |
green: 203 | |
blue: 227 | |
} | |
// historyPeer8UserpicBg — febb5b | |
// orange | |
7: Color { | |
red: 254 | |
green: 187 | |
blue: 91 | |
} | |
} | |
color_order := [0 7 4 1 6 3 5] | |
return colors[color_order[id % 7]] | |
} | |
fn main() { | |
println(pick_color().str()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment