diff --git a/src/Discord.Net.Core/Discord.Net.Core.xml b/src/Discord.Net.Core/Discord.Net.Core.xml
index 30e0a417f..64fbd9e23 100644
--- a/src/Discord.Net.Core/Discord.Net.Core.xml
+++ b/src/Discord.Net.Core/Discord.Net.Core.xml
@@ -11423,6 +11423,13 @@
The text to format.
Gets the formatted block quote text.
+
+
+ Remove discord supported markdown from text.
+
+ The to remove markdown from.
+ Gets the unformatted text.
+
This intent includes no events
diff --git a/src/Discord.Net.Core/Format.cs b/src/Discord.Net.Core/Format.cs
index 0ab70f89c..320c3a5fb 100644
--- a/src/Discord.Net.Core/Format.cs
+++ b/src/Discord.Net.Core/Format.cs
@@ -1,4 +1,5 @@
using System.Text;
+using System.Text.RegularExpressions;
namespace Discord
{
@@ -91,5 +92,17 @@ namespace Discord
return $">>> {text}";
}
+
+ ///
+ /// Remove discord supported markdown from text.
+ ///
+ /// The to remove markdown from.
+ /// Gets the unformatted text.
+ public static string StripMarkDown(string text)
+ {
+ //Remove discord supported markdown
+ var newText = Regex.Replace(text, @"(\*|_|`|~|>|\\)", "");
+ return newText;
+ }
}
}
diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml
index ea9937cd1..a1374578a 100644
--- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml
+++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml
@@ -4531,6 +4531,9 @@
+
+
+
diff --git a/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs b/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs
index acf60f371..b86a2bbfa 100644
--- a/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs
+++ b/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs
@@ -38,6 +38,9 @@ namespace Discord.WebSocket
///
public string Content { get; private set; }
+ ///
+ public string CleanContent => SanitizeMessage();
+
///
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
///
@@ -139,7 +142,11 @@ namespace Discord.WebSocket
_timestampTicks = model.Timestamp.Value.UtcTicks;
if (model.Content.IsSpecified)
+ {
Content = model.Content.Value;
+ //Update CleanContent Property
+ SanitizeMessage();
+ }
if (model.Application.IsSpecified)
{
@@ -265,6 +272,13 @@ namespace Discord.WebSocket
///
IReadOnlyCollection 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)
{
_reactions.Add(reaction);
diff --git a/test/Discord.Net.Tests.Unit/FormatTests.cs b/test/Discord.Net.Tests.Unit/FormatTests.cs
index 2a5adbaae..8cb632b7e 100644
--- a/test/Discord.Net.Tests.Unit/FormatTests.cs
+++ b/test/Discord.Net.Tests.Unit/FormatTests.cs
@@ -59,5 +59,20 @@ namespace Discord
{
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);
+ }
}
}