private static async Task PiracyCheckAsync(string line, LogParseState state)
 {
     if (await PiracyStringProvider.FindTriggerAsync(line).ConfigureAwait(false) is string match)
     {
         state.PiracyTrigger = match;
         state.PiracyContext = line.ToUtf8();
         state.Error         = LogParseState.ErrorCode.PiracyDetected;
     }
 }
        public static async Task <bool> IsClean(DiscordClient client, DiscordMessage message)
        {
            if (message.Channel.IsPrivate)
            {
                return(true);
            }

            if (message.Author.IsBot)
            {
                return(true);
            }

            if (message.Author.IsWhitelisted(client, message.Channel.Guild))
            {
                return(true);
            }

            if (string.IsNullOrEmpty(message.Content))
            {
                return(true);
            }

            string trigger  = null;
            var    severity = ReportSeverity.Low;

            try
            {
                trigger = await PiracyStringProvider.FindTriggerAsync(message.Content);

                if (trigger == null)
                {
                    return(true);
                }

                await message.Channel.DeleteMessageAsync(message, $"Mention of piracy trigger '{trigger}'").ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Config.Log.Warn(e, $"Couldn't delete message in {message.Channel.Name}");
                severity = ReportSeverity.High;
            }
            try
            {
                var rules = await client.GetChannelAsync(Config.BotRulesChannelId).ConfigureAwait(false);

                await Task.WhenAll(
                    message.Channel.SendMessageAsync($"{message.Author.Mention} Please follow the {rules.Mention} and do not discuss piracy on this server. Repeated offence may result in a ban."),
                    client.ReportAsync("Mention of piracy", message, trigger, message.Content, severity),
                    Warnings.AddAsync(client, message, message.Author.Id, message.Author.Username, client.CurrentUser, "Mention of piracy", message.Content.Sanitize())
                    ).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Config.Log.Warn(e, $"Couldn't finish piracy trigger actions for a message in {message.Channel.Name}");
            }
            return(false);
        }