Full code coverage for lottie sticker
This commit is contained in:
parent
d02f86b342
commit
f3b7fcd1a3
2 changed files with 24 additions and 23 deletions
|
@ -497,25 +497,17 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
if (message.sticker_items) {
|
if (message.sticker_items) {
|
||||||
const stickerEvents = await Promise.all(message.sticker_items.map(async stickerItem => {
|
const stickerEvents = await Promise.all(message.sticker_items.map(async stickerItem => {
|
||||||
const format = file.stickerFormat.get(stickerItem.format_type)
|
const format = file.stickerFormat.get(stickerItem.format_type)
|
||||||
|
assert(format?.mime)
|
||||||
if (format?.mime === "lottie") {
|
if (format?.mime === "lottie") {
|
||||||
try {
|
const {mxc_url, info} = await lottie.convert(stickerItem)
|
||||||
const {mxc_url, info} = await lottie.convert(stickerItem)
|
return {
|
||||||
return {
|
$type: "m.sticker",
|
||||||
$type: "m.sticker",
|
"m.mentions": mentions,
|
||||||
"m.mentions": mentions,
|
body: stickerItem.name,
|
||||||
body: stickerItem.name,
|
info,
|
||||||
info,
|
url: mxc_url
|
||||||
url: mxc_url
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
return {
|
|
||||||
$type: "m.room.message",
|
|
||||||
"m.mentions": mentions,
|
|
||||||
msgtype: "m.notice",
|
|
||||||
body: `Failed to convert Lottie sticker:\n${e.toString()}\n${e.stack}`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (format?.mime) {
|
} else {
|
||||||
let body = stickerItem.name
|
let body = stickerItem.name
|
||||||
const sticker = guild.stickers.find(sticker => sticker.id === stickerItem.id)
|
const sticker = guild.stickers.find(sticker => sticker.id === stickerItem.id)
|
||||||
if (sticker && sticker.description) body += ` - ${sticker.description}`
|
if (sticker && sticker.description) body += ` - ${sticker.description}`
|
||||||
|
@ -529,12 +521,6 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
url: await file.uploadDiscordFileToMxc(file.sticker(stickerItem))
|
url: await file.uploadDiscordFileToMxc(file.sticker(stickerItem))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
$type: "m.room.message",
|
|
||||||
"m.mentions": mentions,
|
|
||||||
msgtype: "m.notice",
|
|
||||||
body: `Unsupported sticker format ${format?.mime}. Name: ${stickerItem.name}`
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
events.push(...stickerEvents)
|
events.push(...stickerEvents)
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,6 +224,21 @@ test("message2event: stickers", async t => {
|
||||||
}])
|
}])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("message2event: lottie sticker", async t => {
|
||||||
|
const events = await messageToEvent(data.message.lottie_sticker, data.guild.general, {})
|
||||||
|
t.deepEqual(events, [{
|
||||||
|
$type: "m.sticker",
|
||||||
|
"m.mentions": {},
|
||||||
|
body: "8",
|
||||||
|
info: {
|
||||||
|
mimetype: "image/png",
|
||||||
|
w: 160,
|
||||||
|
h: 160
|
||||||
|
},
|
||||||
|
url: "mxc://cadence.moe/ZtvvVbwMIdUZeovWVyGVFCeR"
|
||||||
|
}])
|
||||||
|
})
|
||||||
|
|
||||||
test("message2event: skull webp attachment with content", async t => {
|
test("message2event: skull webp attachment with content", async t => {
|
||||||
const events = await messageToEvent(data.message.skull_webp_attachment_with_content, data.guild.general, {})
|
const events = await messageToEvent(data.message.skull_webp_attachment_with_content, data.guild.general, {})
|
||||||
t.deepEqual(events, [{
|
t.deepEqual(events, [{
|
||||||
|
|
Loading…
Reference in a new issue