feature: Support FailIfNotExists on MessageReference (#2283)
Fixes #2282
This commit is contained in:
@@ -27,6 +27,12 @@ namespace Discord
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Optional<ulong> GuildId { get; internal set; }
|
public Optional<ulong> GuildId { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether to error if the referenced message doesn't exist instead of sending as a normal (non-reply) message
|
||||||
|
/// Defaults to true.
|
||||||
|
/// </summary>
|
||||||
|
public Optional<bool> FailIfNotExists { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="MessageReference"/> class.
|
/// Initializes a new instance of the <see cref="MessageReference"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -39,16 +45,21 @@ namespace Discord
|
|||||||
/// <param name="guildId">
|
/// <param name="guildId">
|
||||||
/// The ID of the guild that will be referenced. It will be validated if sent.
|
/// The ID of the guild that will be referenced. It will be validated if sent.
|
||||||
/// </param>
|
/// </param>
|
||||||
public MessageReference(ulong? messageId = null, ulong? channelId = null, ulong? guildId = null)
|
/// <param name="failIfNotExists">
|
||||||
|
/// Whether to error if the referenced message doesn't exist instead of sending as a normal (non-reply) message. Defaults to true.
|
||||||
|
/// </param>
|
||||||
|
public MessageReference(ulong? messageId = null, ulong? channelId = null, ulong? guildId = null, bool? failIfNotExists = null)
|
||||||
{
|
{
|
||||||
MessageId = messageId ?? Optional.Create<ulong>();
|
MessageId = messageId ?? Optional.Create<ulong>();
|
||||||
InternalChannelId = channelId ?? Optional.Create<ulong>();
|
InternalChannelId = channelId ?? Optional.Create<ulong>();
|
||||||
GuildId = guildId ?? Optional.Create<ulong>();
|
GuildId = guildId ?? Optional.Create<ulong>();
|
||||||
|
FailIfNotExists = failIfNotExists ?? Optional.Create<bool>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string DebuggerDisplay
|
private string DebuggerDisplay
|
||||||
=> $"Channel ID: ({ChannelId}){(GuildId.IsSpecified ? $", Guild ID: ({GuildId.Value})" : "")}" +
|
=> $"Channel ID: ({ChannelId}){(GuildId.IsSpecified ? $", Guild ID: ({GuildId.Value})" : "")}" +
|
||||||
$"{(MessageId.IsSpecified ? $", Message ID: ({MessageId.Value})" : "")}";
|
$"{(MessageId.IsSpecified ? $", Message ID: ({MessageId.Value})" : "")}" +
|
||||||
|
$"{(FailIfNotExists.IsSpecified ? $", FailIfNotExists: ({FailIfNotExists.Value})" : "")}";
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
=> DebuggerDisplay;
|
=> DebuggerDisplay;
|
||||||
|
|||||||
@@ -12,5 +12,8 @@ namespace Discord.API
|
|||||||
|
|
||||||
[JsonProperty("guild_id")]
|
[JsonProperty("guild_id")]
|
||||||
public Optional<ulong> GuildId { get; set; }
|
public Optional<ulong> GuildId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("fail_if_not_exists")]
|
||||||
|
public Optional<bool> FailIfNotExists { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,8 @@ namespace Discord.Rest
|
|||||||
{
|
{
|
||||||
GuildId = model.Reference.Value.GuildId,
|
GuildId = model.Reference.Value.GuildId,
|
||||||
InternalChannelId = model.Reference.Value.ChannelId,
|
InternalChannelId = model.Reference.Value.ChannelId,
|
||||||
MessageId = model.Reference.Value.MessageId
|
MessageId = model.Reference.Value.MessageId,
|
||||||
|
FailIfNotExists = model.Reference.Value.FailIfNotExists
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ namespace Discord.Rest
|
|||||||
ChannelId = entity.InternalChannelId,
|
ChannelId = entity.InternalChannelId,
|
||||||
GuildId = entity.GuildId,
|
GuildId = entity.GuildId,
|
||||||
MessageId = entity.MessageId,
|
MessageId = entity.MessageId,
|
||||||
|
FailIfNotExists = entity.FailIfNotExists
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static IEnumerable<string> EnumerateMentionTypes(this AllowedMentionTypes mentionTypes)
|
public static IEnumerable<string> EnumerateMentionTypes(this AllowedMentionTypes mentionTypes)
|
||||||
|
|||||||
@@ -182,7 +182,8 @@ namespace Discord.WebSocket
|
|||||||
{
|
{
|
||||||
GuildId = model.Reference.Value.GuildId,
|
GuildId = model.Reference.Value.GuildId,
|
||||||
InternalChannelId = model.Reference.Value.ChannelId,
|
InternalChannelId = model.Reference.Value.ChannelId,
|
||||||
MessageId = model.Reference.Value.MessageId
|
MessageId = model.Reference.Value.MessageId,
|
||||||
|
FailIfNotExists = model.Reference.Value.FailIfNotExists
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user