Skip to content

Commit a952319

Browse files
committed
Merge branch 'vnext'
2 parents 5f02120 + 7121368 commit a952319

File tree

2 files changed

+1
-23
lines changed

2 files changed

+1
-23
lines changed

CompatBot/Database/Providers/ContentFilter.cs

+1-19
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,14 @@ internal static class ContentFilter
2121
public static ValueTask<Piracystring?> FindTriggerAsync(FilterContext ctx, string str)
2222
{
2323
if (str is not {Length: >0})
24-
{
25-
Config.Log.Debug($"[{nameof(ContentFilter)}.{nameof(FindTriggerAsync)}] No content, skipping");
2624
return ValueTask.FromResult((Piracystring?)null);
27-
}
2825

2926
if (!filters.TryGetValue(ctx, out var matcher))
30-
{
31-
Config.Log.Debug($"[{nameof(ContentFilter)}.{nameof(FindTriggerAsync)}] No matcher, skipping");
3227
return ValueTask.FromResult((Piracystring?)null);
33-
}
3428

3529
Piracystring? result = null;
3630
matcher?.ParseText(str, h =>
3731
{
38-
Config.Log.Debug($"[{nameof(ContentFilter)}.{nameof(FindTriggerAsync)}] Hit trigger `{str[h.Begin .. h.End]}`, validating using `{h.Value.ValidatingRegex}`");
3932
if (string.IsNullOrEmpty(h.Value.ValidatingRegex) || Regex.IsMatch(str, h.Value.ValidatingRegex, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.ExplicitCapture))
4033
{
4134
result = h.Value;
@@ -45,13 +38,11 @@ internal static class ContentFilter
4538
return true;
4639
});
4740

48-
Config.Log.Debug($"[{nameof(ContentFilter)}.{nameof(FindTriggerAsync)}] No result, trying on clean content…");
4941
if (result is null && ctx == FilterContext.Chat)
5042
{
5143
str = str.StripInvisibleAndDiacritics();
5244
matcher?.ParseText(str, h =>
5345
{
54-
Config.Log.Debug($"[{nameof(ContentFilter)}.{nameof(FindTriggerAsync)}] Hit trigger `{str[h.Begin .. h.End]}`, validating using `{h.Value.ValidatingRegex}`");
5546
if (string.IsNullOrEmpty(h.Value.ValidatingRegex) || Regex.IsMatch(str, h.Value.ValidatingRegex, RegexOptions.IgnoreCase | RegexOptions.Multiline))
5647
{
5748
result = h.Value;
@@ -137,37 +128,28 @@ public static async ValueTask<bool> IsClean(DiscordClient client, DiscordMessage
137128
#endif
138129

139130
var content = new StringBuilder();
140-
Config.Log.Debug($"[{nameof(ContentFilter)}.{nameof(IsClean)}] Message length: {message.Content.Length}");
141131
DumpMessageContent(message, content);
142-
Config.Log.Debug($"[{nameof(ContentFilter)}.{nameof(IsClean)}] Dumped content length: {content.Length}");
143132
if (message.Reference is {Type: DiscordMessageReferenceType.Forward} refMsg)
144133
{
145134
try
146135
{
147-
Config.Log.Debug($"[{nameof(ContentFilter)}.{nameof(IsClean)}] Message has a forwarded message, getting it…");
148136
var msg = await client.GetMessageAsync(refMsg.Channel, refMsg.Message.Id).ConfigureAwait(false);
149137
if (msg is not null)
150138
{
151-
Config.Log.Debug($"[{nameof(ContentFilter)}.{nameof(IsClean)}] Forwarded message length: {msg.Content.Length}");
152139
content.AppendLine();
153140
DumpMessageContent(msg, content);
154-
Config.Log.Debug($"[{nameof(ContentFilter)}.{nameof(IsClean)}] Dumped content length: {content.Length}");
155141
}
156142
}
157143
catch (Exception e)
158144
{
159-
Config.Log.Warn(e, "Failed to get message reference content");
145+
Config.Log.Warn(e, "Failed to get forwarded message");
160146
}
161147
}
162148

163149
var trigger = await FindTriggerAsync(FilterContext.Chat, content.ToString()).ConfigureAwait(false);
164150
if (trigger is null)
165-
{
166-
Config.Log.Debug($"[{nameof(ContentFilter)}.{nameof(IsClean)}] Nothing found");
167151
return true;
168-
}
169152

170-
Config.Log.Debug($"[{nameof(ContentFilter)}.{nameof(IsClean)}] Cleaning…");
171153
await PerformFilterActions(client, message, trigger, suppressActions).ConfigureAwait(false);
172154
return (trigger.Actions & ~suppressActions & (FilterAction.IssueWarning | FilterAction.RemoveContent)) == 0;
173155
}

CompatBot/EventHandlers/ContentFilterMonitor.cs

-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@ public static async Task OnReaction(DiscordClient c, MessageReactionAddedEventAr
2020
var message = e.Message;
2121
if (message.Author is null)
2222
{
23-
Config.Log.Debug($"[{nameof(ContentFilterMonitor)}] Author is null, getting from full message cache…");
2423
message = await e.Channel.GetMessageCachedAsync(e.Message.Id).ConfigureAwait(false);
2524
if (message?.Author is null)
26-
{
27-
Config.Log.Debug($"[{nameof(ContentFilterMonitor)}] Cached message author is null, getting from full message…");
2825
message = await e.Channel.GetMessageAsync(e.Message.Id).ConfigureAwait(false);
29-
}
3026
}
3127
await ContentFilter.IsClean(c, message).ConfigureAwait(false);
3228
}

0 commit comments

Comments
 (0)