mirror of
https://github.com/RPCS3/discord-bot.git
synced 2025-01-26 04:34:39 +00:00
update log parser to support new filter actions
This commit is contained in:
parent
b448986415
commit
dd0f85cdb6
@ -99,12 +99,18 @@ namespace CompatBot.Database.Providers
|
||||
if (string.IsNullOrEmpty(message.Content))
|
||||
return true;
|
||||
|
||||
var severity = ReportSeverity.Low;
|
||||
var completedActions = new List<FilterAction>();
|
||||
var trigger = await FindTriggerAsync(FilterContext.Chat, message.Content).ConfigureAwait(false);
|
||||
if (trigger == null)
|
||||
return true;
|
||||
|
||||
await PerformFilterActions(client, message, trigger).ConfigureAwait(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static async Task PerformFilterActions(DiscordClient client, DiscordMessage message, Piracystring trigger)
|
||||
{
|
||||
var severity = ReportSeverity.Low;
|
||||
var completedActions = new List<FilterAction>();
|
||||
if (trigger.Actions.HasFlag(FilterAction.RemoveContent))
|
||||
{
|
||||
try
|
||||
@ -165,7 +171,6 @@ namespace CompatBot.Database.Providers
|
||||
{
|
||||
Config.Log.Error(e, "Failed to report content removal");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -214,9 +214,17 @@ namespace CompatBot.EventHandlers.LogParsing
|
||||
if (await ContentFilter.FindTriggerAsync(FilterContext.Log, line).ConfigureAwait(false) is Piracystring match
|
||||
&& match.Actions.HasFlag(FilterAction.RemoveContent))
|
||||
{
|
||||
state.PiracyTrigger = match.String;
|
||||
state.PiracyContext = line.ToUtf8();
|
||||
state.Error = LogParseState.ErrorCode.PiracyDetected;
|
||||
if (state.FilterTriggers.TryGetValue(match.Id, out var fh))
|
||||
{
|
||||
if (fh.context.Length > line.Length)
|
||||
state.FilterTriggers[match.Id] = (match, line.ToUtf8());
|
||||
}
|
||||
else
|
||||
{
|
||||
state.FilterTriggers[match.Id] = (match, line.ToUtf8());
|
||||
if (match.Actions.HasFlag(FilterAction.IssueWarning))
|
||||
state.Error = LogParseState.ErrorCode.PiracyDetected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using CompatBot.Database;
|
||||
|
||||
namespace CompatBot.EventHandlers.LogParsing.POCOs
|
||||
{
|
||||
@ -8,17 +9,18 @@ namespace CompatBot.EventHandlers.LogParsing.POCOs
|
||||
{
|
||||
public NameValueCollection CompleteCollection = null;
|
||||
public NameValueCollection WipCollection = new NameValueCollection();
|
||||
public Dictionary<string, int> ValueHitStats = new Dictionary<string, int>();
|
||||
public readonly Dictionary<string, int> ValueHitStats = new Dictionary<string, int>();
|
||||
public int Id = 0;
|
||||
public ErrorCode Error = ErrorCode.None;
|
||||
public string PiracyTrigger;
|
||||
public string PiracyContext;
|
||||
public readonly Dictionary<int, (Piracystring filter, string context)> FilterTriggers = new Dictionary<int, (Piracystring filter, string context)>();
|
||||
public Piracystring SelectedFilter;
|
||||
public string SelectedFilterContext;
|
||||
public long ReadBytes;
|
||||
public long TotalBytes;
|
||||
public int LinesAfterConfig;
|
||||
public TimeSpan ParsingTime;
|
||||
#if DEBUG
|
||||
public Dictionary<string, int> ExtractorHitStats = new Dictionary<string, int>();
|
||||
public readonly Dictionary<string, int> ExtractorHitStats = new Dictionary<string, int>();
|
||||
#endif
|
||||
|
||||
public enum ErrorCode
|
||||
|
@ -8,6 +8,8 @@ using System.Threading.Tasks;
|
||||
using CompatApiClient.Utils;
|
||||
using CompatBot.Commands;
|
||||
using CompatBot.Commands.Attributes;
|
||||
using CompatBot.Database;
|
||||
using CompatBot.Database.Providers;
|
||||
using CompatBot.EventHandlers.LogParsing;
|
||||
using CompatBot.EventHandlers.LogParsing.POCOs;
|
||||
using CompatBot.EventHandlers.LogParsing.ArchiveHandlers;
|
||||
@ -110,6 +112,17 @@ namespace CompatBot.EventHandlers
|
||||
await fillPipeTask.ConfigureAwait(false);
|
||||
result.TotalBytes = source.LogFileSize;
|
||||
result.ParsingTime = startTime.Elapsed;
|
||||
|
||||
if (result.FilterTriggers.Any())
|
||||
{
|
||||
var (f, c) = result.FilterTriggers.Values.FirstOrDefault(ft => ft.filter.Actions.HasFlag(FilterAction.IssueWarning));
|
||||
if (f == null)
|
||||
(f, c) = result.FilterTriggers.Values.FirstOrDefault(ft => ft.filter.Actions.HasFlag(FilterAction.RemoveContent));
|
||||
if (f == null)
|
||||
(f, c) = result.FilterTriggers.Values.FirstOrDefault();
|
||||
result.SelectedFilter = f;
|
||||
result.SelectedFilterContext = c;
|
||||
}
|
||||
#if DEBUG
|
||||
Config.Log.Debug("~~~~~~~~~~~~~~~~~~~~");
|
||||
Config.Log.Debug("Extractor hit stats:");
|
||||
@ -157,7 +170,7 @@ namespace CompatBot.EventHandlers
|
||||
var piracyWarning = await result.AsEmbedAsync(client, message, source).ConfigureAwait(false);
|
||||
piracyWarning = piracyWarning.WithDescription("Please remove the log and issue warning to the original author of the log");
|
||||
botMsg = await botMsg.UpdateOrCreateMessageAsync(channel, embed: piracyWarning).ConfigureAwait(false);
|
||||
await client.ReportAsync(yarr + " Pirated Release (whitelisted by role)", message, result.PiracyTrigger, result.PiracyContext, ReportSeverity.Low).ConfigureAwait(false);
|
||||
await client.ReportAsync(yarr + " Pirated Release (whitelisted by role)", message, result.SelectedFilter?.String, result.SelectedFilterContext, ReportSeverity.Low).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -184,21 +197,25 @@ namespace CompatBot.EventHandlers
|
||||
}
|
||||
try
|
||||
{
|
||||
await client.ReportAsync(yarr + " Pirated Release", message, result.PiracyTrigger, result.PiracyContext, severity).ConfigureAwait(false);
|
||||
await client.ReportAsync(yarr + " Pirated Release", message, result.SelectedFilter?.String, result.SelectedFilterContext, severity).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Config.Log.Error(e, "Failed to send piracy report");
|
||||
}
|
||||
if (!(message.Channel.IsPrivate || (message.Channel.Name?.Contains("spam") ?? true)))
|
||||
await Warnings.AddAsync(client, message, message.Author.Id, message.Author.Username, client.CurrentUser, "Pirated Release", $"{result.PiracyTrigger} - {result.PiracyContext.Sanitize()}");
|
||||
await Warnings.AddAsync(client, message, message.Author.Id, message.Author.Username, client.CurrentUser, "Pirated Release", $"{result.SelectedFilter?.String} - {result.SelectedFilterContext?.Sanitize()}");
|
||||
}
|
||||
}
|
||||
else
|
||||
botMsg = await botMsg.UpdateOrCreateMessageAsync(channel,
|
||||
requester == null ? null : $"Analyzed log from {client.GetMember(channel.Guild, message.Author)?.GetUsernameWithNickname()} by request from {requester.Mention}:",
|
||||
embed: await result.AsEmbedAsync(client, message, source).ConfigureAwait(false)
|
||||
).ConfigureAwait(false);
|
||||
{
|
||||
await ContentFilter.PerformFilterActions(client, message, result.SelectedFilter).ConfigureAwait(false);
|
||||
if (result.SelectedFilter == null || !result.SelectedFilter.Actions.HasFlag(FilterAction.RemoveContent))
|
||||
botMsg = await botMsg.UpdateOrCreateMessageAsync(channel,
|
||||
requester == null ? null : $"Analyzed log from {client.GetMember(channel.Guild, message.Author)?.GetUsernameWithNickname()} by request from {requester.Mention}:",
|
||||
embed: await result.AsEmbedAsync(client, message, source).ConfigureAwait(false)
|
||||
).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -143,7 +143,6 @@ namespace CompatBot.Utils.ResultFormatters
|
||||
collection["embed_title"] = builder.Title ?? "";
|
||||
if (state.Error == LogParseState.ErrorCode.PiracyDetected)
|
||||
{
|
||||
state.PiracyContext = state.PiracyContext.Sanitize();
|
||||
var msg = "__You are being denied further support until you legally dump the game__.\n" +
|
||||
"Please note that the RPCS3 community and its developers do not support piracy.\n" +
|
||||
"Most of the issues with pirated dumps occur due to them having been tampered with in some way " +
|
||||
|
Loading…
x
Reference in New Issue
Block a user