feature: Add stickers (#1726)
This commit is contained in:
@@ -58,5 +58,7 @@ namespace Discord.API
|
||||
public Optional<AllowedMentions> AllowedMentions { get; set; }
|
||||
[JsonProperty("referenced_message")]
|
||||
public Optional<Message> ReferencedMessage { get; set; }
|
||||
[JsonProperty("stickers")]
|
||||
public Optional<Sticker[]> Stickers { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
25
src/Discord.Net.Rest/API/Common/Sticker.cs
Normal file
25
src/Discord.Net.Rest/API/Common/Sticker.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Sticker
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("pack_id")]
|
||||
public ulong PackId { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("description")]
|
||||
public string Desription { get; set; }
|
||||
[JsonProperty("tags")]
|
||||
public Optional<string> Tags { get; set; }
|
||||
[JsonProperty("asset")]
|
||||
public string Asset { get; set; }
|
||||
[JsonProperty("preview_asset")]
|
||||
public string PreviewAsset { get; set; }
|
||||
[JsonProperty("format_type")]
|
||||
public StickerFormatType FormatType { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,8 @@ namespace Discord.Rest
|
||||
public virtual IReadOnlyCollection<RestUser> MentionedUsers => ImmutableArray.Create<RestUser>();
|
||||
/// <inheritdoc />
|
||||
public virtual IReadOnlyCollection<ITag> Tags => ImmutableArray.Create<ITag>();
|
||||
/// <inheritdoc />
|
||||
public virtual IReadOnlyCollection<Sticker> Stickers => ImmutableArray.Create<Sticker>();
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset Timestamp => DateTimeUtils.FromTicks(_timestampTicks);
|
||||
@@ -173,6 +175,8 @@ namespace Discord.Rest
|
||||
IReadOnlyCollection<IEmbed> IMessage.Embeds => Embeds;
|
||||
/// <inheritdoc />
|
||||
IReadOnlyCollection<ulong> IMessage.MentionedUserIds => MentionedUsers.Select(x => x.Id).ToImmutableArray();
|
||||
/// <inheritdoc />
|
||||
IReadOnlyCollection<ISticker> IMessage.Stickers => Stickers;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyDictionary<IEmote, ReactionMetadata> Reactions => _reactions.ToDictionary(x => x.Emote, x => new ReactionMetadata { ReactionCount = x.Count, IsMe = x.Me });
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace Discord.Rest
|
||||
private ImmutableArray<ITag> _tags = ImmutableArray.Create<ITag>();
|
||||
private ImmutableArray<ulong> _roleMentionIds = ImmutableArray.Create<ulong>();
|
||||
private ImmutableArray<RestUser> _userMentions = ImmutableArray.Create<RestUser>();
|
||||
private ImmutableArray<Sticker> _stickers = ImmutableArray.Create<Sticker>();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsTTS => _isTTS;
|
||||
@@ -45,6 +46,8 @@ namespace Discord.Rest
|
||||
/// <inheritdoc />
|
||||
public override IReadOnlyCollection<ITag> Tags => _tags;
|
||||
/// <inheritdoc />
|
||||
public override IReadOnlyCollection<Sticker> Stickers => _stickers;
|
||||
/// <inheritdoc />
|
||||
public IUserMessage ReferencedMessage => _referencedMessage;
|
||||
|
||||
internal RestUserMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, IUser author, MessageSource source)
|
||||
@@ -132,6 +135,20 @@ namespace Discord.Rest
|
||||
IUser refMsgAuthor = MessageHelper.GetAuthor(Discord, guild, refMsg.Author.Value, refMsg.WebhookId.ToNullable());
|
||||
_referencedMessage = RestUserMessage.Create(Discord, Channel, refMsgAuthor, refMsg);
|
||||
}
|
||||
|
||||
if (model.Stickers.IsSpecified)
|
||||
{
|
||||
var value = model.Stickers.Value;
|
||||
if (value.Length > 0)
|
||||
{
|
||||
var stickers = ImmutableArray.CreateBuilder<Sticker>(value.Length);
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
stickers.Add(Sticker.Create(value[i]));
|
||||
_stickers = stickers.ToImmutable();
|
||||
}
|
||||
else
|
||||
_stickers = ImmutableArray.Create<Sticker>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
48
src/Discord.Net.Rest/Entities/Messages/Sticker.cs
Normal file
48
src/Discord.Net.Rest/Entities/Messages/Sticker.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Model = Discord.API.Sticker;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
/// <inheritdoc cref="ISticker"/>
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class Sticker : ISticker
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public ulong Id { get; }
|
||||
/// <inheritdoc />
|
||||
public ulong PackId { get; }
|
||||
/// <inheritdoc />
|
||||
public string Name { get; }
|
||||
/// <inheritdoc />
|
||||
public string Description { get; }
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<string> Tags { get; }
|
||||
/// <inheritdoc />
|
||||
public string Asset { get; }
|
||||
/// <inheritdoc />
|
||||
public string PreviewAsset { get; }
|
||||
/// <inheritdoc />
|
||||
public StickerFormatType FormatType { get; }
|
||||
|
||||
internal Sticker(ulong id, ulong packId, string name, string description, string[] tags, string asset, string previewAsset, StickerFormatType formatType)
|
||||
{
|
||||
Id = id;
|
||||
PackId = packId;
|
||||
Name = name;
|
||||
Description = description;
|
||||
Tags = tags.ToReadOnlyCollection();
|
||||
Asset = asset;
|
||||
PreviewAsset = previewAsset;
|
||||
FormatType = formatType;
|
||||
}
|
||||
internal static Sticker Create(Model model)
|
||||
{
|
||||
return new Sticker(model.Id, model.PackId, model.Name, model.Desription,
|
||||
model.Tags.IsSpecified ? model.Tags.Value.Split(',') : new string[0],
|
||||
model.Asset, model.PreviewAsset, model.FormatType);
|
||||
}
|
||||
|
||||
private string DebuggerDisplay => $"{Name} ({Id})";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user