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

Allow making archives permanent. Make archives permanent when attached to a case. Add log file metadata dynamically when served (instead of in the body directly). Add missing index on archives.expires_at.

This commit is contained in:
Dragory 2019-01-13 17:29:26 +02:00
parent 10d757f588
commit ab71481b8f
5 changed files with 59 additions and 13 deletions

View file

@ -14,10 +14,6 @@ const MESSAGE_ARCHIVE_HEADER_FORMAT = trimLines(`
`);
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}
`);
export class GuildArchives extends BaseRepository {
protected archives: Repository<ArchiveEntry>;
@ -35,6 +31,7 @@ export class GuildArchives extends BaseRepository {
this.archives
.createQueryBuilder()
.where("guild_id = :guild_id", { guild_id: this.guildId })
.andWhere("expires_at IS NOT NULL")
.andWhere("expires_at <= NOW()")
.delete()
.execute();
@ -47,6 +44,15 @@ export class GuildArchives extends BaseRepository {
});
}
async makePermanent(id: string): Promise<void> {
await this.archives.update(
{ id },
{
expires_at: null
}
);
}
/**
* @returns ID of the created entry
*/
@ -81,11 +87,7 @@ export class GuildArchives extends BaseRepository {
});
});
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);
return this.create([headerStr, messagesStr].join("\n\n"), expiresAt);
}
}

View file

@ -1,4 +1,4 @@
import { Entity, Column, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm";
@Entity("archives")
export class ArchiveEntry {