3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-11 04:45: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 dee4637a7f
commit ce0b7ded08
5 changed files with 36 additions and 26 deletions

View file

@ -326,8 +326,7 @@ export class LogsPlugin extends Plugin {
// Uses events from savesMessages
async onMessageDeleteBulk(savedMessages: SavedMessage[]) {
const channel = this.guild.channels.get(savedMessages[0].channel_id);
const user = this.bot.users.get(savedMessages[0].user_id);
const archiveId = await this.archives.createFromSavedMessages(savedMessages, this.guild, channel, user);
const archiveId = await this.archives.createFromSavedMessages(savedMessages, this.guild);
const baseUrl = this.knub.getGlobalConfig().url;
this.guildLogs.log(

View file

@ -157,9 +157,9 @@ export class SpamPlugin extends Plugin {
this.recentActions = this.recentActions.filter(action => action.timestamp >= expiryTimestamp);
}
async saveSpamArchives(savedMessages: SavedMessage[], channel: Channel, user: User) {
async saveSpamArchives(savedMessages: SavedMessage[], channel: Channel) {
const expiresAt = moment().add(SPAM_ARCHIVE_EXPIRY_DAYS, "days");
const archiveId = await this.archives.createFromSavedMessages(savedMessages, this.guild, channel, user, expiresAt);
const archiveId = await this.archives.createFromSavedMessages(savedMessages, this.guild, expiresAt);
const url = this.knub.getGlobalConfig().url;
return url ? `${url}/archives/${archiveId}` : `Archive ID: ${archiveId}`;
@ -249,8 +249,7 @@ export class SpamPlugin extends Plugin {
// Generate a log from the detected messages
const channel = this.guild.channels.get(savedMessage.channel_id);
const user = this.bot.users.get(savedMessage.user_id);
const archiveUrl = await this.saveSpamArchives(uniqueMessages, channel, user);
const archiveUrl = await this.saveSpamArchives(uniqueMessages, channel);
// Create a case and log the actions taken above
const caseType = spamConfig.mute ? CaseTypes.Mute : CaseTypes.Note;

View file

@ -140,13 +140,20 @@ export class UtilityPlugin extends ZeppelinPlugin {
this.logs.ignoreLog(LogType.MESSAGE_DELETE, savedMessages[0].id);
this.logs.ignoreLog(LogType.MESSAGE_DELETE_BULK, savedMessages[0].id);
// Delete & archive in ID order
savedMessages = Array.from(savedMessages).sort((a, b) => (a.id > b.id ? 1 : -1));
const idsToDelete = savedMessages.map(m => m.id);
// Make sure the deletions aren't double logged
idsToDelete.forEach(id => this.logs.ignoreLog(LogType.MESSAGE_DELETE, id));
this.logs.ignoreLog(LogType.MESSAGE_DELETE_BULK, idsToDelete[0]);
// Actually delete the messages
await this.bot.deleteMessages(channel.id, idsToDelete);
await this.savedMessages.markBulkAsDeleted(idsToDelete);
savedMessages.reverse();
const user = this.bot.users.get(savedMessages[0].user_id);
const archiveId = await this.archives.createFromSavedMessages(savedMessages, this.guild, channel, user);
// Create an archive
const archiveId = await this.archives.createFromSavedMessages(savedMessages, this.guild);
const archiveUrl = `${this.knub.getGlobalConfig().url}/archives/${archiveId}`;
this.logs.log(LogType.CLEAN, {