utility.presence: more image fixes

This commit is contained in:
Cynthia Foxwell 2022-10-10 13:21:17 -06:00
parent 147e1d5028
commit 6176ba0b07

View file

@ -787,7 +787,8 @@ presence.callback = async function (msg, line) {
embed.description = descLines.join("\n");
if (activity.assets?.large_image) {
if (activity.assets) {
if (activity.assets.large_image != null) {
let largeUrl;
if (activity.assets.large_image.startsWith("mp:")) {
largeUrl = activity.large_image.replace(
@ -799,7 +800,7 @@ presence.callback = async function (msg, line) {
}
let smallUrl;
if (activity.assets.small_image) {
if (activity.assets.small_image != null) {
if (activity.assets.small_image.startsWith("mp:")) {
smallUrl = activity.small_image.replace(
"mp:",
@ -837,9 +838,37 @@ presence.callback = async function (msg, line) {
embed.thumbnail = {
url: `attachment://${index}.png`,
};
embeds.push(embed);
} else if (
!activity.assets.large_image &&
activity.assets.small_image != null
) {
let smallUrl;
if (activity.assets.small_image.startsWith("mp:")) {
smallUrl = activity.small_image.replace(
"mp:",
"https://media.discordapp.net/"
);
} else {
smallUrl = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.small_image}.png`;
}
const smallImage = await fetch(smallUrl)
.then((res) => res.arrayBuffer())
.then((b) => Buffer.from(b));
const presenceImage = await sharp(smallImage)
.resize(60, 60)
.toBuffer();
files.push({
content: presenceImage,
name: `${index}.png`,
});
embed.thumbnail = {
url: `attachment://${index}.png`,
};
}
}
embeds.push(embed);
}
}