Skip to content
Draft
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/Discord.Net.Interactions/Attributes/HideAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Discord.Interactions;

/// <summary>
/// Enum values tagged with this attribute will not be displayed as a parameter choice
/// </summary>
/// <remarks>
/// This attribute must be used along with the default <see cref="EnumConverter{T}"/>
/// </remarks>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public sealed class HideAttribute : Attribute { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Discord.Interactions.Attributes.Modals;

public class ModalChannelSelectInputAttribute : SelectInputAttribute
{
public override ComponentType ComponentType => ComponentType.ChannelSelect;

public ModalChannelSelectInputAttribute(string customId) : base(customId)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Discord.Interactions.Attributes.Modals;

public class ModalMentionableSelectInputAttribute : SelectInputAttribute
{
public override ComponentType ComponentType => ComponentType.MentionableSelect;

public ModalMentionableSelectInputAttribute(string customId) : base(customId)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Discord.Interactions.Attributes.Modals;

public class ModalRoleSelectInputAttribute : SelectInputAttribute
{
public override ComponentType ComponentType => ComponentType.RoleSelect;

public ModalRoleSelectInputAttribute(string customId) : base(customId)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Discord.Interactions.Attributes.Modals;

public sealed class ModalSelectMenuInputAttribute : SelectInputAttribute
{
public override ComponentType ComponentType => ComponentType.SelectMenu;

public ModalSelectMenuInputAttribute(string customId) : base(customId)
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Discord.Interactions.Attributes.Modals;

public class ModalUserSelectInputAttribute : SelectInputAttribute
{
public override ComponentType ComponentType => ComponentType.UserSelect;

public ModalUserSelectInputAttribute(string customId) : base(customId)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Discord.Interactions.Attributes.Modals;

public abstract class SelectInputAttribute : ModalInputAttribute
{
public int MinValues { get; set; } = 1;

public int MaxValues { get; set; } = 1;

public string Placeholder { get; set; }

public SelectInputAttribute(string customId) : base(customId)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Discord.Interactions.Info.InputComponents;
using System.Collections.Generic;
using System.Linq;

namespace Discord.Interactions.Builders.Modals.Inputs;

public class ChannelSelectInputComponentBuilder : SnowflakeSelectInputComponentBuilder<ChannelSelectInputComponentInfo, ChannelSelectInputComponentBuilder>
{
protected override ChannelSelectInputComponentBuilder Instance => this;

public ChannelSelectInputComponentBuilder(ModalBuilder modal) : base(modal, ComponentType.ChannelSelect) { }

public ChannelSelectInputComponentBuilder AddDefaulValue(IChannel channel)
{
_defaultValues.Add(new SelectMenuDefaultValue(channel.Id, SelectDefaultValueType.Channel));
return this;
}

public ChannelSelectInputComponentBuilder AddDefaulValue(ulong channelId)
{
_defaultValues.Add(new SelectMenuDefaultValue(channelId, SelectDefaultValueType.Channel));
return this;
}

public ChannelSelectInputComponentBuilder AddDefaultValues(params IChannel[] channels)
{
_defaultValues.AddRange(channels.Select(x => new SelectMenuDefaultValue(x.Id, SelectDefaultValueType.Channel)));
return this;
}

public ChannelSelectInputComponentBuilder AddDefaultValues(IEnumerable<IChannel> channels)
{
_defaultValues.AddRange(channels.Select(x => new SelectMenuDefaultValue(x.Id, SelectDefaultValueType.Channel)));
return this;
}

internal override ChannelSelectInputComponentInfo Build(ModalInfo modal)
=> new(this, modal);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Discord.Interactions.TypeConverters.ModalInputs;
using System;
using System.Collections.Generic;
using System.Reflection;
Expand Down Expand Up @@ -45,12 +46,12 @@ public interface IInputComponentBuilder
PropertyInfo PropertyInfo { get; }

/// <summary>
/// Get the <see cref="ComponentTypeConverter"/> assigned to this input.
/// Get the <see cref="ModalComponentTypeConverter"/> assigned to this input.
/// </summary>
ComponentTypeConverter TypeConverter { get; }
ModalComponentTypeConverter TypeConverter { get; }

/// <summary>
/// Gets the default value of this input component.
/// Gets the default value of this input component property.
/// </summary>
object DefaultValue { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;

namespace Discord.Interactions.Builders.Modals.Inputs;

public interface ISnowflakeSelectInputComponentBuilder : IInputComponentBuilder
{
int MinValues { get; }

int MaxValues { get; }

string Placeholder { get; set; }

IReadOnlyCollection<SelectMenuDefaultValue> DefaultValues { get; }

SelectDefaultValueType? DefaultValuesType { get; }

ISnowflakeSelectInputComponentBuilder AddDefaultValue(SelectMenuDefaultValue defaultValue);

ISnowflakeSelectInputComponentBuilder WithMinValues(int minValues);

ISnowflakeSelectInputComponentBuilder WithMaxValues(int maxValues);

ISnowflakeSelectInputComponentBuilder WithPlaceholder(string placeholder);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Discord.Interactions.TypeConverters.ModalInputs;
using System;
using System.Collections.Generic;
using System.Reflection;
Expand Down Expand Up @@ -38,7 +39,7 @@ public abstract class InputComponentBuilder<TInfo, TBuilder> : IInputComponentBu
public PropertyInfo PropertyInfo { get; internal set; }

/// <inheritdoc/>
public ComponentTypeConverter TypeConverter { get; private set; }
public ModalComponentTypeConverter TypeConverter { get; private set; }

/// <inheritdoc/>
public object DefaultValue { get; set; }
Expand Down Expand Up @@ -102,7 +103,7 @@ public TBuilder SetIsRequired(bool isRequired)
/// <returns>
/// The builder instance.
/// </returns>
public TBuilder WithComponentType(ComponentType componentType)
public virtual TBuilder WithComponentType(ComponentType componentType)
{
ComponentType = componentType;
return Instance;
Expand All @@ -118,7 +119,7 @@ public TBuilder WithComponentType(ComponentType componentType)
public TBuilder WithType(Type type)
{
Type = type;
TypeConverter = Modal._interactionService.GetComponentTypeConverter(type);
TypeConverter = Modal._interactionService.GetModalInputTypeConverter(type);
return Instance;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Discord.Interactions.Info.InputComponents;

namespace Discord.Interactions.Builders.Modals.Inputs;

public class MentionableSelectInputComponentBuilder : SnowflakeSelectInputComponentBuilder<MentionableSelectInputComponentInfo, MentionableSelectInputComponentBuilder>
{
protected override MentionableSelectInputComponentBuilder Instance => this;

public MentionableSelectInputComponentBuilder(ModalBuilder modal) : base(modal, ComponentType.MentionableSelect) { }

public MentionableSelectInputComponentBuilder AddDefaultValue(ulong id, SelectDefaultValueType type)
{
_defaultValues.Add(new SelectMenuDefaultValue(id, type));
return this;
}

public MentionableSelectInputComponentBuilder AddDefaultValue(IUser user)
{
_defaultValues.Add(new SelectMenuDefaultValue(user.Id, SelectDefaultValueType.User));
return this;
}

public MentionableSelectInputComponentBuilder AddDefaultValue(IChannel channel)
{
_defaultValues.Add(new SelectMenuDefaultValue(channel.Id, SelectDefaultValueType.Channel));
return this;
}

public MentionableSelectInputComponentBuilder AddDefaulValue(IRole role)
{
_defaultValues.Add(new SelectMenuDefaultValue(role.Id, SelectDefaultValueType.Role));
return this;
}

internal override MentionableSelectInputComponentInfo Build(ModalInfo modal)
=> new(this, modal);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Discord.Interactions.Info.InputComponents;
using System.Collections.Generic;
using System.Linq;

namespace Discord.Interactions.Builders.Modals.Inputs;

public class RoleSelectInputComponentBuilder : SnowflakeSelectInputComponentBuilder<RoleSelectInputComponentInfo, RoleSelectInputComponentBuilder>
{
protected override RoleSelectInputComponentBuilder Instance => this;

public RoleSelectInputComponentBuilder(ModalBuilder modal) : base(modal, ComponentType.RoleSelect) { }

public RoleSelectInputComponentBuilder AddDefaulValue(IRole role)
{
_defaultValues.Add(new SelectMenuDefaultValue(role.Id, SelectDefaultValueType.Role));
return this;
}

public RoleSelectInputComponentBuilder AddDefaulValue(ulong roleId)
{
_defaultValues.Add(new SelectMenuDefaultValue(roleId, SelectDefaultValueType.Role));
return this;
}

public RoleSelectInputComponentBuilder AddDefaultValues(params IRole[] roles)
{
_defaultValues.AddRange(roles.Select(x => new SelectMenuDefaultValue(x.Id, SelectDefaultValueType.Role)));
return this;
}

public RoleSelectInputComponentBuilder AddDefaultValues(IEnumerable<IRole> roles)
{
_defaultValues.AddRange(roles.Select(x => new SelectMenuDefaultValue(x.Id, SelectDefaultValueType.Role)));
return this;
}

internal override RoleSelectInputComponentInfo Build(ModalInfo modal)
=> new(this, modal);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Discord.Interactions.Info.InputComponents;
using System;
using System.Collections.Generic;

namespace Discord.Interactions.Builders;

public class SelectMenuInputComponentBuilder : InputComponentBuilder<SelectMenuInputComponentInfo, SelectMenuInputComponentBuilder>
{
private readonly List<SelectMenuOptionBuilder> _options;

protected override SelectMenuInputComponentBuilder Instance => this;

public string Placeholder { get; set; }

public int MinValues { get; set; }

public int MaxValues { get; set; }

public IReadOnlyCollection<SelectMenuOptionBuilder> Options => _options;

public SelectMenuInputComponentBuilder(ModalBuilder modal) : base(modal)
{
_options = new();
}

public SelectMenuInputComponentBuilder AddOption(SelectMenuOptionBuilder option)
{
_options.Add(option);
return this;
}

public SelectMenuInputComponentBuilder AddOption(Action<SelectMenuOptionBuilder> configure)
{
var builder = new SelectMenuOptionBuilder();
configure(builder);
_options.Add(builder);
return this;
}

internal override SelectMenuInputComponentInfo Build(ModalInfo modal)
=> new(this, modal);
}
Loading
Loading