forked from Quahu/Disqord
-
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.
Implement default values for auto-populated selections (Quahu#108)
* Implement default values for selections * Added validation for default selection values * Fix check * Update validation check * Add case to handle warning
- Loading branch information
1 parent
9b2a2c1
commit 39562c2
Showing
11 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/Disqord.Core/Entities/Core/Interactions/Components/IDefaultSelectionValue.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,12 @@ | ||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents a default value of a selection message component. | ||
/// </summary> | ||
public interface IDefaultSelectionValue: IIdentifiableEntity | ||
{ | ||
/// <summary> | ||
/// Gets the type of this default value. | ||
/// </summary> | ||
DefaultSelectionValueType Type { get; } | ||
} |
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
69 changes: 69 additions & 0 deletions
69
...isqord.Core/Entities/Local/Interaction/Components/Selection/LocalDefaultSelectionValue.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,69 @@ | ||
using Disqord.Models; | ||
|
||
namespace Disqord; | ||
|
||
public class LocalDefaultSelectionValue : IDefaultSelectionValue, ILocalConstruct<LocalDefaultSelectionValue>, IJsonConvertible<DefaultValueJsonModel> | ||
{ | ||
public static LocalDefaultSelectionValue User(Snowflake id) | ||
{ | ||
return new(id, DefaultSelectionValueType.User); | ||
} | ||
|
||
public static LocalDefaultSelectionValue Role(Snowflake id) | ||
{ | ||
return new(id, DefaultSelectionValueType.Role); | ||
} | ||
|
||
public static LocalDefaultSelectionValue Channel(Snowflake id) | ||
{ | ||
return new(id, DefaultSelectionValueType.Channel); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public Snowflake Id { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public DefaultSelectionValueType Type { get; set; } | ||
|
||
/// <summary> | ||
/// Instantiates a new <see cref="LocalDefaultSelectionValue"/>. | ||
/// </summary> | ||
public LocalDefaultSelectionValue() | ||
{ } | ||
|
||
/// <summary> | ||
/// Instantiates a new <see cref="LocalDefaultSelectionValue"/>. | ||
/// </summary> | ||
/// <param name="id"> The id of the entity. </param> | ||
/// <param name="type"> The type of the entity. </param> | ||
public LocalDefaultSelectionValue(Snowflake id, DefaultSelectionValueType type) | ||
{ | ||
Id = id; | ||
Type = type; | ||
} | ||
|
||
/// <summary> | ||
/// Instantiates a new <see cref="LocalDefaultSelectionValue"/> with the properties copied from another instance. | ||
/// </summary> | ||
/// <param name="other"> The other instance to copy properties from. </param> | ||
protected LocalDefaultSelectionValue(LocalDefaultSelectionValue other) | ||
{ | ||
Id = other.Id; | ||
Type = other.Type; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public LocalDefaultSelectionValue Clone() | ||
{ | ||
return new(this); | ||
} | ||
|
||
public DefaultValueJsonModel ToModel() | ||
{ | ||
return new DefaultValueJsonModel | ||
{ | ||
Id = Id, | ||
Type = Type | ||
}; | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
...Disqord.Core/Entities/Transient/Interactions/Components/TransientDefaultSelectionValue.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,17 @@ | ||
using Disqord.Models; | ||
|
||
namespace Disqord; | ||
|
||
/// <inheritdoc cref="IDefaultSelectionValue"/> | ||
public class TransientDefaultSelectionValue : TransientClientEntity<DefaultValueJsonModel>, IDefaultSelectionValue | ||
{ | ||
/// <inheritdoc/> | ||
public Snowflake Id => Model.Id; | ||
|
||
/// <inheritdoc/> | ||
public DefaultSelectionValueType Type => Model.Type; | ||
|
||
public TransientDefaultSelectionValue(IClient client, DefaultValueJsonModel model) | ||
: base(client, model) | ||
{ } | ||
} |
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
20 changes: 20 additions & 0 deletions
20
src/Disqord.Core/Enums/Interactions/Components/DefaultSelectionValueType.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,20 @@ | ||
using System.Runtime.Serialization; | ||
using Disqord.Serialization.Json; | ||
|
||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents the type of default selection value. | ||
/// </summary> | ||
[StringEnum] | ||
public enum DefaultSelectionValueType | ||
{ | ||
[EnumMember(Value = "user")] | ||
User, | ||
|
||
[EnumMember(Value = "role")] | ||
Role, | ||
|
||
[EnumMember(Value = "channel")] | ||
Channel, | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/Disqord.Core/Models/Interactions/Components/DefaultValueJsonModel.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,12 @@ | ||
using Disqord.Serialization.Json; | ||
|
||
namespace Disqord.Models; | ||
|
||
public class DefaultValueJsonModel : JsonModel | ||
{ | ||
[JsonProperty("id")] | ||
public Snowflake Id; | ||
|
||
[JsonProperty("type")] | ||
public DefaultSelectionValueType Type; | ||
} |