Skip to content

Commit

Permalink
Log forward & embed data to mod log on autowarn
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingMilkshake committed Jan 31, 2025
1 parent ac9034e commit c4cafb6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
48 changes: 25 additions & 23 deletions Events/MessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public static async Task MessageDeleted(DiscordClient client, MessageDeletedEven
await DiscordHelpers.DoEmptyThreadCleanupAsync(e.Channel, e.Message);
}

static async Task DeleteAndWarnAsync(DiscordMessage message, string reason, DiscordClient client)
static async Task DeleteAndWarnAsync(DiscordMessage message, string reason, DiscordClient client, string messageContentOverride = default)
{
await DeleteAndWarnAsync(new MockDiscordMessage(message), reason, client);
await DeleteAndWarnAsync(new MockDiscordMessage(message), reason, client, messageContentOverride: messageContentOverride);
}

static async Task DeleteAndWarnAsync(MockDiscordMessage message, string reason, DiscordClient client, bool wasAutoModBlock = false)
static async Task DeleteAndWarnAsync(MockDiscordMessage message, string reason, DiscordClient client, bool wasAutoModBlock = false, string messageContentOverride = default)
{
var channel = message.Channel;
DiscordMessage msg;
Expand All @@ -100,7 +100,7 @@ static async Task DeleteAndWarnAsync(MockDiscordMessage message, string reason,

try
{
_ = InvestigationsHelpers.SendInfringingMessaageAsync("mod", message, reason, null, wasAutoModBlock: wasAutoModBlock);
_ = InvestigationsHelpers.SendInfringingMessaageAsync("mod", message, reason, null, wasAutoModBlock: wasAutoModBlock, messageContentOverride: messageContentOverride);
}
catch
{
Expand All @@ -121,7 +121,8 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe

string msgContentWithEmbedData = message.Content;
var embeds = new List<DiscordEmbed>();
embeds.AddRange(message.Embeds);
if (message.Embeds is not null)
embeds.AddRange(message.Embeds.Where(embed => embed.Type != "auto_moderation_message"));

if (message.MessageSnapshots is not null)
foreach (var snapshot in message.MessageSnapshots)
Expand Down Expand Up @@ -347,8 +348,8 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
var mentionCount = message.MentionedUsers is not null && message.MentionedUsers.Count > 0 ? message.MentionedUsers.Count : message.MentionedUsersCount;
string content = $"{Program.cfgjson.Emoji.Banned} {message.Author.Mention} was automatically banned for mentioning **{mentionCount}** users.";
var chatMsg = await channel.SendMessageAsync(content);
_ = InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, "Mass mentions (Ban threshold)", DiscordHelpers.MessageLink(chatMsg), content: content, wasAutoModBlock: wasAutoModBlock);
_ = InvestigationsHelpers.SendInfringingMessaageAsync("mod", message, "Mass mentions (Ban threshold)", DiscordHelpers.MessageLink(chatMsg), content: content, wasAutoModBlock: wasAutoModBlock);
_ = InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, "Mass mentions (Ban threshold)", DiscordHelpers.MessageLink(chatMsg), content: content, messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);
_ = InvestigationsHelpers.SendInfringingMessaageAsync("mod", message, "Mass mentions (Ban threshold)", DiscordHelpers.MessageLink(chatMsg), content: content, messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);
return;
}

