Exemplo n.º 1
0
        protected virtual void HandleNewCommand(CommandMatch cmd, IChannelMessageEventArgs message)
        {
            if (!EnsureOp(message))
            {
                return;
            }

            var    criterionName        = (string)cmd.Arguments[0];
            string detectionRegexString = ((string)cmd.Arguments[1]).Trim();

            try
            {
                RegexCache.GetOrAdd(detectionRegexString);
            }
            catch (ArgumentException)
            {
                ConnectionManager.SendChannelMessage(message.Channel, $"{message.SenderNickname}: Invalid regular expression.");
                return;
            }

            using (var ctx = GetNewContext())
            {
                // see if a criterion already matches
                Criterion crit = ctx.Criteria
                                 .FirstOrDefault(c => c.Name == criterionName && c.Channel == message.Channel);
                if (crit == null)
                {
                    // create a new criterion
                    crit = new Criterion
                    {
                        Name           = criterionName,
                        Channel        = message.Channel,
                        DetectionRegex = detectionRegexString,
                        Enabled        = true
                    };
                }
                else if (crit.Enabled)
                {
                    ConnectionManager.SendChannelMessage(
                        message.Channel,
                        $"{message.SenderNickname}: That criterion name is already in use."
                        );
                    return;
                }
                else
                {
                    // modify the existing criterion and re-enable it
                    crit.DetectionRegex = detectionRegexString;
                    crit.Enabled        = true;
                }
                ctx.SaveChanges();

                // update the cache
                Dictionary <string, long> commandsIDs = ObtainCommandCacheForChannel(message.Channel);
                commandsIDs[crit.Name] = crit.ID;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Searches an input span for all occurrences of a regular expression and returns a <see cref="ValueMatchEnumerator"/> to iterate over the matches.
 /// </summary>
 /// <remarks>
 /// Each match won't actually happen until <see cref="ValueMatchEnumerator.MoveNext"/> is invoked on the enumerator, with one match being performed per <see cref="ValueMatchEnumerator.MoveNext"/> call.
 /// Since the evaluation of the match happens lazily, any changes to the passed in input in between calls to <see cref="ValueMatchEnumerator.MoveNext"/> will affect the match results.
 /// The enumerator returned by this method, as well as the structs returned by the enumerator that wrap each match found in the input are ref structs which
 /// make this method be amortized allocation free.
 /// </remarks>
 /// <param name="input">The span to search for a match.</param>
 /// <param name="pattern">The regular expression pattern to match.</param>
 /// <param name="options">A bitwise combination of the enumeration values that specify options for matching.</param>
 /// <returns>A <see cref="ValueMatchEnumerator"/> to iterate over the matches.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="pattern"/> is null.</exception>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="options"/> is not a valid bitwise combination of RegexOptions values.</exception>
 /// <exception cref="RegexParseException">A regular expression parsing error occurred.</exception>
 public static ValueMatchEnumerator EnumerateMatches(ReadOnlySpan <char> input, [StringSyntax(StringSyntaxAttribute.Regex, nameof(options))] string pattern, RegexOptions options) =>
 RegexCache.GetOrAdd(pattern, options, s_defaultMatchTimeout).EnumerateMatches(input);
Exemplo n.º 3
0
 /// <summary>
 /// Searches the input string for one or more occurrences of the text
 /// supplied in the pattern parameter.
 /// </summary>
 public static Match Match(string input, [StringSyntax(StringSyntaxAttribute.Regex)] string pattern) =>
 RegexCache.GetOrAdd(pattern).Match(input);
Exemplo n.º 4
0
 public static string[] Split(string input, [StringSyntax(StringSyntaxAttribute.Regex, nameof(options))] string pattern, RegexOptions options, TimeSpan matchTimeout) =>
 RegexCache.GetOrAdd(pattern, options, matchTimeout).Split(input);
Exemplo n.º 5
0
 public static string Replace(string input, string pattern, MatchEvaluator evaluator, RegexOptions options, TimeSpan matchTimeout) =>
 RegexCache.GetOrAdd(pattern, options, matchTimeout).Replace(input, evaluator);
Exemplo n.º 6
0
 public static string Replace(string input, string pattern, string replacement, RegexOptions options, TimeSpan matchTimeout) =>
 RegexCache.GetOrAdd(pattern, options, matchTimeout).Replace(input, replacement);
Exemplo n.º 7
0
 public static string Replace(string input, [StringSyntax(StringSyntaxAttribute.Regex, nameof(options))] string pattern, MatchEvaluator evaluator, RegexOptions options, TimeSpan matchTimeout) =>
 RegexCache.GetOrAdd(pattern, options, matchTimeout).Replace(input, evaluator);
Exemplo n.º 8
0
 public static string Replace(string input, [StringSyntax(StringSyntaxAttribute.Regex, nameof(options))] string pattern, string replacement, RegexOptions options, TimeSpan matchTimeout) =>
 RegexCache.GetOrAdd(pattern, options, matchTimeout).Replace(input, replacement);
 public static bool IsMatch(string input, string pattern, RegexOptions options, TimeSpan matchTimeout) =>
 RegexCache.GetOrAdd(pattern, options, matchTimeout).IsMatch(input);
 /// <summary>
 /// Searches the input string for one or more occurrences of the text
 /// supplied in the pattern parameter with matching options supplied in the options
 /// parameter.
 /// </summary>
 public static bool IsMatch(string input, string pattern, RegexOptions options) =>
 RegexCache.GetOrAdd(pattern, options, s_defaultMatchTimeout).IsMatch(input);
 public static MatchCollection Matches(string input, string pattern, RegexOptions options, TimeSpan matchTimeout) =>
 RegexCache.GetOrAdd(pattern, options, matchTimeout).Matches(input);
 /// <summary>
 /// Returns all the successful matches as if Match were called iteratively numerous times.
 /// </summary>
 public static MatchCollection Matches(string input, string pattern) =>
 RegexCache.GetOrAdd(pattern).Matches(input);
Exemplo n.º 13
0
 /// <summary>
 /// Replaces all occurrences of the <paramref name="pattern"/> with the recent
 /// replacement pattern, starting at the first character.
 /// </summary>
 public static string Replace(string input, [StringSyntax(StringSyntaxAttribute.Regex, "options")] string pattern, MatchEvaluator evaluator, RegexOptions options) =>
 RegexCache.GetOrAdd(pattern, options, s_defaultMatchTimeout).Replace(input, evaluator);
Exemplo n.º 14
0
 /// <summary>
 /// Replaces all occurrences of
 /// the <paramref name="pattern "/>with the <paramref name="replacement "/>
 /// pattern, starting at the first character in the input string.
 /// </summary>
 public static string Replace(string input, [StringSyntax(StringSyntaxAttribute.Regex, "options")] string pattern, string replacement, RegexOptions options) =>
 RegexCache.GetOrAdd(pattern, options, s_defaultMatchTimeout).Replace(input, replacement);
Exemplo n.º 15
0
 /// <summary>
 /// Indicates whether the specified regular expression finds a match in the specified input span.
 /// </summary>
 /// <param name="input">The span to search for a match.</param>
 /// <param name="pattern">The regular expression pattern to match.</param>
 /// <returns><see langword="true"/> if the regular expression finds a match; otherwise, <see langword="false"/>.</returns>
 /// <exception cref="ArgumentException">A regular expression parsing error occurred.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="pattern"/> is <see langword="null"/></exception>
 /// <exception cref="RegexMatchTimeoutException">A time-out occurred.</exception>
 public static bool IsMatch(ReadOnlySpan <char> input, [StringSyntax(StringSyntaxAttribute.Regex)] string pattern) =>
 RegexCache.GetOrAdd(pattern).IsMatch(input);
 public static string[] Split(string input, string pattern, RegexOptions options, TimeSpan matchTimeout) =>
 RegexCache.GetOrAdd(pattern, options, matchTimeout).Split(input);
Exemplo n.º 17
0
 /// <summary>
 /// Replaces all occurrences of the pattern with the <paramref name="replacement"/> pattern, starting at
 /// the first character in the input string.
 /// </summary>
 public static string Replace(string input, [StringSyntax(StringSyntaxAttribute.Regex)] string pattern, string replacement) =>
 RegexCache.GetOrAdd(pattern).Replace(input, replacement);
 /// <summary>
 /// Searches the input string for one or more occurrences of the text
 /// supplied in the pattern parameter.
 /// </summary>
 public static Match Match(string input, string pattern) =>
 RegexCache.GetOrAdd(pattern).Match(input);
Exemplo n.º 19
0
 /// <summary>
 /// Replaces all occurrences of the <paramref name="pattern"/> with the recent
 /// replacement pattern.
 /// </summary>
 public static string Replace(string input, [StringSyntax(StringSyntaxAttribute.Regex)] string pattern, MatchEvaluator evaluator) =>
 RegexCache.GetOrAdd(pattern).Replace(input, evaluator);
Exemplo n.º 20
0
 /// <summary>
 /// Searches an input span for all occurrences of a regular expression and returns a <see cref="ValueMatchEnumerator"/> to iterate over the matches.
 /// </summary>
 /// <remarks>
 /// Each match won't actually happen until <see cref="ValueMatchEnumerator.MoveNext"/> is invoked on the enumerator, with one match being performed per <see cref="ValueMatchEnumerator.MoveNext"/> call.
 /// Since the evaluation of the match happens lazily, any changes to the passed in input in between calls to <see cref="ValueMatchEnumerator.MoveNext"/> will affect the match results.
 /// The enumerator returned by this method, as well as the structs returned by the enumerator that wrap each match found in the input are ref structs which
 /// make this method be amortized allocation free.
 /// </remarks>
 /// <param name="input">The span to search for a match.</param>
 /// <param name="pattern">The regular expression pattern to match.</param>
 /// <returns>A <see cref="ValueMatchEnumerator"/> to iterate over the matches.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="pattern"/> is null.</exception>
 /// <exception cref="RegexParseException">A regular expression parsing error occurred.</exception>
 public static ValueMatchEnumerator EnumerateMatches(ReadOnlySpan <char> input, [StringSyntax(StringSyntaxAttribute.Regex)] string pattern) =>
 RegexCache.GetOrAdd(pattern).EnumerateMatches(input);
Exemplo n.º 21
0
 /// <summary>
 /// Replaces all occurrences of the pattern with the <paramref name="replacement"/> pattern, starting at
 /// the first character in the input string.
 /// </summary>
 public static string Replace(string input, string pattern, string replacement) =>
 RegexCache.GetOrAdd(pattern).Replace(input, replacement);
Exemplo n.º 22
0
 /// <summary>
 /// Searches an input span for all occurrences of a regular expression and returns a <see cref="ValueMatchEnumerator"/> to iterate over the matches.
 /// </summary>
 /// <remarks>
 /// Each match won't actually happen until <see cref="ValueMatchEnumerator.MoveNext"/> is invoked on the enumerator, with one match being performed per <see cref="ValueMatchEnumerator.MoveNext"/> call.
 /// Since the evaluation of the match happens lazily, any changes to the passed in input in between calls to <see cref="ValueMatchEnumerator.MoveNext"/> will affect the match results.
 /// The enumerator returned by this method, as well as the structs returned by the enumerator that wrap each match found in the input are ref structs which
 /// make this method be amortized allocation free.
 /// </remarks>
 /// <param name="input">The span to search for a match.</param>
 /// <param name="pattern">The regular expression pattern to match.</param>
 /// <param name="options">A bitwise combination of the enumeration values that specify options for matching.</param>
 /// <param name="matchTimeout">A time-out interval, or <see cref="InfiniteMatchTimeout"/> to indicate that the method should not time out.</param>
 /// <returns>A <see cref="ValueMatchEnumerator"/> to iterate over the matches.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="pattern"/> is null.</exception>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="options"/> is not a valid bitwise combination of RegexOptions values, or <paramref name="matchTimeout"/> is negative, zero, or greater than approximately 24 days.</exception>
 /// <exception cref="RegexParseException">A regular expression parsing error occurred.</exception>
 public static ValueMatchEnumerator EnumerateMatches(ReadOnlySpan <char> input, [StringSyntax(StringSyntaxAttribute.Regex, "options")] string pattern, RegexOptions options, TimeSpan matchTimeout) =>
 RegexCache.GetOrAdd(pattern, options, matchTimeout).EnumerateMatches(input);
Exemplo n.º 23
0
 /// <summary>
 /// Replaces all occurrences of the <paramref name="pattern"/> with the recent
 /// replacement pattern.
 /// </summary>
 public static string Replace(string input, string pattern, MatchEvaluator evaluator) =>
 RegexCache.GetOrAdd(pattern).Replace(input, evaluator);
Exemplo n.º 24
0
 /// <summary>
 /// Searches an input span for all occurrences of a regular expression and returns the number of matches.
 /// </summary>
 /// <param name="input">The span to search for a match.</param>
 /// <param name="pattern">The regular expression pattern to match.</param>
 /// <param name="options">A bitwise combination of the enumeration values that specify options for matching.</param>
 /// <param name="matchTimeout">A time-out interval, or <see cref="InfiniteMatchTimeout"/> to indicate that the method should not time out.</param>
 /// <returns>The number of matches.</returns>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="options"/> is not a valid bitwise combination of RegexOptions values, or <paramref name="matchTimeout"/> is negative, zero, or greater than approximately 24 days.</exception>
 /// <exception cref="RegexParseException">A regular expression parsing error occurred.</exception>
 public static int Count(ReadOnlySpan <char> input, [StringSyntax(StringSyntaxAttribute.Regex, "options")] string pattern, RegexOptions options, TimeSpan matchTimeout) =>
 RegexCache.GetOrAdd(pattern, options, matchTimeout).Count(input);
Exemplo n.º 25
0
 /// <summary>
 /// Splits the <paramref name="input "/>string at the position defined
 /// by <paramref name="pattern"/>.
 /// </summary>
 public static string[] Split(string input, [StringSyntax(StringSyntaxAttribute.Regex)] string pattern) =>
 RegexCache.GetOrAdd(pattern).Split(input);
Exemplo n.º 26
0
 /// <summary>
 /// Searches an input span for all occurrences of a regular expression and returns the number of matches.
 /// </summary>
 /// <param name="input">The span to search for a match.</param>
 /// <param name="pattern">The regular expression pattern to match.</param>
 /// <returns>The number of matches.</returns>
 /// <exception cref="RegexParseException">A regular expression parsing error occurred.</exception>
 public static int Count(ReadOnlySpan <char> input, [StringSyntax(StringSyntaxAttribute.Regex)] string pattern) =>
 RegexCache.GetOrAdd(pattern).Count(input);
Exemplo n.º 27
0
 /// <summary>
 /// Searches the input string for one or more occurrences of the text
 /// supplied in the pattern parameter with matching options supplied in the options
 /// parameter.
 /// </summary>
 public static bool IsMatch(string input, [StringSyntax(StringSyntaxAttribute.Regex, "options")] string pattern, RegexOptions options) =>
 RegexCache.GetOrAdd(pattern, options, s_defaultMatchTimeout).IsMatch(input);
 /// <summary>
 /// Splits the <paramref name="input "/>string at the position defined
 /// by <paramref name="pattern"/>.
 /// </summary>
 public static string[] Split(string input, string pattern) =>
 RegexCache.GetOrAdd(pattern).Split(input);
Exemplo n.º 29
0
 public static Match Match(string input, [StringSyntax(StringSyntaxAttribute.Regex, "options")] string pattern, RegexOptions options, TimeSpan matchTimeout) =>
 RegexCache.GetOrAdd(pattern, options, matchTimeout).Match(input);
 /// <summary>
 /// Splits the <paramref name="input "/>string at the position defined by <paramref name="pattern"/>.
 /// </summary>
 public static string[] Split(string input, string pattern, RegexOptions options) =>
 RegexCache.GetOrAdd(pattern, options, s_defaultMatchTimeout).Split(input);