utility.presence: remap media proxy urls
This commit is contained in:
parent
95b24f8e7f
commit
8c95848a70
1 changed files with 72 additions and 2 deletions
|
@ -1907,7 +1907,30 @@ presence.callback = async function (msg, line) {
|
|||
largeUrl = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.large_image}.png`;
|
||||
}
|
||||
|
||||
image_links.push(`[Large Image](${largeUrl})`);
|
||||
let fixedLargeUrl = largeUrl;
|
||||
if (fixedLargeUrl.includes("media.discordapp.net")) {
|
||||
if (fixedLargeUrl.includes("/external/")) {
|
||||
const split = fixedLargeUrl
|
||||
.replace("https://media.discordapp.net/external/", "")
|
||||
.split("/");
|
||||
split.shift();
|
||||
|
||||
let query = "";
|
||||
if (split[0].startsWith("%")) {
|
||||
query = decodeURIComponent(split.shift());
|
||||
}
|
||||
split[0] = split[0] + ":/";
|
||||
|
||||
fixedLargeUrl = split.join("/") + query;
|
||||
} else {
|
||||
fixedLargeUrl = fixedLargeUrl.replace(
|
||||
"media.discordapp.net",
|
||||
"cdn.discordapp.com"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
image_links.push(`[Large Image](${fixedLargeUrl})`);
|
||||
|
||||
let smallUrl;
|
||||
if (activity.assets.small_image != null) {
|
||||
|
@ -1925,7 +1948,30 @@ presence.callback = async function (msg, line) {
|
|||
smallUrl = `https://cdn.discordapp.com/app-assets/${activity.application_id}/${activity.assets.small_image}.png`;
|
||||
}
|
||||
|
||||
image_links.push(`[Small Image](${smallUrl})`);
|
||||
let fixedSmallUrl = smallUrl;
|
||||
if (fixedSmallUrl.includes("media.discordapp.net")) {
|
||||
if (fixedSmallUrl.includes("/external/")) {
|
||||
const split = fixedSmallUrl
|
||||
.replace("https://media.discordapp.net/external/", "")
|
||||
.split("/");
|
||||
split.shift();
|
||||
|
||||
let query = "";
|
||||
if (split[0].startsWith("%")) {
|
||||
query = decodeURIComponent(split.shift());
|
||||
}
|
||||
split[0] = split[0] + ":/";
|
||||
|
||||
fixedSmallUrl = split.join("/") + query;
|
||||
} else {
|
||||
fixedSmallUrl = fixedSmallUrl.replace(
|
||||
"media.discordapp.net",
|
||||
"cdn.discordapp.com"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
image_links.push(`[Small Image](${fixedSmallUrl})`);
|
||||
}
|
||||
|
||||
const largeImage = await fetch(largeUrl)
|
||||
|
@ -1987,6 +2033,30 @@ presence.callback = async function (msg, line) {
|
|||
embed.thumbnail = {
|
||||
url: `attachment://${index}.png`,
|
||||
};
|
||||
|
||||
let fixedSmallUrl = smallUrl;
|
||||
if (fixedSmallUrl.includes("media.discordapp.net")) {
|
||||
if (fixedSmallUrl.includes("/external/")) {
|
||||
const split = fixedSmallUrl
|
||||
.replace("https://media.discordapp.net/external/", "")
|
||||
.split("/");
|
||||
split.shift();
|
||||
|
||||
let query = "";
|
||||
if (split[0].startsWith("%")) {
|
||||
query = decodeURIComponent(split.shift());
|
||||
}
|
||||
split[0] = split[0] + ":/";
|
||||
|
||||
fixedSmallUrl = split.join("/") + query;
|
||||
} else {
|
||||
fixedSmallUrl = fixedSmallUrl.replace(
|
||||
"media.discordapp.net",
|
||||
"cdn.discordapp.com"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
embed.fields.push({
|
||||
name: "\u200b",
|
||||
value: `[Small Image](${smallUrl})`,
|
||||
|
|
Loading…
Reference in a new issue