Expand All @@ -374,7 +375,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
string reason = listItem.Reason;
try
{
await InvestigationsHelpers.SendInfringingMessaageAsync("mod", message, reason, null, wasAutoModBlock: wasAutoModBlock);
await InvestigationsHelpers.SendInfringingMessaageAsync("mod", message, reason, null, messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);
}
catch
{
Expand All @@ -393,7 +394,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe

DiscordMessage msg = await WarningHelpers.SendPublicWarningMessageAndDeleteInfringingMessageAsync(message, $"{Program.cfgjson.Emoji.Denied} {message.Author.Mention} was automatically warned: **{reason.Replace("`", "\\`").Replace("*", "\\*")}**", wasAutoModBlock, 1);
var warning = await WarningHelpers.GiveWarningAsync(message.Author, client.CurrentUser, reason, contextMessage: msg, channel, " automatically ");
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, extraField: ("Match", flaggedWord, true), wasAutoModBlock: wasAutoModBlock);
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, extraField: ("Match", flaggedWord, true), messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);
return;
}
}
Expand Down Expand Up @@ -423,7 +424,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
string reason = "Sent an unapproved invite";
try
{
_ = InvestigationsHelpers.SendInfringingMessaageAsync("mod", message, reason, null, wasAutoModBlock: wasAutoModBlock);
_ = InvestigationsHelpers.SendInfringingMessaageAsync("mod", message, reason, null, messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);
}
catch
{
Expand All @@ -432,7 +433,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe

DiscordMessage msg = await WarningHelpers.SendPublicWarningMessageAndDeleteInfringingMessageAsync(message, $"{Program.cfgjson.Emoji.Denied} {message.Author.Mention} was automatically warned: **{reason.Replace("`", "\\`").Replace("*", "\\*")}**", wasAutoModBlock, 1);
var warning = await WarningHelpers.GiveWarningAsync(message.Author, client.CurrentUser, reason, contextMessage: msg, channel, " automatically ");
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, wasAutoModBlock: wasAutoModBlock);
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);
match = true;
return;
}
Expand All @@ -442,7 +443,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
if ((await GetPermLevelAsync(member)) < (ServerPermLevel)Program.cfgjson.InviteTierRequirement && inviteMatches.Count > 3)
{
string reason = "Sent too many invites";
await DeleteAndWarnAsync(message, reason, client, wasAutoModBlock);
await DeleteAndWarnAsync(message, reason, client, wasAutoModBlock, messageContentOverride: msgContentWithEmbedData);
match = true;
return;
}
Expand All @@ -469,7 +470,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
if (!match)
{
string reason = "Sent an unapproved invite";
await DeleteAndWarnAsync(message, reason, client, wasAutoModBlock);
await DeleteAndWarnAsync(message, reason, client, wasAutoModBlock, messageContentOverride: msgContentWithEmbedData);
match = true;
}
break;
Expand Down Expand Up @@ -502,7 +503,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
string responseToSend = $"```json\n{JsonConvert.SerializeObject(maliciousCache)}\n```";

(string name, string value, bool inline) extraField = new("Cached API response", responseToSend, false);
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, extraField, wasAutoModBlock: wasAutoModBlock);
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, extraField, messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);

match = true;
break;
Expand Down Expand Up @@ -530,7 +531,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
if (!match)
{
string reason = "Sent an unapproved invite";
await DeleteAndWarnAsync(message, reason, client, wasAutoModBlock);
await DeleteAndWarnAsync(message, reason, client, wasAutoModBlock, messageContentOverride: msgContentWithEmbedData);
}
return;
}
Expand Down Expand Up @@ -592,7 +593,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
pardonOutput = $"{Program.cfgjson.Emoji.Information} {message.Author.Mention} Your message was automatically deleted for mass emoji.";

var msgOut = await WarningHelpers.SendPublicWarningMessageAndDeleteInfringingMessageAsync(message, pardonOutput, wasAutoModBlock);
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, DiscordHelpers.MessageLink(msgOut), wasAutoModBlock: wasAutoModBlock);
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, DiscordHelpers.MessageLink(msgOut), messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);
return;
}

Expand All @@ -605,7 +606,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe

DiscordMessage msg = await WarningHelpers.SendPublicWarningMessageAndDeleteInfringingMessageAsync(message, output, wasAutoModBlock);
var warning = await WarningHelpers.GiveWarningAsync(message.Author, client.CurrentUser, reason, contextMessage: msg, channel, " automatically ");
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, wasAutoModBlock: wasAutoModBlock);
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);
return;
}

Expand Down Expand Up @@ -684,7 +685,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
string responseToSend = await StringHelpers.CodeOrHasteBinAsync(responseText, "json", 1000, true);

