-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutil.js
More file actions
27 lines (21 loc) · 787 Bytes
/
util.js
File metadata and controls
27 lines (21 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const DISCORD_CDN = 'https://cdn.discordapp.com'
export function userAvatar({id, discriminator, avatar}, {size = 512}) {
if (avatar) {
return `${DISCORD_CDN}/avatars/${id}/${avatar}.webp?size=${size}`
} else {
return `${DISCORD_CDN}/embed/avatars/${parseInt(discriminator) % 5}.png?size=${size}`
}
}
export function guildIcon({id, icon}, {size = 512}) {
if (!icon) return null
return `${DISCORD_CDN}/icons/${id}/${icon}.webp?size=${size}`
}
export function hasBitFlag(value, bit) {
if (!value) return false
const shifted = 1 << bit;
return (value & shifted) === shifted
}
export function formatTimestamp(timestamp) {
const date = new Date(timestamp * 1000)
return `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`
}