Browse Source

Clean Content Expanded (#212)

* Implement CleanContent In IMessage & RestMessage

* Update Spelling and Documentation

* Add SanatizeMessage to MessageHelper and Refactor Rest and Socket Message
pull/1923/head
Emily GitHub 3 years ago
parent
commit
c073db1cec
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 10 deletions
  1. +23
    -0
      src/Discord.Net.Core/Discord.Net.Core.xml
  2. +7
    -0
      src/Discord.Net.Core/Entities/Messages/IMessage.cs
  3. +3
    -0
      src/Discord.Net.Rest/Discord.Net.Rest.xml
  4. +6
    -0
      src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
  5. +3
    -1
      src/Discord.Net.Rest/Entities/Messages/RestMessage.cs
  6. +1
    -9
      src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs

+ 23
- 0
src/Discord.Net.Core/Discord.Net.Core.xml View File

@@ -508,6 +508,11 @@
The user has set a custom status.
</summary>
</member>
<member name="F:Discord.ActivityType.Competing">
<summary>
The user is competing in a game.
</summary>
</member>
<member name="T:Discord.CustomStatusGame">
<summary>
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.
</returns>
</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">
<summary>
Gets the time this message was sent.
@@ -12920,10 +12933,20 @@
<member name="M:Discord.Utils.UrlValidation.Validate(System.String)">
<summary>
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>
<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>
<returns>true if url is valid by our standard, false if null, throws an error upon invalid </returns>
</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>
</doc>

+ 7
- 0
src/Discord.Net.Core/Entities/Messages/IMessage.cs View File

@@ -53,6 +53,13 @@ namespace Discord
/// </returns>
string Content { get; }
/// <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.
/// </summary>
/// <returns>


+ 3
- 0
src/Discord.Net.Rest/Discord.Net.Rest.xml View File

@@ -4299,6 +4299,9 @@
<member name="P:Discord.Rest.RestMessage.Content">
<inheritdoc />
</member>
<member name="P:Discord.Rest.RestMessage.CleanContent">
<inheritdoc />
</member>
<member name="P:Discord.Rest.RestMessage.CreatedAt">
<inheritdoc />
</member>


+ 6
- 0
src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs View File

@@ -246,6 +246,12 @@ namespace Discord.Rest
return System.Web.HttpUtility.UrlEncode(text);
#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,
RequestOptions options)


+ 3
- 1
src/Discord.Net.Rest/Entities/Messages/RestMessage.cs View File

@@ -28,6 +28,9 @@ namespace Discord.Rest
/// <inheritdoc />
public string Content { get; private set; }

/// <inheritdoc />
public string CleanContent => MessageHelper.SanitizeMessage(this);

/// <inheritdoc />
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
/// <inheritdoc />
@@ -208,7 +211,6 @@ namespace Discord.Rest
else
_reactions = ImmutableArray.Create<RestReaction>();
}

/// <inheritdoc />
public async Task UpdateAsync(RequestOptions options = null)
{


+ 1
- 9
src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs View File

@@ -39,7 +39,7 @@ namespace Discord.WebSocket
public string Content { get; private set; }

/// <inheritdoc />
public string CleanContent => SanitizeMessage();
public string CleanContent => MessageHelper.SanitizeMessage(this);

/// <inheritdoc />
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
@@ -144,8 +144,6 @@ namespace Discord.WebSocket
if (model.Content.IsSpecified)
{
Content = model.Content.Value;
//Update CleanContent Property
SanitizeMessage();
}

if (model.Application.IsSpecified)
@@ -272,12 +270,6 @@ namespace Discord.WebSocket
/// <inheritdoc />
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)
{


Loading…
Cancel
Save