d2m username colors #107
1 changed files with 13 additions and 3 deletions
assign role colors to d2m users
commit
d7ad37e407
|
|
@ -113,8 +113,9 @@ async function userToGlobalProfile(user) {
|
|||
/**
|
||||
* @param {DiscordTypes.APIUser} user
|
||||
* @param {Omit<DiscordTypes.APIGuildMember, "user"> | undefined} member
|
||||
* @param {DiscordTypes.APIGuild} guild
|
||||
*/
|
||||
async function memberToStateContent(user, member, guildID) {
|
||||
async function memberToStateContent(user, member, guild) {
|
||||
let displayname = user.username
|
||||
if (user.global_name) displayname = user.global_name
|
||||
if (member?.nick) displayname = member.nick
|
||||
|
|
@ -134,11 +135,20 @@ async function memberToStateContent(user, member, guildID) {
|
|||
|
||||
if (member?.avatar || user.avatar) {
|
||||
// const avatarPath = file.userAvatar(user) // the user avatar only
|
||||
const avatarPath = file.memberAvatar(guildID, user, member) // the member avatar or the user avatar
|
||||
const avatarPath = file.memberAvatar(guild.id, user, member) // the member avatar or the user avatar
|
||||
content["moe.cadence.ooye.member"].avatar = avatarPath
|
||||
content.avatar_url = await file.uploadDiscordFileToMxc(avatarPath)
|
||||
}
|
||||
|
||||
const colorRole = member ? guild.roles.find(role => role.colors.primary_color && member.roles.includes(role.id)) : undefined
|
||||
if (colorRole) {
|
||||
const encoded = `#${colorRole.colors.primary_color.toString(16).padStart(6, "0")}`
|
||||
content["eu.she-a.color"] = {
|
||||
"on_dark": encoded,
|
||||
"on_light": encoded
|
||||
}
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +229,7 @@ function _hashProfileContent(content, powerLevel) {
|
|||
*/
|
||||
async function syncUser(user, member, channel, guild, roomID, interactionMetadata) {
|
||||
const mxid = await ensureSimJoined(user, roomID)
|
||||
const content = await memberToStateContent(user, member, guild.id)
|
||||
const content = await memberToStateContent(user, member, guild)
|
||||
const powerLevel = memberToPowerLevel(user, member, guild, channel)
|
||||
await _sendSyncUser(roomID, mxid, content, powerLevel, {
|
||||
// do not overwrite pre-existing data if we already have data and `member` is not accessible, because this would replace good data with bad data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue