Coverage for role and emoji converter
This commit is contained in:
parent
8439512f1a
commit
7029247461
2 changed files with 16 additions and 5 deletions
|
@ -52,11 +52,8 @@ function getDiscordParseCallbacks(message, guild, useHTML) {
|
|||
emoji: node => {
|
||||
if (useHTML) {
|
||||
const mxc = select("emoji", "mxc_url", {emoji_id: node.id}).pluck().get()
|
||||
if (mxc) {
|
||||
assert(mxc) // All emojis should have been added ahead of time in the messageToEvent function.
|
||||
return `<img data-mx-emoticon height="32" src="${mxc}" title=":${node.name}:" alt=":${node.name}:">`
|
||||
} else { // We shouldn't get here since all emojis should have been added ahead of time in the messageToEvent function.
|
||||
return `<img src="mxc://cadence.moe/${node.id}" data-mx-emoticon alt=":${node.name}:" title=":${node.name}:" height="24">`
|
||||
}
|
||||
} else {
|
||||
return `:${node.name}:`
|
||||
}
|
||||
|
@ -64,7 +61,9 @@ function getDiscordParseCallbacks(message, guild, useHTML) {
|
|||
role: node => {
|
||||
const role = guild.roles.find(r => r.id === node.id)
|
||||
if (!role) {
|
||||
return "@&" + node.id // fallback for if the cache breaks. if this happens, fix discord-packets.js to store the role info.
|
||||
// This fallback should only trigger if somebody manually writes a silly message, or if the cache breaks (hasn't happened yet).
|
||||
// If the cache breaks, fix discord-packets.js to store role info properly.
|
||||
return "@&" + node.id
|
||||
} else if (useHTML && role.color) {
|
||||
return `<font color="#${role.color.toString(16)}">@${role.name}</font>`
|
||||
} else if (useHTML) {
|
||||
|
|
|
@ -85,6 +85,18 @@ test("message2event: simple role mentions", async t => {
|
|||
}])
|
||||
})
|
||||
|
||||
test("message2event: manually constructed unknown roles should use fallback", async t => {
|
||||
const events = await messageToEvent(data.message.unknown_role, data.guild.general, {})
|
||||
t.deepEqual(events, [{
|
||||
$type: "m.room.message",
|
||||
"m.mentions": {},
|
||||
msgtype: "m.text",
|
||||
body: "I'm just @&4 testing a few role pings <@&B> don't mind me",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: "I'm just @&4 testing a few role pings <@&B> don't mind me"
|
||||
}])
|
||||
})
|
||||
|
||||
test("message2event: simple message link", async t => {
|
||||
const events = await messageToEvent(data.message.simple_message_link, data.guild.general, {})
|
||||
t.deepEqual(events, [{
|
||||
|
|
Loading…
Reference in a new issue