Standardize how message summaries are generated in logs
This commit is contained in:
parent
65dfa27eaf
commit
081c7d0ac3
2 changed files with 33 additions and 24 deletions
|
@ -27,8 +27,8 @@
|
||||||
"ROLE_DELETE": "🖊 Role **{role.name}** (`{role.id}`) was deleted",
|
"ROLE_DELETE": "🖊 Role **{role.name}** (`{role.id}`) was deleted",
|
||||||
"ROLE_EDIT": "🖊 Role **{role.name}** (`{role.id}`) was edited",
|
"ROLE_EDIT": "🖊 Role **{role.name}** (`{role.id}`) was edited",
|
||||||
|
|
||||||
"MESSAGE_EDIT": "✏ {userMention(member)} edited their message in {channelMention(channel)}:\nBefore:```{before}```After:```{after}```",
|
"MESSAGE_EDIT": "✏ {userMention(member)} edited their message in {channelMention(channel)}:\n\n**Before:**{messageSummary(before)}\n**After:**{messageSummary(after)}",
|
||||||
"MESSAGE_DELETE": "🗑 Message from {userMention(member)} deleted in {channelMention(channel)} (originally posted at **{messageDate}**):\n```{messageText}```{attachments}{embeds}",
|
"MESSAGE_DELETE": "🗑 Message from {userMention(member)} deleted in {channelMention(channel)} (originally posted at **{messageDate}**):{messageSummary(message)}",
|
||||||
"MESSAGE_DELETE_BULK": "🗑 **{count}** messages deleted in {channelMention(channel)} ({archiveUrl})",
|
"MESSAGE_DELETE_BULK": "🗑 **{count}** messages deleted in {channelMention(channel)} ({archiveUrl})",
|
||||||
"MESSAGE_DELETE_BARE": "🗑 Message (`{messageId}`) deleted in {channelMention(channel)} (no more info available)",
|
"MESSAGE_DELETE_BARE": "🗑 Message (`{messageId}`) deleted in {channelMention(channel)} (no more info available)",
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { decorators as d, IPluginOptions, logger } from "knub";
|
import { decorators as d, IPluginOptions, logger } from "knub";
|
||||||
import { GuildLogs } from "../data/GuildLogs";
|
import { GuildLogs } from "../data/GuildLogs";
|
||||||
import { LogType } from "../data/LogType";
|
import { LogType } from "../data/LogType";
|
||||||
import { Channel, Constants as ErisConstants, Embed, Member, TextChannel, User } from "eris";
|
import { Attachment, Channel, Constants as ErisConstants, Embed, Member, TextChannel, User } from "eris";
|
||||||
import {
|
import {
|
||||||
createChunkedMessage,
|
createChunkedMessage,
|
||||||
deactivateMentions,
|
deactivateMentions,
|
||||||
|
@ -10,6 +10,7 @@ import {
|
||||||
findRelevantAuditLogEntry,
|
findRelevantAuditLogEntry,
|
||||||
noop,
|
noop,
|
||||||
stripObjectToScalars,
|
stripObjectToScalars,
|
||||||
|
trimLines,
|
||||||
UnknownUser,
|
UnknownUser,
|
||||||
useMediaUrls,
|
useMediaUrls,
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
|
@ -188,6 +189,24 @@ export class LogsPlugin extends ZeppelinPlugin<ILogsPluginConfig> {
|
||||||
if (!channel) return "";
|
if (!channel) return "";
|
||||||
return `<#${channel.id}> (**#${channel.name}**, \`${channel.id}\`)`;
|
return `<#${channel.id}> (**#${channel.name}**, \`${channel.id}\`)`;
|
||||||
},
|
},
|
||||||
|
messageSummary: (msg: SavedMessage) => {
|
||||||
|
// Regular text content
|
||||||
|
let result = "```" + (msg.data.content ? disableCodeBlocks(msg.data.content) : "<no text content>") + "```";
|
||||||
|
|
||||||
|
// Rich embed
|
||||||
|
const richEmbed = (msg.data.embeds || []).find(e => (e as Embed).type === "rich");
|
||||||
|
if (richEmbed) result += "Embed:```" + JSON.stringify(richEmbed) + "```";
|
||||||
|
|
||||||
|
// Attachments
|
||||||
|
if (msg.data.attachments) {
|
||||||
|
result +=
|
||||||
|
"Attachments:\n" +
|
||||||
|
msg.data.attachments.map((a: Attachment) => disableLinkPreviews(a.url)).join("\n") +
|
||||||
|
"\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof TemplateParseError) {
|
if (e instanceof TemplateParseError) {
|
||||||
|
@ -198,6 +217,8 @@ export class LogsPlugin extends ZeppelinPlugin<ILogsPluginConfig> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
formatted = formatted.trim();
|
||||||
|
|
||||||
const timestampFormat = config.format.timestamp;
|
const timestampFormat = config.format.timestamp;
|
||||||
if (timestampFormat) {
|
if (timestampFormat) {
|
||||||
const timestamp = moment().format(timestampFormat);
|
const timestamp = moment().format(timestampFormat);
|
||||||
|
@ -431,21 +452,11 @@ export class LogsPlugin extends ZeppelinPlugin<ILogsPluginConfig> {
|
||||||
const member = this.guild.members.get(savedMessage.user_id);
|
const member = this.guild.members.get(savedMessage.user_id);
|
||||||
const channel = this.guild.channels.get(savedMessage.channel_id);
|
const channel = this.guild.channels.get(savedMessage.channel_id);
|
||||||
|
|
||||||
let oldMessageContent = oldSavedMessage.data.content || "<no text content>";
|
|
||||||
if (oldRichEmbed) {
|
|
||||||
oldMessageContent += "\n\nEmbed:\n\n" + JSON.stringify(oldRichEmbed);
|
|
||||||
}
|
|
||||||
|
|
||||||
let newMessageContent = savedMessage.data.content || "<no text content>";
|
|
||||||
if (newRichEmbed) {
|
|
||||||
newMessageContent += "\n\nEmbed:\n\n" + JSON.stringify(newRichEmbed);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.guildLogs.log(LogType.MESSAGE_EDIT, {
|
this.guildLogs.log(LogType.MESSAGE_EDIT, {
|
||||||
member: stripObjectToScalars(member, ["user"]),
|
member: stripObjectToScalars(member, ["user"]),
|
||||||
channel: stripObjectToScalars(channel),
|
channel: stripObjectToScalars(channel),
|
||||||
before: disableCodeBlocks(deactivateMentions(oldMessageContent)),
|
before: oldSavedMessage,
|
||||||
after: disableCodeBlocks(deactivateMentions(newMessageContent)),
|
after: savedMessage,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,22 +469,20 @@ export class LogsPlugin extends ZeppelinPlugin<ILogsPluginConfig> {
|
||||||
const channel = this.guild.channels.get(savedMessage.channel_id);
|
const channel = this.guild.channels.get(savedMessage.channel_id);
|
||||||
|
|
||||||
if (member) {
|
if (member) {
|
||||||
const attachments = savedMessage.data.attachments
|
// Replace attachment URLs with media URLs
|
||||||
? "\nAttachments:\n" + savedMessage.data.attachments.map((a: any) => a.url).join("\n")
|
if (savedMessage.data.attachments) {
|
||||||
: "";
|
for (const attachment of savedMessage.data.attachments as Attachment[]) {
|
||||||
|
attachment.url = useMediaUrls(attachment.url);
|
||||||
const richEmbed = (savedMessage.data.embeds || []).find(e => (e as Embed).type === "rich");
|
}
|
||||||
const embeds = richEmbed ? "\nEmbeds:\n```" + disableCodeBlocks(JSON.stringify(richEmbed)) + "```" : "";
|
}
|
||||||
|
|
||||||
this.guildLogs.log(
|
this.guildLogs.log(
|
||||||
LogType.MESSAGE_DELETE,
|
LogType.MESSAGE_DELETE,
|
||||||
{
|
{
|
||||||
member: stripObjectToScalars(member, ["user"]),
|
member: stripObjectToScalars(member, ["user"]),
|
||||||
channel: stripObjectToScalars(channel),
|
channel: stripObjectToScalars(channel),
|
||||||
messageText: disableCodeBlocks(deactivateMentions(savedMessage.data.content || "<no text content>")),
|
|
||||||
messageDate: moment(savedMessage.data.timestamp, "x").format(this.getConfig().format.timestamp),
|
messageDate: moment(savedMessage.data.timestamp, "x").format(this.getConfig().format.timestamp),
|
||||||
attachments: disableLinkPreviews(useMediaUrls(attachments)),
|
message: savedMessage,
|
||||||
embeds,
|
|
||||||
},
|
},
|
||||||
savedMessage.id,
|
savedMessage.id,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue