Add GuildArchives.getUrl for getting the archive entry URL

This commit is contained in:
Dragory 2019-01-15 04:03:04 +02:00
parent a2b7038b71
commit 429653c66d
3 changed files with 9 additions and 5 deletions

View file

@ -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}`;
}
}

View file

@ -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
);

View file

@ -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(