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); }
public async Task Add(CommandContext ctx, [RemainingText, Description("A plain string to match")] string trigger) { var wasSuccessful = await PiracyStringProvider.AddAsync(trigger).ConfigureAwait(false); if (wasSuccessful) { await ctx.ReactWithAsync(Config.Reactions.Success, "New trigger successfully saved!").ConfigureAwait(false); } else { await ctx.ReactWithAsync(Config.Reactions.Failure, "Trigger already defined.").ConfigureAwait(false); } if (wasSuccessful) { await List(ctx).ConfigureAwait(false); } }
public async Task Remove(CommandContext ctx, [Description("Filter IDs to remove, separated with spaces")] params int[] ids) { var failedIds = new List <int>(); foreach (var id in ids) { if (!await PiracyStringProvider.RemoveAsync(id).ConfigureAwait(false)) { failedIds.Add(id); } } if (failedIds.Count > 0) { await ctx.RespondAsync("Some ids couldn't be removed: " + string.Join(", ", failedIds)).ConfigureAwait(false); } else { await ctx.ReactWithAsync(Config.Reactions.Success, $"Trigger{StringUtils.GetSuffix(ids.Length)} successfully removed!").ConfigureAwait(false); } await List(ctx).ConfigureAwait(false); }