use role whitelist for piracy checks

This commit is contained in:
13xforever 2018-07-25 15:28:34 +05:00 committed by Roberto Anić Banić
parent 2bf9221a53
commit 89f58e2201
4 changed files with 29 additions and 5 deletions

View File

@ -30,6 +30,9 @@ namespace CompatBot.EventHandlers
if (string.IsNullOrEmpty(message.Content) || message.Content.StartsWith(Config.CommandPrefix))
return true;
if ((message.Author as DiscordMember)?.Roles.IsWhitelisted() ?? false)
return true;
string trigger = null;
bool needsAttention = false;
try

View File

@ -1,7 +1,7 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CompatBot.Utils;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
@ -9,7 +9,7 @@ namespace CompatBot.EventHandlers
{
internal class LogsAsTextMonitor
{
private static readonly Regex LogLine = new Regex(@"^·|^\w {(rsx|PPU|SPU)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline);
private static readonly Regex LogLine = new Regex(@"^·|^(\w|!) ({(rsx|PPU|SPU)|LDR:)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline);
public static async Task OnMessageCreated(MessageCreateEventArgs args)
{
@ -22,11 +22,17 @@ namespace CompatBot.EventHandlers
if (!"help".Equals(args.Channel.Name, StringComparison.InvariantCultureIgnoreCase))
return;
if ((args.Message.Author as DiscordMember)?.Roles?.Any() ?? false)
if ((args.Message.Author as DiscordMember)?.Roles.IsWhitelisted() ?? false)
return;
if (LogLine.IsMatch(args.Message.Content))
{
if (args.Message.Content.Contains("LDR:") && args.Message.Content.Contains("fs::file is null"))
await args.Channel.SendMessageAsync($"{args.Message.Author.Mention} this error usually indicates a missing `.rap` license file.{Environment.NewLine}" +
"Please follow the quickstart guide to get a proper dump of a digital title.").ConfigureAwait(false);
else
await args.Channel.SendMessageAsync($"{args.Message.Author.Mention} please upload the full log file instead of pasting some random bits that might be completely irrelevant").ConfigureAwait(false);
}
}
}
}

View File

@ -80,7 +80,7 @@ namespace CompatBot.EventHandlers
// in case it's not in cache and doesn't contain any info, including Author
message = await channel.GetMessageAsync(message.Id).ConfigureAwait(false);
if ((message.Author as DiscordMember)?.Roles.Any(r => Config.Moderation.RoleWhiteList.Contains(r.Name)) ?? false)
if ((message.Author as DiscordMember)?.Roles.IsWhitelisted() ?? false)
return;
var users = await message.GetReactionsAsync(emoji).ConfigureAwait(false);

View File

@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using DSharpPlus.Entities;
namespace CompatBot.Utils
{
internal static class RolesExtensions
{
public static bool IsWhitelisted(this IEnumerable<DiscordRole> memberRoles)
{
return memberRoles?.Any(r => Config.Moderation.RoleWhiteList.Contains(r.Name)) ?? false;
}
}
}