fedi moji :3
This commit is contained in:
parent
a9b3d84366
commit
09846c524c
9 changed files with 100 additions and 31 deletions
|
|
@ -20,18 +20,7 @@ async function onMessage(client, event) {
|
|||
|
||||
if(emb.thumbnail && emb.thumbnail.url) {
|
||||
var avatar = document.createElement("img");
|
||||
var matrixUrl = client.cache.get("fedimbed_" + emb.thumbnail.url);
|
||||
if(!matrixUrl) {
|
||||
const buffer = await fetch(emb.thumbnail.url, {
|
||||
headers: {
|
||||
"User-Agent": "PossumBot/1.0 (+https://bot.possum.city/)",
|
||||
},
|
||||
}).then((res) => res.arrayBuffer()).then((buf) => Buffer.from(buf));
|
||||
const uploadResponse = await client.uploadContent(buffer, { rawResponse: false });
|
||||
matrixUrl = uploadResponse.content_uri;
|
||||
client.cache.set("fedimbed_" + emb.thumbnail.url, matrixUrl);
|
||||
}
|
||||
avatar.src = matrixUrl;
|
||||
avatar.src = await client.uploadMedia(emb.thumbnail.url);
|
||||
avatar.height = "16";
|
||||
link.appendChild(avatar);
|
||||
}
|
||||
|
|
@ -44,20 +33,19 @@ async function onMessage(client, event) {
|
|||
|
||||
var text = document.createElement("p");
|
||||
text.innerHTML = emb.description;
|
||||
|
||||
for(const emote of embed.emotes) {
|
||||
console.log(text.innerHTML);
|
||||
var img = document.createElement("img");
|
||||
img.src = await client.uploadMedia(emote.url);
|
||||
img.height = "16";
|
||||
img.alt = emote.name;
|
||||
text.innerHTML = text.innerHTML.replaceAll(emote.name, img.outerHTML);
|
||||
}
|
||||
|
||||
quote.appendChild(text);
|
||||
}
|
||||
for(const file of embed.files) {
|
||||
var matrixUrl = client.cache.get("fedimbed_" + file.url);
|
||||
if(!matrixUrl) {
|
||||
const buffer = await fetch(file.url, {
|
||||
headers: {
|
||||
"User-Agent": "PossumBot/1.0 (+https://bot.possum.city/)",
|
||||
},
|
||||
}).then((res) => res.arrayBuffer()).then((buf) => Buffer.from(buf));
|
||||
const uploadResponse = await client.uploadContent(buffer, { rawResponse: false });
|
||||
matrixUrl = uploadResponse.content_uri;
|
||||
client.cache.set("fedimbed_" + file.url, matrixUrl);
|
||||
}
|
||||
var media;
|
||||
switch(file.type.split("/")[0]) {
|
||||
case "audio":
|
||||
|
|
@ -70,7 +58,7 @@ async function onMessage(client, event) {
|
|||
media = document.createElement("img");
|
||||
break;
|
||||
}
|
||||
media.src = matrixUrl;
|
||||
media.src = await client.uploadMedia(file.url);
|
||||
media.alt = file.desc;
|
||||
quote.appendChild(media);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue