mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35: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:
parent
dee4637a7f
commit
ce0b7ded08
5 changed files with 36 additions and 26 deletions
|
@ -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");
|
||||
|
|
|
@ -180,23 +180,31 @@ export class GuildSavedMessages extends BaseRepository {
|
|||
this.events.emit("delete", [deleted]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the specified messages as deleted in the database (if they weren't already marked before).
|
||||
* If any messages were marked as deleted, also emits the deleteBulk event.
|
||||
*/
|
||||
async markBulkAsDeleted(ids) {
|
||||
const deletedAt = moment().format("YYYY-MM-DD HH:mm:ss.SSS");
|
||||
|
||||
await this.messages
|
||||
.createQueryBuilder()
|
||||
.update()
|
||||
.set({
|
||||
deleted_at: () => "NOW(3)"
|
||||
})
|
||||
.set({ deleted_at: deletedAt })
|
||||
.where("guild_id = :guild_id", { guild_id: this.guildId })
|
||||
.andWhere("id IN (:ids)", { ids })
|
||||
.andWhere("deleted_at IS NULL")
|
||||
.execute();
|
||||
|
||||
const deleted = await this.messages
|
||||
.createQueryBuilder()
|
||||
.where("id IN (:ids)", { ids })
|
||||
.where("deleted_at = :deletedAt", { deletedAt })
|
||||
.getMany();
|
||||
|
||||
this.events.emit("deleteBulk", [deleted]);
|
||||
if (deleted.length) {
|
||||
this.events.emit("deleteBulk", [deleted]);
|
||||
}
|
||||
}
|
||||
|
||||
async saveEdit(id, newData: ISavedMessageData) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue