From b47e661d4fcb51fe2cdaa0d31e092c48026e1771 Mon Sep 17 00:00:00 2001 From: database64128 Date: Wed, 20 Mar 2024 23:19:36 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9F=20Use=20regex=20to=20match=20233+?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CubicBot.Telegram/Stats/TwoTripleThree.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CubicBot.Telegram/Stats/TwoTripleThree.cs b/CubicBot.Telegram/Stats/TwoTripleThree.cs index a218a34..56f405f 100644 --- a/CubicBot.Telegram/Stats/TwoTripleThree.cs +++ b/CubicBot.Telegram/Stats/TwoTripleThree.cs @@ -1,25 +1,25 @@ using CubicBot.Telegram.Utils; -using System; using System.Numerics; +using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; namespace CubicBot.Telegram.Stats; -public sealed class TwoTripleThree : IStatsCollector +public sealed partial class TwoTripleThree : IStatsCollector { - private const string TwoDoubleThree = "233"; + [GeneratedRegex("^233+|233+$")] + private static partial Regex LeadingAndTrailingTwoDoubleThreeRegex(); /// - /// Checks whether the message starts with or ends with "233". + /// Checks whether the message starts with or ends with the pattern "233+". /// /// The text message to check. /// - /// True if the message starts with or ends with "233". + /// True if the message starts with or ends with the pattern "233+". /// Otherwise, false. /// - private static bool ContainsTwoDoubleThree(ReadOnlySpan msg) => msg.Length >= TwoDoubleThree.Length && - (msg[..TwoDoubleThree.Length] == TwoDoubleThree || msg[(msg.Length - TwoDoubleThree.Length)..] == TwoDoubleThree); + private static bool ContainsTwoDoubleThree(string msg) => LeadingAndTrailingTwoDoubleThreeRegex().IsMatch(msg); public Task CollectAsync(MessageContext messageContext, CancellationToken cancellationToken = default) {