* Implement CleanContent In IMessage & RestMessage * Update Spelling and Documentation * Add SanatizeMessage to MessageHelper and Refactor Rest and Socket Messagepull/1923/head
@@ -508,6 +508,11 @@ | |||||
The user has set a custom status. | The user has set a custom status. | ||||
</summary> | </summary> | ||||
</member> | </member> | ||||
<member name="F:Discord.ActivityType.Competing"> | |||||
<summary> | |||||
The user is competing in a game. | |||||
</summary> | |||||
</member> | |||||
<member name="T:Discord.CustomStatusGame"> | <member name="T:Discord.CustomStatusGame"> | ||||
<summary> | <summary> | ||||
A user's activity for their custom status. | A user's activity for their custom status. | ||||
@@ -7594,6 +7599,14 @@ | |||||
A string that contains the body of the message; note that this field may be empty if there is an embed. | A string that contains the body of the message; note that this field may be empty if there is an embed. | ||||
</returns> | </returns> | ||||
</member> | </member> | ||||
<member name="P:Discord.IMessage.CleanContent"> | |||||
<summary> | |||||
Gets the clean content for this message. | |||||
</summary> | |||||
<returns> | |||||
A string that contains the body of the message stripped of mentions, markdown, emojiis and pings; note that this field may be empty if there is an embed. | |||||
</returns> | |||||
</member> | |||||
<member name="P:Discord.IMessage.Timestamp"> | <member name="P:Discord.IMessage.Timestamp"> | ||||
<summary> | <summary> | ||||
Gets the time this message was sent. | Gets the time this message was sent. | ||||
@@ -12920,10 +12933,20 @@ | |||||
<member name="M:Discord.Utils.UrlValidation.Validate(System.String)"> | <member name="M:Discord.Utils.UrlValidation.Validate(System.String)"> | ||||
<summary> | <summary> | ||||
Not full URL validation right now. Just ensures protocol is present and that it's either http or https | Not full URL validation right now. Just ensures protocol is present and that it's either http or https | ||||
<see cref="M:Discord.Utils.UrlValidation.ValidateButton(System.String)"/> should be used for url buttons | |||||
</summary> | </summary> | ||||
<param name="url">url to validate before sending to Discord.</param> | <param name="url">url to validate before sending to Discord.</param> | ||||
<exception cref="T:System.InvalidOperationException">A URL must include a protocol (http or https).</exception> | <exception cref="T:System.InvalidOperationException">A URL must include a protocol (http or https).</exception> | ||||
<returns>true if url is valid by our standard, false if null, throws an error upon invalid </returns> | <returns>true if url is valid by our standard, false if null, throws an error upon invalid </returns> | ||||
</member> | </member> | ||||
<member name="M:Discord.Utils.UrlValidation.ValidateButton(System.String)"> | |||||
<summary> | |||||
Not full URL validation right now. Just Ensures the protocol is either http, https, or discord | |||||
<see cref="M:Discord.Utils.UrlValidation.Validate(System.String)"/> should be used everything other than url buttons | |||||
</summary> | |||||
<param name="url">the url to validate before sending to discord</param> | |||||
<exception cref="T:System.InvalidOperationException">A URL must include a protocol (either http, https, or discord).</exception> | |||||
<returns>true if the url is valid by our standard, false if null, throws an error upon invalid</returns> | |||||
</member> | |||||
</members> | </members> | ||||
</doc> | </doc> |
@@ -53,6 +53,13 @@ namespace Discord | |||||
/// </returns> | /// </returns> | ||||
string Content { get; } | string Content { get; } | ||||
/// <summary> | /// <summary> | ||||
/// Gets the clean content for this message. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// A string that contains the body of the message stripped of mentions, markdown, emojiis and pings; note that this field may be empty if there is an embed. | |||||
/// </returns> | |||||
string CleanContent { get; } | |||||
/// <summary> | |||||
/// Gets the time this message was sent. | /// Gets the time this message was sent. | ||||
/// </summary> | /// </summary> | ||||
/// <returns> | /// <returns> | ||||
@@ -4299,6 +4299,9 @@ | |||||
<member name="P:Discord.Rest.RestMessage.Content"> | <member name="P:Discord.Rest.RestMessage.Content"> | ||||
<inheritdoc /> | <inheritdoc /> | ||||
</member> | </member> | ||||
<member name="P:Discord.Rest.RestMessage.CleanContent"> | |||||
<inheritdoc /> | |||||
</member> | |||||
<member name="P:Discord.Rest.RestMessage.CreatedAt"> | <member name="P:Discord.Rest.RestMessage.CreatedAt"> | ||||
<inheritdoc /> | <inheritdoc /> | ||||
</member> | </member> | ||||
@@ -246,6 +246,12 @@ namespace Discord.Rest | |||||
return System.Web.HttpUtility.UrlEncode(text); | return System.Web.HttpUtility.UrlEncode(text); | ||||
#endif | #endif | ||||
} | } | ||||
public static string SanitizeMessage(IMessage message) | |||||
{ | |||||
var newContent = MentionUtils.Resolve(message, 0, TagHandling.Sanitize, TagHandling.Sanitize, TagHandling.Sanitize, TagHandling.Sanitize, TagHandling.Sanitize); | |||||
newContent = Format.StripMarkDown(newContent); | |||||
return newContent; | |||||
} | |||||
public static async Task PinAsync(IMessage msg, BaseDiscordClient client, | public static async Task PinAsync(IMessage msg, BaseDiscordClient client, | ||||
RequestOptions options) | RequestOptions options) | ||||
@@ -28,6 +28,9 @@ namespace Discord.Rest | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public string Content { get; private set; } | public string Content { get; private set; } | ||||
/// <inheritdoc /> | |||||
public string CleanContent => MessageHelper.SanitizeMessage(this); | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
@@ -208,7 +211,6 @@ namespace Discord.Rest | |||||
else | else | ||||
_reactions = ImmutableArray.Create<RestReaction>(); | _reactions = ImmutableArray.Create<RestReaction>(); | ||||
} | } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public async Task UpdateAsync(RequestOptions options = null) | public async Task UpdateAsync(RequestOptions options = null) | ||||
{ | { | ||||
@@ -39,7 +39,7 @@ namespace Discord.WebSocket | |||||
public string Content { get; private set; } | public string Content { get; private set; } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public string CleanContent => SanitizeMessage(); | |||||
public string CleanContent => MessageHelper.SanitizeMessage(this); | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | ||||
@@ -144,8 +144,6 @@ namespace Discord.WebSocket | |||||
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) | ||||
@@ -272,12 +270,6 @@ 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) | ||||
{ | { | ||||