* Added Clean Content Function * Fixed Spelling problems and bad var handling * Add StripMarkDown Methodpull/1923/head
| @@ -11423,6 +11423,13 @@ | |||||
| <param name="text">The text to format.</param> | <param name="text">The text to format.</param> | ||||
| <returns>Gets the formatted block quote text.</returns> | <returns>Gets the formatted block quote text.</returns> | ||||
| </member> | </member> | ||||
| <member name="M:Discord.Format.StripMarkDown(System.String)"> | |||||
| <summary> | |||||
| Remove discord supported markdown from text. | |||||
| </summary> | |||||
| <param name="text">The to remove markdown from.</param> | |||||
| <returns>Gets the unformatted text.</returns> | |||||
| </member> | |||||
| <member name="F:Discord.GatewayIntents.None"> | <member name="F:Discord.GatewayIntents.None"> | ||||
| <summary> This intent includes no events </summary> | <summary> This intent includes no events </summary> | ||||
| </member> | </member> | ||||
| @@ -1,4 +1,5 @@ | |||||
| using System.Text; | using System.Text; | ||||
| using System.Text.RegularExpressions; | |||||
| namespace Discord | namespace Discord | ||||
| { | { | ||||
| @@ -91,5 +92,17 @@ namespace Discord | |||||
| return $">>> {text}"; | return $">>> {text}"; | ||||
| } | } | ||||
| /// <summary> | |||||
| /// Remove discord supported markdown from text. | |||||
| /// </summary> | |||||
| /// <param name="text">The to remove markdown from.</param> | |||||
| /// <returns>Gets the unformatted text.</returns> | |||||
| public static string StripMarkDown(string text) | |||||
| { | |||||
| //Remove discord supported markdown | |||||
| var newText = Regex.Replace(text, @"(\*|_|`|~|>|\\)", ""); | |||||
| return newText; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -4531,6 +4531,9 @@ | |||||
| <member name="P:Discord.WebSocket.SocketMessage.Content"> | <member name="P:Discord.WebSocket.SocketMessage.Content"> | ||||
| <inheritdoc /> | <inheritdoc /> | ||||
| </member> | </member> | ||||
| <member name="P:Discord.WebSocket.SocketMessage.CleanContent"> | |||||
| <inheritdoc /> | |||||
| </member> | |||||
| <member name="P:Discord.WebSocket.SocketMessage.CreatedAt"> | <member name="P:Discord.WebSocket.SocketMessage.CreatedAt"> | ||||
| <inheritdoc /> | <inheritdoc /> | ||||
| </member> | </member> | ||||
| @@ -38,6 +38,9 @@ namespace Discord.WebSocket | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public string Content { get; private set; } | public string Content { get; private set; } | ||||
| /// <inheritdoc /> | |||||
| public string CleanContent => SanitizeMessage(); | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| @@ -139,7 +142,11 @@ namespace Discord.WebSocket | |||||
| _timestampTicks = model.Timestamp.Value.UtcTicks; | _timestampTicks = model.Timestamp.Value.UtcTicks; | ||||
| if (model.Content.IsSpecified) | if (model.Content.IsSpecified) | ||||
| { | |||||
| Content = model.Content.Value; | Content = model.Content.Value; | ||||
| //Update CleanContent Property | |||||
| SanitizeMessage(); | |||||
| } | |||||
| if (model.Application.IsSpecified) | if (model.Application.IsSpecified) | ||||
| { | { | ||||
| @@ -265,6 +272,13 @@ namespace Discord.WebSocket | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| IReadOnlyCollection<IStickerItem> IMessage.Stickers => Stickers; | IReadOnlyCollection<IStickerItem> IMessage.Stickers => Stickers; | ||||
| internal string SanitizeMessage() | |||||
| { | |||||
| var newContent = MentionUtils.Resolve(this, 0, TagHandling.Sanitize, TagHandling.Sanitize, TagHandling.Sanitize, TagHandling.Sanitize, TagHandling.Sanitize); | |||||
| newContent = Format.StripMarkDown(newContent); | |||||
| return newContent; | |||||
| } | |||||
| internal void AddReaction(SocketReaction reaction) | internal void AddReaction(SocketReaction reaction) | ||||
| { | { | ||||
| _reactions.Add(reaction); | _reactions.Add(reaction); | ||||
| @@ -59,5 +59,20 @@ namespace Discord | |||||
| { | { | ||||
| Assert.Equal(expected, Format.BlockQuote(input)); | Assert.Equal(expected, Format.BlockQuote(input)); | ||||
| } | } | ||||
| [Theory] | |||||
| [InlineData("", "")] | |||||
| [InlineData("\n", "\n")] | |||||
| [InlineData("**hi**", "hi")] | |||||
| [InlineData("__uwu__", "uwu")] | |||||
| [InlineData(">>__uwu__", "uwu")] | |||||
| [InlineData("```uwu```", "uwu")] | |||||
| [InlineData("~uwu~", "uwu")] | |||||
| [InlineData("berries __and__ *Cream**, i'm a little lad who loves berries and cream", "berries and Cream, i'm a little lad who loves berries and cream")] | |||||
| public void StripMarkdown(string input, string expected) | |||||
| { | |||||
| var test = Format.StripMarkDown(input); | |||||
| Assert.Equal(expected, test); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||