| @@ -11,6 +11,16 @@ namespace Discord.Rest | |||||
| { | { | ||||
| internal static class MessageHelper | internal static class MessageHelper | ||||
| { | { | ||||
| /// <summary> | |||||
| /// Regex used to check if some text is formatted as inline code. | |||||
| /// </summary> | |||||
| private static readonly Regex InlineCodeRegex = new Regex(@"[^\\]?(`).+?[^\\](`)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | |||||
| /// <summary> | |||||
| /// Regex used to check if some text is formatted as a code block. | |||||
| /// </summary> | |||||
| private static readonly Regex BlockCodeRegex = new Regex(@"[^\\]?(```).+?[^\\](```)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | |||||
| /// <exception cref="InvalidOperationException">Only the author of a message may modify the message.</exception> | /// <exception cref="InvalidOperationException">Only the author of a message may modify the message.</exception> | ||||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | ||||
| public static async Task<Model> ModifyAsync(IMessage msg, BaseDiscordClient client, Action<MessageProperties> func, | public static async Task<Model> ModifyAsync(IMessage msg, BaseDiscordClient client, Action<MessageProperties> func, | ||||
| @@ -112,9 +122,6 @@ namespace Discord.Rest | |||||
| int index = 0; | int index = 0; | ||||
| var codeIndex = 0; | var codeIndex = 0; | ||||
| var inlineRegex = new Regex(@"[^\\]?(`).+?[^\\](`)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | |||||
| var blockRegex = new Regex(@"[^\\]?(```).+?[^\\](```)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | |||||
| // checks if the tag being parsed is wrapped in code blocks | // checks if the tag being parsed is wrapped in code blocks | ||||
| bool CheckWrappedCode() | bool CheckWrappedCode() | ||||
| { | { | ||||
| @@ -125,7 +132,7 @@ namespace Discord.Rest | |||||
| // loop through all code blocks that are before the start of the tag | // loop through all code blocks that are before the start of the tag | ||||
| while (codeIndex < index) | while (codeIndex < index) | ||||
| { | { | ||||
| var blockMatch = blockRegex.Match(text, codeIndex); | |||||
| var blockMatch = BlockCodeRegex.Match(text, codeIndex); | |||||
| if (blockMatch.Success) | if (blockMatch.Success) | ||||
| { | { | ||||
| if (EnclosedInBlock(blockMatch)) | if (EnclosedInBlock(blockMatch)) | ||||
| @@ -136,7 +143,7 @@ namespace Discord.Rest | |||||
| continue; | continue; | ||||
| return false; | return false; | ||||
| } | } | ||||
| var inlineMatch = inlineRegex.Match(text, codeIndex); | |||||
| var inlineMatch = InlineCodeRegex.Match(text, codeIndex); | |||||
| if (inlineMatch.Success) | if (inlineMatch.Success) | ||||
| { | { | ||||
| if (EnclosedInBlock(inlineMatch)) | if (EnclosedInBlock(inlineMatch)) | ||||