feature: Implemented Message Reference Property (#1413)
* Added support for Message References * Removed unused usings, added debugger display, updated ToString override * Changed snowflakes to be wrapped in an optional instead of a nullable.
This commit is contained in:
@@ -140,6 +140,18 @@ namespace Discord
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
MessageApplication Application { get; }
|
MessageApplication Application { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the reference to the original message if it was crossposted.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Sent with Cross-posted messages, meaning they were published from news channels
|
||||||
|
/// and received by subscriber channels.
|
||||||
|
/// </remarks>
|
||||||
|
/// <returns>
|
||||||
|
/// A message's reference, if any is associated.
|
||||||
|
/// </returns>
|
||||||
|
MessageReference Reference { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all reactions included in this message.
|
/// Gets all reactions included in this message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
33
src/Discord.Net.Core/Entities/Messages/MessageReference.cs
Normal file
33
src/Discord.Net.Core/Entities/Messages/MessageReference.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Discord
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains the IDs sent from a crossposted message.
|
||||||
|
/// </summary>
|
||||||
|
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||||
|
public class MessageReference
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Message ID of the original message.
|
||||||
|
/// </summary>
|
||||||
|
public Optional<ulong> MessageId { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Channel ID of the original message.
|
||||||
|
/// </summary>
|
||||||
|
public ulong ChannelId { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Guild ID of the original message.
|
||||||
|
/// </summary>
|
||||||
|
public Optional<ulong> GuildId { get; internal set; }
|
||||||
|
|
||||||
|
private string DebuggerDisplay
|
||||||
|
=> $"Channel ID: ({ChannelId}){(GuildId.IsSpecified ? $", Guild ID: ({GuildId.Value})" : "")}" +
|
||||||
|
$"{(MessageId.IsSpecified ? $", Message ID: ({MessageId.Value})" : "")}";
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
=> DebuggerDisplay;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,6 +50,8 @@ namespace Discord.API
|
|||||||
// sent with Rich Presence-related chat embeds
|
// sent with Rich Presence-related chat embeds
|
||||||
[JsonProperty("application")]
|
[JsonProperty("application")]
|
||||||
public Optional<MessageApplication> Application { get; set; }
|
public Optional<MessageApplication> Application { get; set; }
|
||||||
|
[JsonProperty("message_reference")]
|
||||||
|
public Optional<MessageReference> Reference { get; set; }
|
||||||
[JsonProperty("flags")]
|
[JsonProperty("flags")]
|
||||||
public Optional<MessageFlags> Flags { get; set; }
|
public Optional<MessageFlags> Flags { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/Discord.Net.Rest/API/Common/MessageReference.cs
Normal file
16
src/Discord.Net.Rest/API/Common/MessageReference.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Discord.API
|
||||||
|
{
|
||||||
|
internal class MessageReference
|
||||||
|
{
|
||||||
|
[JsonProperty("message_id")]
|
||||||
|
public Optional<ulong> MessageId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("channel_id")]
|
||||||
|
public ulong ChannelId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("guild_id")]
|
||||||
|
public Optional<ulong> GuildId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,6 +62,8 @@ namespace Discord.Rest
|
|||||||
public MessageActivity Activity { get; private set; }
|
public MessageActivity Activity { get; private set; }
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MessageApplication Application { get; private set; }
|
public MessageApplication Application { get; private set; }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public MessageReference Reference { get; private set; }
|
||||||
|
|
||||||
internal RestMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, IUser author, MessageSource source)
|
internal RestMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, IUser author, MessageSource source)
|
||||||
: base(discord, id)
|
: base(discord, id)
|
||||||
@@ -108,6 +110,17 @@ namespace Discord.Rest
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(model.Reference.IsSpecified)
|
||||||
|
{
|
||||||
|
// Creates a new Reference from the API model
|
||||||
|
Reference = new MessageReference
|
||||||
|
{
|
||||||
|
GuildId = model.Reference.Value.GuildId,
|
||||||
|
ChannelId = model.Reference.Value.ChannelId,
|
||||||
|
MessageId = model.Reference.Value.MessageId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (model.Reactions.IsSpecified)
|
if (model.Reactions.IsSpecified)
|
||||||
{
|
{
|
||||||
var value = model.Reactions.Value;
|
var value = model.Reactions.Value;
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ namespace Discord.WebSocket
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MessageApplication Application { get; private set; }
|
public MessageApplication Application { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public MessageReference Reference { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns all attachments included in this message.
|
/// Returns all attachments included in this message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -140,6 +143,17 @@ namespace Discord.WebSocket
|
|||||||
PartyId = model.Activity.Value.PartyId.Value
|
PartyId = model.Activity.Value.PartyId.Value
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (model.Reference.IsSpecified)
|
||||||
|
{
|
||||||
|
// Creates a new Reference from the API model
|
||||||
|
Reference = new MessageReference
|
||||||
|
{
|
||||||
|
GuildId = model.Reference.Value.GuildId,
|
||||||
|
ChannelId = model.Reference.Value.ChannelId,
|
||||||
|
MessageId = model.Reference.Value.MessageId
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
Reference in New Issue
Block a user