<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CompatApiClient.Compression;
using CompatBot.Commands;
using CompatBot.Database.Providers;
using CompatBot.Utils;
using CompatBot.Utils.Extensions;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using Microsoft.Extensions.Caching.Memory;

namespace CompatBot.EventHandlers;

internal static class DiscordInviteFilter
{
    private const RegexOptions DefaultOptions = RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.Multiline;
    private static readonly Regex InviteLink = new(@"(https?://)?discord(((app\.com/invite|\.gg)/(?<invite_id>[a-z0-9\-]+))|(\.me/(?<me_id>.*?))(\s|>|$))", DefaultOptions);
    private static readonly MemoryCache InviteCodeCache = new(new MemoryCacheOptions{ExpirationScanFrequency = TimeSpan.FromHours(1)});
    private static readonly TimeSpan CacheDuration = TimeSpan.FromHours(24);

    public static async Task OnMessageCreated(DiscordClient c, MessageCreateEventArgs args)
    {
        args.Handled = !await CheckMessageForInvitesAsync(c, args.Message).ConfigureAwait(false);
    }

    public static async Task OnMessageUpdated(DiscordClient c, MessageUpdateEventArgs args)
    {
        args.Handled = !await CheckMessageForInvitesAsync(c, args.Message).ConfigureAwait(false);
    }<commit_msg>Fix #842<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CompatApiClient.Compression;
using CompatBot.Commands;
using CompatBot.Database.Providers;
using CompatBot.Utils;
using CompatBot.Utils.Extensions;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using Microsoft.Extensions.Caching.Memory;

namespace CompatBot.EventHandlers;

internal static class DiscordInviteFilter
{
    private const RegexOptions DefaultOptions = RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.Multiline;
    private static readonly Regex InviteLink = new(@"(https?://)?discord((((app)?\.com/invite|\.gg)/(?<invite_id>[a-z0-9\-]+))|(\.me/(?<me_id>.*?))(\s|>|$))", DefaultOptions);
    private static readonly MemoryCache InviteCodeCache = new(new MemoryCacheOptions{ExpirationScanFrequency = TimeSpan.FromHours(1)});
    private static readonly TimeSpan CacheDuration = TimeSpan.FromHours(24);

    public static async Task OnMessageCreated(DiscordClient c, MessageCreateEventArgs args)
    {
        args.Handled = !await CheckMessageForInvitesAsync(c, args.Message).ConfigureAwait(false);
    }

    public static async Task OnMessageUpdated(DiscordClient c, MessageUpdateEventArgs args)
    {
        args.Handled = !await CheckMessageForInvitesAsync(c, args.Message).ConfigureAwait(false);
    }
{'fraction_non_alphanumeric': 0.10987573577501634, 'fraction_numerical': 0.004251144538914323, 'mean_word_length': 5.858744394618834, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2794', 'n_tokens_mistral': 923, 'n_tokens_neox': 901, 'n_words': 187}