bridge discord stickers
This commit is contained in:
parent
456090ae51
commit
9dbc77b9dd
1 changed files with 44 additions and 3 deletions
|
@ -9,6 +9,7 @@ import { discordFetchUser, revoltFetchMessage } from "../util";
|
||||||
import { MessageEmbed, TextChannel } from "discord.js";
|
import { MessageEmbed, TextChannel } from "discord.js";
|
||||||
import { smartReplace } from "smart-replace";
|
import { smartReplace } from "smart-replace";
|
||||||
import { metrics } from "../metrics";
|
import { metrics } from "../metrics";
|
||||||
|
import { SendableEmbed } from "revolt-api";
|
||||||
|
|
||||||
const MAX_BRIDGED_FILE_SIZE = 8_000_000; // 8 MB
|
const MAX_BRIDGED_FILE_SIZE = 8_000_000; // 8 MB
|
||||||
const RE_MENTION_USER = /<@!*[0-9]+>/g;
|
const RE_MENTION_USER = /<@!*[0-9]+>/g;
|
||||||
|
@ -155,6 +156,43 @@ client.on('messageCreate', async message => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const autumnUrls: string[] = [];
|
const autumnUrls: string[] = [];
|
||||||
|
const stickerEmbeds: SendableEmbed[] = [];
|
||||||
|
|
||||||
|
if (message.stickers.size) {
|
||||||
|
for (const sticker of message.stickers) {
|
||||||
|
try {
|
||||||
|
logger.debug(`Downloading sticker ${sticker[0]} ${sticker[1].name}`);
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
const file = await axios.get(sticker[1].url, { responseType: 'arraybuffer' });
|
||||||
|
|
||||||
|
logger.debug(`Downloading sticker ${sticker[0]} finished, uploading to autumn`);
|
||||||
|
|
||||||
|
formData.append(
|
||||||
|
sticker[0],
|
||||||
|
file.data,
|
||||||
|
{
|
||||||
|
filename: sticker[1].name || sticker[0],
|
||||||
|
contentType: file.headers['content-type']
|
||||||
|
// I have no clue what "LOTTIE" is so I'll pretend it doesn't exist
|
||||||
|
?? sticker[1].format == "PNG" ? 'image/png' : "image/vnd.mozilla.apng"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const res = await axios.post(
|
||||||
|
`${AUTUMN_URL}/attachments`, formData, { headers: formData.getHeaders() }
|
||||||
|
);
|
||||||
|
|
||||||
|
logger.debug(`Uploading attachment ${sticker[0]} finished`);
|
||||||
|
|
||||||
|
stickerEmbeds.push({
|
||||||
|
colour: 'var(--primary-header)',
|
||||||
|
title: sticker[1].name,
|
||||||
|
media: res.data.id,
|
||||||
|
});
|
||||||
|
} catch (e) { console.error(e) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// todo: upload all attachments at once instead of sequentially
|
// todo: upload all attachments at once instead of sequentially
|
||||||
for (const a of message.attachments) {
|
for (const a of message.attachments) {
|
||||||
|
@ -212,9 +250,12 @@ client.on('messageCreate', async message => {
|
||||||
: "var(--foreground)"
|
: "var(--foreground)"
|
||||||
: undefined,
|
: undefined,
|
||||||
},
|
},
|
||||||
embeds: message.embeds.length
|
embeds: [
|
||||||
? message.embeds.map((e) => new GenericEmbed(e).toRevolt())
|
...stickerEmbeds,
|
||||||
: undefined,
|
...(message.embeds.length
|
||||||
|
? message.embeds.map((e) => new GenericEmbed(e).toRevolt())
|
||||||
|
: []),
|
||||||
|
],
|
||||||
attachments: autumnUrls.length ? autumnUrls : undefined,
|
attachments: autumnUrls.length ? autumnUrls : undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue