diff --git a/DisCatSharp/Entities/Interaction/DiscordInteractionModalBuilder.cs b/DisCatSharp/Entities/Interaction/DiscordInteractionModalBuilder.cs
index bc9b876b0..2c2b0d9da 100644
--- a/DisCatSharp/Entities/Interaction/DiscordInteractionModalBuilder.cs
+++ b/DisCatSharp/Entities/Interaction/DiscordInteractionModalBuilder.cs
@@ -1,156 +1,156 @@
// This file is part of the DisCatSharp project.
//
// Copyright (c) 2021 AITSYS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
namespace DisCatSharp.Entities
{
///
/// Constructs an interaction modal response.
///
public sealed class DiscordInteractionModalBuilder
{
///
/// Title of modal.
///
public string Title
{
get => this._title;
set
{
if (value != null && value.Length > 128)
throw new ArgumentException("Title length cannot exceed 128 characters.", nameof(value));
this._title = value;
}
}
private string _title;
///
/// Custom id of modal.
///
public string CustomId { get; set; }
///
/// Components to send on this interaction response.
///
public IReadOnlyList ModalComponents => this._components;
private readonly List _components = new();
///
/// Constructs a new empty interaction modal builder.
///
public DiscordInteractionModalBuilder() { }
public DiscordInteractionModalBuilder WithTitle(string title)
{
this.Title = title;
return this;
}
public DiscordInteractionModalBuilder WithCustomId(string customId)
{
this.CustomId = customId;
return this;
}
///
/// Appends a collection of components to the builder. Each call will append to a new row.
///
/// The components to append. Up to five.
/// The current builder to chain calls with.
/// Thrown when passing more than 5 components.
public DiscordInteractionModalBuilder AddModalComponents(params DiscordComponent[] components)
=> this.AddModalComponents((IEnumerable)components);
///
/// Appends a text component to the builder.
///
/// The component to append.
/// The current builder to chain calls with.
public DiscordInteractionModalBuilder AddTextComponent(DiscordTextComponent component)
{
List comp = new(1);
comp.Add(component);
return this.AddModalComponents(comp);
}
///
/// Appends several rows of components to the message
///
/// The rows of components to add, holding up to five each.
///
public DiscordInteractionModalBuilder AddModalComponents(IEnumerable components)
{
var ara = components.ToArray();
if (ara.Length + this._components.Count > 5)
throw new ArgumentException("ActionRow count exceeds maximum of five.");
foreach (var ar in ara)
this._components.Add(ar);
return this;
}
///
/// Appends a collection of components to the builder. Each call will append to a new row.
/// If you add a you can only add one.
///
/// The components to append. Up to five.
/// The current builder to chain calls with.
/// Thrown when passing more than 5 components.
public DiscordInteractionModalBuilder AddModalComponents(IEnumerable components)
{
var compArr = components.ToArray();
var count = compArr.Length;
if (count > 5)
throw new ArgumentException("Cannot add more than 5 components per action row!");
- if (components.Where(c => c.Type == Enums.ComponentType.InputText).Any())
+ if (components.Where(c => c.Type == Enums.ComponentType.InputText).Any() && count < 1)
throw new ArgumentException("Cannot add more than 1 text components per action row!");
var arc = new DiscordActionRowComponent(compArr);
this._components.Add(arc);
return this;
}
///
/// Clears all message components on this builder.
///
public void ClearComponents()
=> this._components.Clear();
///
/// Allows for clearing the Interaction Response Builder so that it can be used again to send a new response.
///
public void Clear()
{
this._components.Clear();
this.Title = null;
this.CustomId = null;
}
}
}