forked from discord-net/Discord.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Include allowed mentions payload on message creation (discor…
…d-net#1455) * Feature: Allowed mentions object on msg create (interface breaking) This change implements the AllowedMentions object for the payload of message creation. By default, the mentions behavior remains unchanged, the message content is parsed for all mentionable entities and they are all notified. If this payload is not null, it will use the content of the allowed_mentions field to determine if a role is notified, or just displayed. This change is interface breaking. This follows the conventions of keeping RequestOptions as the last argument, but could break some users who specify each of these arguments without using named arguments. * lint: remove commented-out code This change removes the commented-out code which was added during testing from the previous commit. * fix interface break: reorder allowedMentions arg so that it's after options This change modifies the order of the AllowedMentions argument of SendMessageAsync so that this addition shouldn't be interface breaking. The downside to this change is that it breaks the convention followed by other methods, where the RequestOptions argument is normally last. * docs: fix typo in allowedMentions arg doc * fix interface break arg from IRestMessageChannel * docs: update xmldoc for allowedMentions args * fix interface breaking arg order for ISocketMessageChannel * fix mocked classes that weren't updated * fix: RestDMChannel#SendMessageAsync bug, allowed mentions always null This change fixes a bug that was introduced while testing changes to the interface of the SendMessageAsync method to try and retain interface compatibility * docs: update xmldoc for AllowedMentions type * docs: reword xmldoc of AllowedMentionTypes type * docs: fix typo * fix: validate that User/Role flags and UserIds/RoleIds lists are mutually exclusive This change adds validation to SendMessageAsync which checks that the User flag is mutually exclusive with the list of UserIds, and that the Role flag is also mutually exclusive with the list of RoleIds * docs: reword summaries for AllowedMentions type * Add util properties for specifying all or no mentions Adds read only properties which specify that all mentions or no mentions will notify users. These settings might be more common than others, so this would make them easier to use. * docs: Resolve PR comments for documentation issues/typos
- Loading branch information
1 parent
9678cd1
commit 9043b85
Showing
21 changed files
with
204 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Discord.Net.Core/Entities/Messages/AllowedMentionTypes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
|
||
namespace Discord | ||
{ | ||
/// <summary> | ||
/// Specifies the type of mentions that will be notified from the message content. | ||
/// </summary> | ||
[Flags] | ||
public enum AllowedMentionTypes | ||
{ | ||
/// <summary> | ||
/// Controls role mentions. | ||
/// </summary> | ||
Roles, | ||
/// <summary> | ||
/// Controls user mentions. | ||
/// </summary> | ||
Users, | ||
/// <summary> | ||
/// Controls <code>@everyone</code> and <code>@here</code> mentions. | ||
/// </summary> | ||
Everyone, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Discord | ||
{ | ||
/// <summary> | ||
/// Defines which mentions and types of mentions that will notify users from the message content. | ||
/// </summary> | ||
public class AllowedMentions | ||
{ | ||
private static readonly Lazy<AllowedMentions> none = new Lazy<AllowedMentions>(() => new AllowedMentions()); | ||
private static readonly Lazy<AllowedMentions> all = new Lazy<AllowedMentions>(() => | ||
new AllowedMentions(AllowedMentionTypes.Everyone | AllowedMentionTypes.Users | AllowedMentionTypes.Roles)); | ||
|
||
/// <summary> | ||
/// Gets a value which indicates that no mentions in the message content should notify users. | ||
/// </summary> | ||
public static AllowedMentions None => none.Value; | ||
|
||
/// <summary> | ||
/// Gets a value which indicates that all mentions in the message content should notify users. | ||
/// </summary> | ||
public static AllowedMentions All => all.Value; | ||
|
||
/// <summary> | ||
/// Gets or sets the type of mentions that will be parsed from the message content. | ||
/// </summary> | ||
/// <remarks> | ||
/// The <see cref="AllowedMentionTypes.Users"/> flag is mutually exclusive with the <see cref="UserIds"/> | ||
/// property, and the <see cref="AllowedMentionTypes.Roles"/> flag is mutually exclusive with the | ||
/// <see cref="RoleIds"/> property. | ||
/// If <c>null</c>, only the ids specified in <see cref="UserIds"/> and <see cref="RoleIds"/> will be mentioned. | ||
/// </remarks> | ||
public AllowedMentionTypes? AllowedTypes { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the list of all role ids that will be mentioned. | ||
/// This property is mutually exclusive with the <see cref="AllowedMentionTypes.Roles"/> | ||
/// flag of the <see cref="AllowedTypes"/> property. If the flag is set, the value of this property | ||
/// must be <c>null</c> or empty. | ||
/// </summary> | ||
public List<ulong> RoleIds { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the list of all user ids that will be mentioned. | ||
/// This property is mutually exclusive with the <see cref="AllowedMentionTypes.Users"/> | ||
/// flag of the <see cref="AllowedTypes"/> property. If the flag is set, the value of this property | ||
/// must be <c>null</c> or empty. | ||
/// </summary> | ||
public List<ulong> UserIds { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AllowedMentions"/> class. | ||
/// </summary> | ||
/// <param name="allowedTypes"> | ||
/// The types of mentions to parse from the message content. | ||
/// If <c>null</c>, only the ids specified in <see cref="UserIds"/> and <see cref="RoleIds"/> will be mentioned. | ||
/// </param> | ||
public AllowedMentions(AllowedMentionTypes? allowedTypes = null) | ||
{ | ||
AllowedTypes = allowedTypes; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Discord.API | ||
{ | ||
public class AllowedMentions | ||
{ | ||
[JsonProperty("parse")] | ||
public Optional<string[]> Parse { get; set; } | ||
// Roles and Users have a max size of 100 | ||
[JsonProperty("roles")] | ||
public Optional<ulong[]> Roles { get; set; } | ||
[JsonProperty("users")] | ||
public Optional<ulong[]> Users { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.