utility.presence: more image fixes
This commit is contained in:
parent
147e1d5028
commit
6176ba0b07
1 changed files with 65 additions and 36 deletions
|
@ -787,19 +787,62 @@ presence.callback = async function (msg, line) {
|
|||
|
||||
embed.description = descLines.join("\n");
|
||||
|
||||
if (activity.assets?.large_image) {
|
||||
let largeUrl;
|
||||
if (activity.assets.large_image.startsWith("mp:")) {
|
||||
largeUrl = activity.large_image.replace(
|
||||
"mp:",
|
||||
"https://media.discordapp.net/"
|
||||
);
|
||||
} else {
|
||||
largeUrl = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.large_image}.png`;
|
||||
}
|
||||
if (activity.assets) {
|
||||
if (activity.assets.large_image != null) {
|
||||
let largeUrl;
|
||||
if (activity.assets.large_image.startsWith("mp:")) {
|
||||
largeUrl = activity.large_image.replace(
|
||||
"mp:",
|
||||
"https://media.discordapp.net/"
|
||||
);
|
||||
} else {
|
||||
largeUrl = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.large_image}.png`;
|
||||
}
|
||||
|
||||
let smallUrl;
|
||||
if (activity.assets.small_image) {
|
||||
let smallUrl;
|
||||
if (activity.assets.small_image != null) {
|
||||
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 largeImage = await fetch(largeUrl)
|
||||
.then((res) => res.arrayBuffer())
|
||||
.then((b) => Buffer.from(b));
|
||||
const presenceImage = sharp(largeImage).resize(60, 60);
|
||||
if (smallUrl) {
|
||||
const smallImage = await fetch(smallUrl)
|
||||
.then((res) => res.arrayBuffer())
|
||||
.then((b) => Buffer.from(b));
|
||||
const smallImageBuffer = await sharp(smallImage)
|
||||
.resize(20, 20)
|
||||
.toBuffer();
|
||||
|
||||
presenceImage.composite([
|
||||
{
|
||||
input: smallImageBuffer,
|
||||
gravity: "southeast",
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
files.push({
|
||||
content: await presenceImage.toBuffer(),
|
||||
name: `${index}.png`,
|
||||
});
|
||||
embed.thumbnail = {
|
||||
url: `attachment://${index}.png`,
|
||||
};
|
||||
} 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:",
|
||||
|
@ -808,38 +851,24 @@ presence.callback = async function (msg, line) {
|
|||
} else {
|
||||
smallUrl = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.small_image}.png`;
|
||||
}
|
||||
}
|
||||
|
||||
const largeImage = await fetch(largeUrl)
|
||||
.then((res) => res.arrayBuffer())
|
||||
.then((b) => Buffer.from(b));
|
||||
const presenceImage = sharp(largeImage).resize(60, 60);
|
||||
if (smallUrl) {
|
||||
const smallImage = await fetch(smallUrl)
|
||||
.then((res) => res.arrayBuffer())
|
||||
.then((b) => Buffer.from(b));
|
||||
const smallImageBuffer = await sharp(smallImage)
|
||||
.resize(20, 20)
|
||||
const presenceImage = await sharp(smallImage)
|
||||
.resize(60, 60)
|
||||
.toBuffer();
|
||||
|
||||
presenceImage.composite([
|
||||
{
|
||||
input: smallImageBuffer,
|
||||
gravity: "southeast",
|
||||
},
|
||||
]);
|
||||
files.push({
|
||||
content: presenceImage,
|
||||
name: `${index}.png`,
|
||||
});
|
||||
embed.thumbnail = {
|
||||
url: `attachment://${index}.png`,
|
||||
};
|
||||
}
|
||||
|
||||
files.push({
|
||||
content: await presenceImage.toBuffer(),
|
||||
name: `${index}.png`,
|
||||
});
|
||||
embed.thumbnail = {
|
||||
url: `attachment://${index}.png`,
|
||||
};
|
||||
|
||||
embeds.push(embed);
|
||||
}
|
||||
embeds.push(embed);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue