Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,39 @@ internal void AddComponent(IMessageComponent component, int row)
}
}

/// <summary>
/// Removes all components of the given type from the <see cref="ComponentBuilder"/>.
/// </summary>
/// <param name="t">The <see cref="ComponentType"/> to remove.</param>
/// <returns>The current builder.</returns>
public ComponentBuilder RemoveComponentsOfType(ComponentType t)
{
this.ActionRows.ForEach(ar => ar.Components.RemoveAll(c => c.Type == t));
return this;
}

/// <summary>
/// Removes a component from the <see cref="ComponentBuilder"/>.
/// </summary>
/// <param name="customId">The custom id of the component.</param>
/// <returns>The current builder.</returns>
public ComponentBuilder RemoveComponent(string customId)
{
this.ActionRows.ForEach(ar => ar.Components.RemoveAll(c => c.CustomId == customId));
return this;
}

/// <summary>
/// Removes a Link Button from the <see cref="ComponentBuilder"/> based on its URL.
/// </summary>
/// <param name="url">The URL of the Link Button.</param>
/// <returns>The current builder.</returns>
public ComponentBuilder RemoveButtonByURL(string url)
{
this.ActionRows.ForEach(ar => ar.Components.RemoveAll(c => c is ButtonComponent b && b.Url == url));
return this;
}

/// <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.
Expand Down Expand Up @@ -283,6 +316,11 @@ public MessageComponent Build()
if (_actionRows?.SelectMany(x => x.Components)?.Any(x => x.Type == ComponentType.TextInput) ?? false)
throw new ArgumentException("TextInputComponents are not allowed in messages.", nameof(ActionRows));

if (_actionRows?.Count > 0)
for (int i = 0; i < _actionRows?.Count; i++)
if (_actionRows[i]?.Components?.Count == 0)
_actionRows.RemoveAt(i);

return _actionRows != null
? new MessageComponent(_actionRows.Select(x => x.Build()).ToList())
: MessageComponent.Empty;
Expand Down