3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-17 15:15:02 +00:00

Message archive formatting tweaks and fixes; only emit deleteBulk event from SavedMessages if any messages were actually marked as deleted

This commit is contained in:
Dragory 2018-12-22 13:06:40 +02:00
parent 95ae2ff9ca
commit 29782bbfda
5 changed files with 36 additions and 26 deletions

View file

@ -11,10 +11,9 @@ 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_MESSAGE_FORMAT =
"[#{channel.name}] [{user.id}] [{timestamp}] {user.username}#{user.discriminator}: {content}{attachments}";
const MESSAGE_ARCHIVE_FOOTER_FORMAT = trimLines(`
Log file generated on {timestamp}
Expires at {expires}
@ -65,22 +64,20 @@ export class GuildArchives extends BaseRepository {
return result.identifiers[0].id;
}
createFromSavedMessages(
savedMessages: SavedMessage[],
guild: Guild,
channel: Channel = null,
user: User = null,
expiresAt = null
) {
createFromSavedMessages(savedMessages: SavedMessage[], guild: Guild, expiresAt = null) {
if (expiresAt == null) expiresAt = moment().add(DEFAULT_EXPIRY_DAYS, "days");
const headerStr = formatTemplateString(MESSAGE_ARCHIVE_HEADER_FORMAT, { guild, channel, user });
const headerStr = formatTemplateString(MESSAGE_ARCHIVE_HEADER_FORMAT, { guild });
const msgLines = savedMessages.map(msg => {
const channel = guild.channels.get(msg.channel_id);
const user = { ...msg.data.author, id: msg.user_id };
return formatTemplateString(MESSAGE_ARCHIVE_MESSAGE_FORMAT, {
id: msg.id,
timestamp: moment(msg.posted_at).format("HH:mm:ss"),
timestamp: moment(msg.posted_at).format("YYYY-MM-DD HH:mm:ss"),
content: msg.data.content,
user
user,
channel
});
});
const messagesStr = msgLines.join("\n");