mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-06 07:56:11 +02:00
added user-fetching functionality on build
This commit is contained in:
committed by
Jean-Philippe Sirois
parent
1d93f4e160
commit
1b6525f4b4
@@ -0,0 +1,34 @@
|
||||
const DEFAULT_AVATAR_MODULO = 5
|
||||
module.exports = {
|
||||
splitHash(identifier) {
|
||||
const hashLocation = identifier.lastIndexOf("#")
|
||||
|
||||
if (hashLocation === -1) {
|
||||
throw Error(`Invalid name format ${identifier}`)
|
||||
}
|
||||
|
||||
const name = identifier.slice(0, hashLocation)
|
||||
const hash = identifier.slice(hashLocation + 1)
|
||||
return [name, hash]
|
||||
},
|
||||
getDefaultAvatar(name) {
|
||||
const [_, hash] = this.splitHash(hashLocation)
|
||||
|
||||
const avatar = Number(hash) % DEFAULT_AVATAR_MODULO
|
||||
return `https://cdn.discordapp.com/embed/avatars/${avatar}.png`
|
||||
},
|
||||
resolveAuthor(users, author) {
|
||||
const target = users.find(user => user.identifier === author)
|
||||
const [name, hash] = this.splitHash(author)
|
||||
const avatar = target ? target.avatar : this.getDefaultAvatar(author)
|
||||
|
||||
return {
|
||||
name,
|
||||
hash,
|
||||
avatar,
|
||||
}
|
||||
},
|
||||
resolveAuthors(users, authors) {
|
||||
return authors.map(author => this.resolveAuthor(users, author))
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user