mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
More rework progress, mostly done up to ModActions
This commit is contained in:
parent
52839cc9f3
commit
57893e7f76
38 changed files with 199 additions and 241 deletions
|
@ -1,10 +1,11 @@
|
|||
import { downloadFile } from "../../utils";
|
||||
import fs from "fs";
|
||||
import { MessageAttachment, MessageOptions, TextChannel } from "discord.js";
|
||||
const fsp = fs.promises;
|
||||
|
||||
const MAX_ATTACHMENT_REHOST_SIZE = 1024 * 1024 * 8;
|
||||
|
||||
export async function rehostAttachment(attachment: Attachment, targetChannel: TextChannel): Promise<string> {
|
||||
export async function rehostAttachment(attachment: MessageAttachment, targetChannel: TextChannel): Promise<string> {
|
||||
if (attachment.size > MAX_ATTACHMENT_REHOST_SIZE) {
|
||||
return "Attachment too big to rehost";
|
||||
}
|
||||
|
@ -17,11 +18,9 @@ export async function rehostAttachment(attachment: Attachment, targetChannel: Te
|
|||
}
|
||||
|
||||
try {
|
||||
const rehostMessage = await targetChannel.createMessage(`Rehost of attachment ${attachment.id}`, {
|
||||
name: attachment.filename,
|
||||
file: await fsp.readFile(downloaded.path),
|
||||
});
|
||||
return rehostMessage.attachments[0].url;
|
||||
const content: MessageOptions = { content: `Rehost of attachment ${attachment.id}`, files: [{ name: attachment.name ? attachment.name : undefined, attachment: await fsp.readFile(downloaded.path)}]}
|
||||
const rehostMessage = await targetChannel.send({ content, split: false });
|
||||
return rehostMessage.attachments.values()[0].url;
|
||||
} catch {
|
||||
return "Failed to rehost attachment";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue