d2m username colors #107
3 changed files with 35 additions and 10 deletions
also write accent color to profile
commit
1e717a1e59
|
|
@ -107,6 +107,10 @@ async function userToGlobalProfile(user) {
|
|||
globalProfile.avatar_url = await file.uploadDiscordFileToMxc(avatarPath)
|
||||
}
|
||||
|
||||
if (user.accent_color) {
|
||||
globalProfile.name_color = `#${user.accent_color.toString(16).padStart(6, "0")}`
|
||||
}
|
||||
|
||||
return globalProfile
|
||||
}
|
||||
|
||||
|
|
@ -140,14 +144,14 @@ async function memberToStateContent(user, member, guild) {
|
|||
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
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
@ -248,9 +252,9 @@ async function syncUser(user, member, channel, guild, roomID, interactionMetadat
|
|||
/**
|
||||
* @param {string} roomID
|
||||
* @param {string} mxid
|
||||
* @param {{displayname: string, avatar_url?: string}} content
|
||||
* @param {{displayname: string, avatar_url?: string, "eu.she-a.color"?: {on_light: string, on_dark: string}}} content
|
||||
* @param {number | null} powerLevel
|
||||
* @param {{allowOverwrite?: boolean, globalProfile?: {displayname: string, avatar_url?: string}}} [options]
|
||||
* @param {{allowOverwrite?: boolean, globalProfile?: {displayname: string, avatar_url?: string, name_color?: string}}} [options]
|
||||
*/
|
||||
async function _sendSyncUser(roomID, mxid, content, powerLevel, options) {
|
||||
const currentHash = _hashProfileContent(content, powerLevel ?? 0)
|
||||
|
|
@ -272,6 +276,10 @@ async function _sendSyncUser(roomID, mxid, content, powerLevel, options) {
|
|||
if (await supportsMsc4069) {
|
||||
actions.push(api.profileSetDisplayname(mxid, options?.globalProfile?.displayname || content.displayname, true))
|
||||
actions.push(api.profileSetAvatarUrl(mxid, options?.globalProfile?.avatar_url || content.avatar_url, true))
|
||||
if (options?.globalProfile?.name_color || content["eu.she-a.color"]?.on_light) {
|
||||
// @ts-ignore
|
||||
actions.push(api.profileSetNameColor(mxid, options?.globalProfile?.name_color ?? content["eu.she-a.color"]?.on_light, true))
|
||||
}
|
||||
}
|
||||
await Promise.all(actions)
|
||||
// Update cached hash
|
||||
|
|
|
|||
|
|
@ -156,6 +156,8 @@ async function onPacket(client, message, listen) {
|
|||
// Role doesn't already exist.
|
||||
guild.roles.push(...newRoles)
|
||||
}
|
||||
// lower position values mean lower priority (`@everyone` has position 0)
|
||||
guild.roles.sort((a, b) => b.position - a.position)
|
||||
}
|
||||
|
||||
} else if (message.t === "GUILD_MEMBER_UPDATE") {
|
||||
|
|
|
|||
|
|
@ -449,6 +449,20 @@ async function profileSetAvatarUrl(mxid, avatar_url, inhibitPropagate) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} mxid
|
||||
* @param {string} color
|
||||
* @param {boolean} [inhibitPropagate]
|
||||
*/
|
||||
async function profileSetNameColor(mxid, color, inhibitPropagate) {
|
||||
const params = {}
|
||||
if (inhibitPropagate) params["org.matrix.msc4069.propagate"] = false
|
||||
await mreq.mreq("PUT", path(route`/client/v3/profile/${mxid}/eu.she-a.color`, mxid, params), {
|
||||
"on_light": color,
|
||||
"on_dark": color
|
||||
})
|
||||
}
|
||||
|
||||
async function ping() {
|
||||
// not using mreq so that we can read the status code
|
||||
const res = await fetch(mreq.baseUrl + route`/client/v1/appservice/${reg.id}/ping`, {
|
||||
|
|
@ -673,6 +687,7 @@ module.exports.redactEvent = redactEvent
|
|||
module.exports.sendTyping = sendTyping
|
||||
module.exports.profileSetDisplayname = profileSetDisplayname
|
||||
module.exports.profileSetAvatarUrl = profileSetAvatarUrl
|
||||
module.exports.profileSetNameColor = profileSetNameColor
|
||||
module.exports.ping = ping
|
||||
module.exports.previewUrlIfEnabled = previewUrlIfEnabled
|
||||
module.exports.getMedia = getMedia
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue