From 429653c66d04b96258c72d9ff3ba5328ed3bca0e Mon Sep 17 00:00:00 2001 From: Dragory Date: Tue, 15 Jan 2019 04:03:04 +0200 Subject: [PATCH] Add GuildArchives.getUrl for getting the archive entry URL --- src/data/GuildArchives.ts | 4 ++++ src/plugins/Logs.ts | 4 ++-- src/plugins/Spam.ts | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/data/GuildArchives.ts b/src/data/GuildArchives.ts index d33d68a4..a7007d43 100644 --- a/src/data/GuildArchives.ts +++ b/src/data/GuildArchives.ts @@ -90,4 +90,8 @@ export class GuildArchives extends BaseRepository { return this.create([headerStr, messagesStr].join("\n\n"), expiresAt); } + + getUrl(baseUrl, archiveId) { + return baseUrl ? `${baseUrl}/archives/${archiveId}` : `Archive ID: ${archiveId}`; + } } diff --git a/src/plugins/Logs.ts b/src/plugins/Logs.ts index 47afc7de..daed6c0e 100644 --- a/src/plugins/Logs.ts +++ b/src/plugins/Logs.ts @@ -341,14 +341,14 @@ export class LogsPlugin extends Plugin { async onMessageDeleteBulk(savedMessages: SavedMessage[]) { const channel = this.guild.channels.get(savedMessages[0].channel_id); const archiveId = await this.archives.createFromSavedMessages(savedMessages, this.guild); - const baseUrl = this.knub.getGlobalConfig().url; + const archiveUrl = this.archives.getUrl(this.knub.getGlobalConfig().url, archiveId); this.guildLogs.log( LogType.MESSAGE_DELETE_BULK, { count: savedMessages.length, channel, - archiveUrl: `${baseUrl}/archives/${archiveId}` + archiveUrl }, savedMessages[0].id ); diff --git a/src/plugins/Spam.ts b/src/plugins/Spam.ts index f185b453..ae19f4b7 100644 --- a/src/plugins/Spam.ts +++ b/src/plugins/Spam.ts @@ -43,7 +43,7 @@ const MAX_INTERVAL = 300; const SPAM_ARCHIVE_EXPIRY_DAYS = 90; export class SpamPlugin extends Plugin { - public static pluginName = 'spam'; + public static pluginName = "spam"; protected actions: GuildActions; protected logs: GuildLogs; @@ -163,8 +163,8 @@ export class SpamPlugin extends Plugin { const expiresAt = moment().add(SPAM_ARCHIVE_EXPIRY_DAYS, "days"); const archiveId = await this.archives.createFromSavedMessages(savedMessages, this.guild, expiresAt); - const url = this.knub.getGlobalConfig().url; - return url ? `${url}/archives/${archiveId}` : `Archive ID: ${archiveId}`; + const baseUrl = this.knub.getGlobalConfig().url; + return this.archives.getUrl(baseUrl, archiveId); } async logAndDetectSpam(