/// <summary> /// Respond to an interaction with a <see cref="IModal"/>. /// </summary> /// <typeparam name="T">Type of the <see cref="IModal"/> implementation.</typeparam> /// <param name="interaction">The interaction to respond to.</param> /// <param name="modifyModal">Delegate that can be used to modify the modal.</param> /// <param name="options">The request options for this <see langword="async"/> request.</param> /// <returns>A task that represents the asynchronous operation of responding to the interaction.</returns> public static async Task RespondWithModalAsync <T>(this IDiscordInteraction interaction, string customId, RequestOptions options = null, Action <ModalBuilder> modifyModal = null) where T : class, IModal { if (!ModalUtils.TryGet <T>(out var modalInfo)) { throw new ArgumentException($"{typeof(T).FullName} isn't referenced by any registered Modal Interaction Command and doesn't have a cached {typeof(ModalInfo)}"); } var builder = new ModalBuilder(modalInfo.Title, customId); foreach (var input in modalInfo.Components) { switch (input) { case TextInputComponentInfo textComponent: builder.AddTextInput(textComponent.Label, textComponent.CustomId, textComponent.Style, textComponent.Placeholder, textComponent.IsRequired ? textComponent.MinLength : null, textComponent.MaxLength, textComponent.IsRequired, textComponent.InitialValue); break; default: throw new InvalidOperationException($"{input.GetType().FullName} isn't a valid component info class"); } } if (modifyModal is not null) { modifyModal(builder); } await interaction.RespondWithModalAsync(builder.Build(), options).ConfigureAwait(false); }
internal static string GetErrorModal(string errorMessage) { //create Slack modal ModalBuilder builder = new ModalBuilder("An error occured", submitButton: false, closeText: "Ok"); builder.AddBlock(new Section(new Text(errorMessage, "mrkdwn"))); return(builder.GetJObject().ToString()); }
public async Task Rant() { var mb = new ModalBuilder() .WithTitle("New rant") .WithCustomId("new-rant-modal") .AddTextInput("What is the rant about?", "rant-type", placeholder: "ETH", minLength: 3, maxLength: 40) .AddTextInput("Rant message", "rant-message", TextInputStyle.Paragraph, "Your rant message"); await Context.Interaction.RespondWithModalAsync(mb.Build()); }
public static string GetAddSkillModal() { //create Slack modal ModalBuilder builder = new ModalBuilder("Add Skill", "addSkill_view"); builder.AddBlock( new Input( new PlainTextInput("skill_name", "Skill name goes here") , "Skill name" , "Skill name to be filtered", "addSkill_block")); return(builder.GetJObject().ToString()); }
public static string GetQualificationModal(string message_ts, string hookUrl) { //create Slack modal ModalBuilder builder = new ModalBuilder("Qualify Lead", message_ts).AddPrivateMetadata(hookUrl); builder.AddBlock( new Input( new PlainTextInput("customer_name", "Customer name goes here") , "Customer name" , "Customer name as it will appear in Close", "customer_block")); return(builder.GetJObject().ToString()); }
public async Task ButtonPress(string id) { var emote = DatabaseManager.EmoteDatabaseManager.GetDiscordEmoteById(ulong.Parse(id)); var mb = new ModalBuilder() .WithTitle("Favourite Emote form") .WithCustomId($"emote-fav-modal-{emote.DiscordEmoteId}") //.AddComponents(new List<IMessageComponent>() { menuBuilder.Build() }, 0) .AddTextInput($"Name for {emote.EmoteName}", "custom-emote-name", placeholder: emote.EmoteName, required: true); Context.Interaction.RespondWithModalAsync(mb.Build()); Context.Interaction.DeferAsync(); }
public async Task DeleteFavEmote(string id) { Context.Interaction.DeferAsync(); var emote = DatabaseManager.EmoteDatabaseManager.GetDiscordEmoteById(ulong.Parse(id)); var mb = new ModalBuilder() .WithTitle("Delete favourite emote") .WithCustomId($"emote-fav-delete-modal-{emote.DiscordEmoteId}") //.AddComponents(new List<IMessageComponent>() { menuBuilder.Build() }, 0) .AddTextInput($"Confirm delete by typing \"DELETE\"", "custom-emote-name-delete", placeholder: "DELETE", required: true); Context.Interaction.RespondWithModalAsync(mb.Build()); }
/// <summary> /// Initializes a new <see cref="TextInputComponentBuilder"/>. /// </summary> /// <param name="modal">Parent modal of this component.</param> public TextInputComponentBuilder(ModalBuilder modal) : base(modal) { }