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)
|
globalProfile.avatar_url = await file.uploadDiscordFileToMxc(avatarPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (user.accent_color) {
|
||||||
|
globalProfile.name_color = `#${user.accent_color.toString(16).padStart(6, "0")}`
|
||||||
|
}
|
||||||
|
|
||||||
return globalProfile
|
return globalProfile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -248,9 +252,9 @@ async function syncUser(user, member, channel, guild, roomID, interactionMetadat
|
||||||
/**
|
/**
|
||||||
* @param {string} roomID
|
* @param {string} roomID
|
||||||
* @param {string} mxid
|
* @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 {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) {
|
async function _sendSyncUser(roomID, mxid, content, powerLevel, options) {
|
||||||
const currentHash = _hashProfileContent(content, powerLevel ?? 0)
|
const currentHash = _hashProfileContent(content, powerLevel ?? 0)
|
||||||
|
|
@ -272,6 +276,10 @@ async function _sendSyncUser(roomID, mxid, content, powerLevel, options) {
|
||||||
if (await supportsMsc4069) {
|
if (await supportsMsc4069) {
|
||||||
actions.push(api.profileSetDisplayname(mxid, options?.globalProfile?.displayname || content.displayname, true))
|
actions.push(api.profileSetDisplayname(mxid, options?.globalProfile?.displayname || content.displayname, true))
|
||||||
actions.push(api.profileSetAvatarUrl(mxid, options?.globalProfile?.avatar_url || content.avatar_url, 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)
|
await Promise.all(actions)
|
||||||
// Update cached hash
|
// Update cached hash
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,8 @@ async function onPacket(client, message, listen) {
|
||||||
// Role doesn't already exist.
|
// Role doesn't already exist.
|
||||||
guild.roles.push(...newRoles)
|
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") {
|
} 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() {
|
async function ping() {
|
||||||
// not using mreq so that we can read the status code
|
// not using mreq so that we can read the status code
|
||||||
const res = await fetch(mreq.baseUrl + route`/client/v1/appservice/${reg.id}/ping`, {
|
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.sendTyping = sendTyping
|
||||||
module.exports.profileSetDisplayname = profileSetDisplayname
|
module.exports.profileSetDisplayname = profileSetDisplayname
|
||||||
module.exports.profileSetAvatarUrl = profileSetAvatarUrl
|
module.exports.profileSetAvatarUrl = profileSetAvatarUrl
|
||||||
|
module.exports.profileSetNameColor = profileSetNameColor
|
||||||
module.exports.ping = ping
|
module.exports.ping = ping
|
||||||
module.exports.previewUrlIfEnabled = previewUrlIfEnabled
|
module.exports.previewUrlIfEnabled = previewUrlIfEnabled
|
||||||
module.exports.getMedia = getMedia
|
module.exports.getMedia = getMedia
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue