Browse Source

Add single embed message property back for backwards compatibility

pull/1923/head
quin lynch 3 years ago
parent
commit
8dce6a6e1f
2 changed files with 35 additions and 2 deletions
  1. +8
    -0
      src/Discord.Net.Core/Entities/Messages/MessageProperties.cs
  2. +27
    -2
      src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs

+ 8
- 0
src/Discord.Net.Core/Entities/Messages/MessageProperties.cs View File

@@ -18,6 +18,14 @@ namespace Discord
/// </remarks> /// </remarks>
public Optional<string> Content { get; set; } public Optional<string> Content { get; set; }


/// <summary>
/// Gets or sets a single embed for this message.
/// </summary>
/// <remarks>
/// This property will be added to the <see cref="Embed"/> array, in the future please use the array rather then this property.
/// </remarks>
public Optional<Embed> Embed { get; set; }

/// <summary> /// <summary>
/// Gets or sets the embeds of the message. /// Gets or sets the embeds of the message.
/// </summary> /// </summary>


+ 27
- 2
src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs View File

@@ -61,10 +61,22 @@ namespace Discord.Rest
} }
} }


var embeds = new List<API.Embed>();

if (args.Embed.IsSpecified)
{
embeds.Add(args.Embed.Value.ToModel());
}

if (args.Embeds.IsSpecified)
{
embeds.AddRange(args.Embeds.Value.Select(x => x.ToModel()));
}

var apiArgs = new ModifyMessageParams var apiArgs = new ModifyMessageParams
{ {
Content = args.Content, Content = args.Content,
Embeds = args.Embeds.IsSpecified ? args.Embeds.Value.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified,
Embeds = embeds.ToArray(),
Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified, Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified,
Flags = args.Flags, Flags = args.Flags,
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional<API.AllowedMentions>.Unspecified, AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional<API.AllowedMentions>.Unspecified,
@@ -105,12 +117,25 @@ namespace Discord.Rest
} }
} }


var embeds = new List<API.Embed>();

if (args.Embed.IsSpecified)
{
embeds.Add(args.Embed.Value.ToModel());
}

if (args.Embeds.IsSpecified)
{
embeds.AddRange(args.Embeds.Value.Select(x => x.ToModel()));
}

var apiArgs = new API.Rest.ModifyMessageParams var apiArgs = new API.Rest.ModifyMessageParams
{ {
Content = args.Content, Content = args.Content,
Embeds = args.Embeds.IsSpecified ? args.Embeds.Value.Select(x => x.ToModel()).ToArray() : Optional.Create<API.Embed[]>(),
Embeds = embeds.ToArray(),
Flags = args.Flags.IsSpecified ? args.Flags.Value : Optional.Create<MessageFlags?>(), Flags = args.Flags.IsSpecified ? args.Flags.Value : Optional.Create<MessageFlags?>(),
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Create<API.AllowedMentions>(), AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Create<API.AllowedMentions>(),
Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified,
}; };
return await client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options).ConfigureAwait(false); return await client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options).ConfigureAwait(false);
} }


Loading…
Cancel
Save