mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-17 15:15:02 +00:00
Create archives from bulk deletes and cleans. Use GuildSavedMessages for cleans.
This commit is contained in:
parent
4a65b94cc3
commit
2c561afe1a
9 changed files with 176 additions and 145 deletions
|
@ -3,9 +3,23 @@ import moment from "moment-timezone";
|
|||
import { ArchiveEntry } from "./entities/ArchiveEntry";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { BaseRepository } from "./BaseRepository";
|
||||
import { formatTemplateString, trimLines } from "../utils";
|
||||
import { SavedMessage } from "./entities/SavedMessage";
|
||||
import { Channel, Guild, User } from "eris";
|
||||
|
||||
const DEFAULT_EXPIRY_DAYS = 30;
|
||||
|
||||
const MESSAGE_ARCHIVE_HEADER_FORMAT = trimLines(`
|
||||
Server: {guild.name} ({guild.id})
|
||||
Channel: #{channel.name} ({channel.id})
|
||||
User: {user.username}#{user.discriminator} ({user.id})
|
||||
`);
|
||||
const MESSAGE_ARCHIVE_MESSAGE_FORMAT = "[MSG ID {id}] [{timestamp}] {user.username}: {content}{attachments}";
|
||||
const MESSAGE_ARCHIVE_FOOTER_FORMAT = trimLines(`
|
||||
Log file generated on {timestamp}
|
||||
Expires at {expires}
|
||||
`);
|
||||
|
||||
export class GuildArchives extends BaseRepository {
|
||||
protected archives: Repository<ArchiveEntry>;
|
||||
|
||||
|
@ -50,4 +64,31 @@ export class GuildArchives extends BaseRepository {
|
|||
|
||||
return result.identifiers[0].id;
|
||||
}
|
||||
|
||||
createFromSavedMessages(
|
||||
savedMessages: SavedMessage[],
|
||||
guild: Guild,
|
||||
channel: Channel = null,
|
||||
user: User = null,
|
||||
expiresAt = null
|
||||
) {
|
||||
if (expiresAt == null) expiresAt = moment().add(DEFAULT_EXPIRY_DAYS, "days");
|
||||
|
||||
const headerStr = formatTemplateString(MESSAGE_ARCHIVE_HEADER_FORMAT, { guild, channel, user });
|
||||
const msgLines = savedMessages.map(msg => {
|
||||
return formatTemplateString(MESSAGE_ARCHIVE_MESSAGE_FORMAT, {
|
||||
id: msg.id,
|
||||
timestamp: moment(msg.posted_at).format("HH:mm:ss"),
|
||||
content: msg.data.content,
|
||||
user
|
||||
});
|
||||
});
|
||||
const messagesStr = msgLines.join("\n");
|
||||
const footerStr = formatTemplateString(MESSAGE_ARCHIVE_FOOTER_FORMAT, {
|
||||
timestamp: moment().format("YYYY-MM-DD [at] HH:mm:ss (Z)"),
|
||||
expires: expiresAt.format("YYYY-MM-DD [at] HH:mm:ss (Z)")
|
||||
});
|
||||
|
||||
return this.create([headerStr, messagesStr, footerStr].join("\n\n"), expiresAt);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue