| @@ -45,6 +45,47 @@ namespace Discord | |||
| private List<ActionRowBuilder> _actionRows { get; set; } | |||
| /// <summary> | |||
| /// Creates a new builder from a message. | |||
| /// </summary> | |||
| /// <param name="message">The message to create the builder from.</param> | |||
| /// <returns>The newly created builder.</returns> | |||
| public static ComponentBuilder FromMessage(IMessage message) | |||
| => FromComponents(message.Components); | |||
| /// <summary> | |||
| /// Creates a new builder from the provided list of components. | |||
| /// </summary> | |||
| /// <param name="components">The components to create the builder from.</param> | |||
| /// <returns>The newly created builder.</returns> | |||
| public static ComponentBuilder FromComponents(IReadOnlyCollection<IMessageComponent> components) | |||
| { | |||
| var builder = new ComponentBuilder(); | |||
| for(int i = 0; i != components.Count; i++) | |||
| { | |||
| var component = components.ElementAt(i); | |||
| builder.AddComponent(component, i); | |||
| } | |||
| return builder; | |||
| } | |||
| internal void AddComponent(IMessageComponent component, int row) | |||
| { | |||
| switch (component) | |||
| { | |||
| case ButtonComponent button: | |||
| this.WithButton(button.Label, button.CustomId, button.Style, button.Emote, button.Url, button.Disabled, row); | |||
| break; | |||
| case ActionRowComponent actionRow: | |||
| foreach (var cmp in actionRow.Components) | |||
| AddComponent(cmp, row); | |||
| break; | |||
| case SelectMenu menu: | |||
| this.WithSelectMenu(menu.Placeholder, menu.CustomId, menu.Options.Select(x => new SelectMenuOptionBuilder(x.Label, x.Value, x.Description, x.Emote, x.Default)).ToList(), menu.Placeholder, menu.MinValues, menu.MaxValues, menu.Disabled, row); | |||
| break; | |||
| } | |||
| } | |||
| /// <summary> | |||
| /// Adds a <see cref="SelectMenuBuilder"/> to the <see cref="ComponentBuilder"/> at the specific row. | |||
| /// If the row cannot accept the component then it will add it to a row that can. | |||
| @@ -8,7 +8,7 @@ | |||
| <TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;netstandard2.0;netstandard2.1</TargetFrameworks> | |||
| <TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard2.0;netstandard2.1</TargetFrameworks> | |||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |||
| <Version>3.0.1</Version> | |||
| <Version>3.0.2</Version> | |||
| <RepositoryUrl>https://github.com/Discord-Net-Labs/Discord.Net-Labs</RepositoryUrl> | |||
| <PackageProjectUrl>https://github.com/Discord-Net-Labs/Discord.Net-Labs</PackageProjectUrl> | |||
| <PackageIcon>Temporary.png</PackageIcon> | |||
| @@ -16,8 +16,8 @@ | |||
| </PropertyGroup> | |||
| <PropertyGroup> | |||
| <DocumentationFile>..\Discord.Net.WebSocket\Discord.Net.WebSocket.xml</DocumentationFile> | |||
| <AssemblyVersion>3.0.1</AssemblyVersion> | |||
| <FileVersion>3.0.1</FileVersion> | |||
| <AssemblyVersion>3.0.2</AssemblyVersion> | |||
| <FileVersion>3.0.2</FileVersion> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | |||
| <DefineConstants>TRACE</DefineConstants> | |||
| @@ -2,7 +2,7 @@ | |||
| <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> | |||
| <metadata> | |||
| <id>Discord.Net.Labs</id> | |||
| <version>3.0.1$suffix$</version> | |||
| <version>3.0.2$suffix$</version> | |||
| <title>Discord.Net Labs</title> | |||
| <authors>Discord.Net Contributors</authors> | |||
| <owners>quinchs</owners> | |||
| @@ -16,21 +16,21 @@ | |||
| <group targetFramework="net461"> | |||
| <dependency id="Discord.Net.Labs.Core" version="3.0.0$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.Rest" version="3.0.1$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.WebSocket" version="3.0.1$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.WebSocket" version="3.0.2$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.Commands" version="3.0.0$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.Webhook" version="3.0.0$suffix$" /> | |||
| </group> | |||
| <group targetFramework="netstandard2.0"> | |||
| <dependency id="Discord.Net.Labs.Core" version="3.0.0$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.Rest" version="3.0.1$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.WebSocket" version="3.0.1$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.WebSocket" version="3.0.2$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.Commands" version="3.0.0$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.Webhook" version="3.0.0$suffix$" /> | |||
| </group> | |||
| <group targetFramework="netstandard2.1"> | |||
| <dependency id="Discord.Net.Labs.Core" version="3.0.0$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.Rest" version="3.0.1$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.WebSocket" version="3.0.1$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.WebSocket" version="3.0.2$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.Commands" version="3.0.0$suffix$" /> | |||
| <dependency id="Discord.Net.Labs.Webhook" version="3.0.0$suffix$" /> | |||
| </group> | |||