Skip to content

Commit

Permalink
🐟 Use regex to match 233+
Browse files Browse the repository at this point in the history
  • Loading branch information
database64128 committed Mar 20, 2024
1 parent 0e366e1 commit b47e661
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions CubicBot.Telegram/Stats/TwoTripleThree.cs
Original file line number Diff line number Diff line change
@@ -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();

/// <summary>
/// Checks whether the message starts with or ends with "233".
/// Checks whether the message starts with or ends with the pattern "233+".
/// </summary>
/// <param name="msg">The text message to check.</param>
/// <returns>
/// True if the message starts with or ends with "233".
/// True if the message starts with or ends with the pattern "233+".
/// Otherwise, false.
/// </returns>
private static bool ContainsTwoDoubleThree(ReadOnlySpan<char> 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)
{
Expand Down

0 comments on commit b47e661

Please sign in to comment.