add support for acronym guild icons

This commit is contained in:
bignutty 2024-12-20 20:53:31 +01:00
parent a68f5ab3e7
commit c8783b12bc
3 changed files with 26 additions and 14 deletions

16
labscore/utils/guilds.js Normal file
View file

@ -0,0 +1,16 @@
function getAcronym(guildName){
// Based on discord-web
return guildName.replace(/'s /g, " ").replace(/\w+/g, e => e[0]).replace(/\s/g, "")
}
function getGuildIcon(guild){
return (guild.iconUrl ?
guild.iconUrl + "?size=4096" :
// Removes emojis from the icon since this api doesn't support them, todo for the future maybe build our own image generation service for these.
"https://ui-avatars.com/api/?background=333339&color=fff&size=512&uppercase=false&length=999&name=" + encodeURIComponent(getAcronym(guild.name).replace(/(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?)*/g, '')))
}
module.exports = {
getAcronym,
getGuildIcon
}