-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37eeab1
commit f457023
Showing
12 changed files
with
304 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Disqord.Models; | ||
|
||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents a custom emoji (e.g. <c><:professor:667582610431803437></c>) retrieved from an application. | ||
/// </summary> | ||
public interface IApplicationEmoji : ICustomEmoji, IApplicationEntity, IClientEntity, INamableEntity, IJsonUpdatable<EmojiJsonModel> | ||
{ | ||
/// <summary> | ||
/// Gets the user that created this emoji. | ||
/// </summary> | ||
IUser? Creator { get; } | ||
|
||
/// <summary> | ||
/// Gets whether this emoji requires colons in chat. | ||
/// </summary> | ||
bool RequiresColons { get; } | ||
|
||
/// <summary> | ||
/// Gets whether this emoji is managed by an integration. | ||
/// </summary> | ||
bool IsManaged { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents a Discord entity that exists within an application. | ||
/// </summary> | ||
public interface IApplicationEntity | ||
{ | ||
/// <summary> | ||
/// Gets the ID of the application this entity is tied to. | ||
/// </summary> | ||
Snowflake ApplicationId { get; } | ||
} |
59 changes: 59 additions & 0 deletions
59
src/Disqord.Core/Entities/Transient/Emoji/TransientApplicationEmoji.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,59 @@ | ||
using Disqord.Models; | ||
using Qommon; | ||
|
||
namespace Disqord; | ||
|
||
public class TransientApplicationEmoji : TransientClientEntity<EmojiJsonModel>, IApplicationEmoji | ||
{ | ||
/// <inheritdoc /> | ||
public Snowflake Id => Model.Id!.Value; | ||
|
||
/// <inheritdoc /> | ||
public Snowflake ApplicationId { get; } | ||
|
||
/// <inheritdoc cref="INamableEntity.Name"/> | ||
public string Name => Model.Name!; | ||
|
||
/// <inheritdoc/> | ||
public bool IsAnimated => Model.Animated.Value; | ||
|
||
/// <inheritdoc/> | ||
public IUser? Creator => _creator ??= Optional.ConvertOrDefault(Model.User, static (user, client) => new TransientUser(client, user), Client); | ||
|
||
private IUser? _creator; | ||
|
||
/// <inheritdoc/> | ||
public bool RequiresColons => Model.RequireColons.Value; | ||
|
||
/// <inheritdoc/> | ||
public bool IsManaged => Model.Managed.Value; | ||
|
||
/// <inheritdoc/> | ||
public string Tag => ToString(); | ||
|
||
public TransientApplicationEmoji(IClient client, Snowflake applicationId, EmojiJsonModel model) | ||
: base(client, model) | ||
{ | ||
ApplicationId = applicationId; | ||
} | ||
|
||
public bool Equals(IEmoji? other) | ||
{ | ||
return Comparers.Emoji.Equals(this, other); | ||
} | ||
|
||
public bool Equals(ICustomEmoji? other) | ||
{ | ||
return Comparers.Emoji.Equals(this, other); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Comparers.Emoji.GetHashCode(this); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return this.GetString(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Disqord.Rest.Api/Content/Json/CreateApplicationEmojiJsonRestRequestContent.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,19 @@ | ||
using System.IO; | ||
using Disqord.Serialization.Json; | ||
|
||
namespace Disqord.Rest.Api; | ||
|
||
public class CreateApplicationEmojiJsonRestRequestContent : JsonModelRestRequestContent | ||
{ | ||
[JsonProperty("name")] | ||
public string Name; | ||
|
||
[JsonProperty("image")] | ||
public Stream Image; | ||
|
||
public CreateApplicationEmojiJsonRestRequestContent(string name, Stream image) | ||
{ | ||
Name = name; | ||
Image = image; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Disqord.Rest.Api/Content/Json/ModifyApplicationEmojiJsonRestRequestContent.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,10 @@ | ||
using Disqord.Serialization.Json; | ||
using Qommon; | ||
|
||
namespace Disqord.Rest.Api; | ||
|
||
public class ModifyApplicationEmojiJsonRestRequestContent : JsonModelRestRequestContent | ||
{ | ||
[JsonProperty("name")] | ||
public Optional<string> Name; | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/Disqord.Rest/ActionProperties/Modify/ModifyApplicationEmojiActionProperties.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,11 @@ | ||
using Qommon; | ||
|
||
namespace Disqord; | ||
|
||
public class ModifyApplicationEmojiActionProperties | ||
{ | ||
public Optional<string> Name { internal get; set; } | ||
|
||
internal ModifyApplicationEmojiActionProperties() | ||
{ } | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Disqord.Rest/Extensions/Entity/RestEntityExtensions.Application.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,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Disqord.Rest; | ||
|
||
public static partial class RestEntityExtensions | ||
{ | ||
public static Task<IReadOnlyList<IApplicationEmoji>> FetchEmojisAsync(this IApplication application, | ||
IRestRequestOptions? options = null, CancellationToken cancellationToken = default) | ||
{ | ||
var client = application.GetRestClient(); | ||
return client.FetchApplicationEmojisAsync(application.Id, options, cancellationToken); | ||
} | ||
|
||
public static Task<IApplicationEmoji> FetchEmojiAsync(this IApplication application, | ||
Snowflake emojiId, | ||
IRestRequestOptions? options = null, CancellationToken cancellationToken = default) | ||
{ | ||
var client = application.GetRestClient(); | ||
return client.FetchApplicationEmojiAsync(application.Id, emojiId, options, cancellationToken); | ||
} | ||
|
||
public static Task<IApplicationEmoji> CreateEmojiAsync(this IApplication application, | ||
string name, Stream image, | ||
IRestRequestOptions? options = null, CancellationToken cancellationToken = default) | ||
{ | ||
var client = application.GetRestClient(); | ||
return client.CreateApplicationEmojiAsync(application.Id, name, image, options, cancellationToken); | ||
} | ||
|
||
public static Task<IApplicationEmoji> ModifyEmojiAsync(this IApplication application, | ||
Snowflake emojiId, Action<ModifyApplicationEmojiActionProperties> action, | ||
IRestRequestOptions? options = null, CancellationToken cancellationToken = default) | ||
{ | ||
var client = application.GetRestClient(); | ||
return client.ModifyApplicationEmojiAsync(application.Id, emojiId, action, options, cancellationToken); | ||
} | ||
|
||
public static Task DeleteEmojiAsync(this IApplication application, | ||
Snowflake emojiId, | ||
IRestRequestOptions? options = null, CancellationToken cancellationToken = default) | ||
{ | ||
var client = application.GetRestClient(); | ||
return client.DeleteApplicationEmojiAsync(application.Id, emojiId, options, cancellationToken); | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
src/Disqord.Rest/Extensions/Entity/RestEntityExtensions.User.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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
|
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