(string name, string value, bool inline) extraField = new("API Response", responseToSend, false);
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, extraField, wasAutoModBlock: wasAutoModBlock);
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, extraField, messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);
return;
}
}
Expand All @@ -708,7 +709,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
string reason = "Attempted to ping everyone/here";
DiscordMessage msg = await WarningHelpers.SendPublicWarningMessageAndDeleteInfringingMessageAsync(message, $"{Program.cfgjson.Emoji.Denied} {message.Author.Mention} was automatically warned: **{reason.Replace("`", "\\`").Replace("*", "\\*")}**", wasAutoModBlock);
var warning = await WarningHelpers.GiveWarningAsync(message.Author, client.CurrentUser, reason, contextMessage: msg, channel, " automatically ");
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, wasAutoModBlock: wasAutoModBlock);
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);
return;
}

Expand All @@ -727,7 +728,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
string reason = "Mass mentions";
try
{
_ = InvestigationsHelpers.SendInfringingMessaageAsync("mod", message, reason, null, wasAutoModBlock: wasAutoModBlock);
_ = InvestigationsHelpers.SendInfringingMessaageAsync("mod", message, reason, null, messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);
}
catch
{
Expand All @@ -736,7 +737,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe

DiscordMessage msg = await WarningHelpers.SendPublicWarningMessageAndDeleteInfringingMessageAsync(message, $"{Program.cfgjson.Emoji.Denied} {message.Author.Mention} was automatically warned: **{reason.Replace("`", "\\`").Replace("*", "\\*")}**", wasAutoModBlock);
var warning = await WarningHelpers.GiveWarningAsync(message.Author, client.CurrentUser, reason, contextMessage: msg, channel, " automatically ");
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, wasAutoModBlock: wasAutoModBlock);
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);
return;
}

Expand Down Expand Up @@ -783,7 +784,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
{
msg = await channel.SendMessageAsync(messageBuilder);
}
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, DiscordHelpers.MessageLink(msg), wasAutoModBlock: wasAutoModBlock);
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, DiscordHelpers.MessageLink(msg), messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);
return;
}
else
Expand All @@ -805,7 +806,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
}

var warning = await WarningHelpers.GiveWarningAsync(message.Author, client.CurrentUser, reason, contextMessage: msg, channel, " automatically ");
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, wasAutoModBlock: wasAutoModBlock);
await InvestigationsHelpers.SendInfringingMessaageAsync("investigations", message, reason, warning.ContextLink, messageContentOverride: msgContentWithEmbedData, wasAutoModBlock: wasAutoModBlock);

return;
}
Expand Down Expand Up @@ -892,6 +893,7 @@ await InvestigationsHelpers.SendInfringingMessaageAsync(
colour: new DiscordColor(0xFEC13D),
channelOverride: logChannel,
extraField: extraField,
messageContentOverride: msgContentWithEmbedData,
wasAutoModBlock: wasAutoModBlock
);
}
Expand Down
4 changes: 2 additions & 2 deletions Helpers/InvestigationsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ public static async Task SendInfringingMessaageAsync(string logChannelKey, Disco
{
await SendInfringingMessaageAsync(logChannelKey, new MockDiscordMessage(infringingMessage), reason, messageURL, extraField, content, colour, channelOverride);
}
public static async Task SendInfringingMessaageAsync(string logChannelKey, MockDiscordMessage infringingMessage, string reason, string messageURL, (string name, string value, bool inline) extraField = default, string content = default, DiscordColor? colour = null, DiscordChannel channelOverride = default, bool wasAutoModBlock = false)
public static async Task SendInfringingMessaageAsync(string logChannelKey, MockDiscordMessage infringingMessage, string reason, string messageURL, (string name, string value, bool inline) extraField = default, string content = default, DiscordColor? colour = null, DiscordChannel channelOverride = default, string messageContentOverride = default, bool wasAutoModBlock = false)
{
if (colour is null)
colour = new DiscordColor(0xf03916);

var embed = new DiscordEmbedBuilder()
.WithDescription(infringingMessage.Content)
.WithDescription(string.IsNullOrWhiteSpace(messageContentOverride) ? infringingMessage.Content : messageContentOverride)
.WithColor((DiscordColor)colour)
.WithTimestamp(infringingMessage.Timestamp)
.WithFooter(
Expand Down

0 comments on commit c4cafb6

Please sign in to comment.