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
|
@ -51,7 +51,7 @@ export const ArchiveChannelCmd = channelArchiverCmd({
|
|||
let previousId: string | undefined;
|
||||
|
||||
const startTime = Date.now();
|
||||
const progressMsg = await msg.channel.createMessage("Creating archive...");
|
||||
const progressMsg = await msg.channel.send("Creating archive...");
|
||||
const progressUpdateInterval = setInterval(() => {
|
||||
const secondsSinceStart = Math.round((Date.now() - startTime) / 1000);
|
||||
progressMsg
|
||||
|
@ -61,16 +61,16 @@ export const ArchiveChannelCmd = channelArchiverCmd({
|
|||
|
||||
while (archivedMessages < maxMessagesToArchive) {
|
||||
const messagesToFetch = Math.min(MAX_MESSAGES_PER_FETCH, maxMessagesToArchive - archivedMessages);
|
||||
const messages = await args.channel.getMessages(messagesToFetch, previousId);
|
||||
if (messages.length === 0) break;
|
||||
const messages = await args.channel.messages.fetch({ limit: messagesToFetch, before: previousId });
|
||||
if (messages.size === 0) break;
|
||||
|
||||
for (const message of messages) {
|
||||
const ts = moment.utc(message.timestamp).format("YYYY-MM-DD HH:mm:ss");
|
||||
for (const message of messages.values()) {
|
||||
const ts = moment.utc(message.createdTimestamp).format("YYYY-MM-DD HH:mm:ss");
|
||||
let content = `[${ts}] [${message.author.id}] [${message.author.username}#${
|
||||
message.author.discriminator
|
||||
}]: ${message.content || "<no text content>"}`;
|
||||
|
||||
if (message.attachments.length) {
|
||||
if (message.attachments.size) {
|
||||
if (args["attachment-channel"]) {
|
||||
const rehostedAttachmentUrl = await rehostAttachment(message.attachments[0], args["attachment-channel"]);
|
||||
content += `\n-- Attachment: ${rehostedAttachmentUrl}`;
|
||||
|
@ -104,9 +104,6 @@ export const ArchiveChannelCmd = channelArchiverCmd({
|
|||
result += `\n\n${archiveLines.join("\n")}\n`;
|
||||
|
||||
progressMsg.delete().catch(noop);
|
||||
msg.channel.createMessage("Archive created!", {
|
||||
file: Buffer.from(result),
|
||||
name: `archive-${args.channel.name}-${moment.utc().format("YYYY-MM-DD-HH-mm-ss")}.txt`,
|
||||
});
|
||||
msg.channel.send({ content: "Archive created!", files: [{attachment: Buffer.from(result), name: `archive-${args.channel.name}-${moment.utc().format("YYYY-MM-DD-HH-mm-ss")}.txt`}], split: false });
|
||||
},
|
||||
});
|
||||
|
|
|
@ -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