add respondwithmodal methods to restinteractinmodulebase (#2227)

This commit is contained in:
Cenk Ergen
2022-04-05 00:11:15 +03:00
committed by GitHub
parent c4131cfc8b
commit 1c680db2ba
3 changed files with 80 additions and 0 deletions

View File

@@ -196,5 +196,26 @@ namespace Discord.Interactions
}).ToList(),
Options = commandOption.Options?.Select(x => x.ToApplicationCommandOptionProps()).ToList()
};
public static Modal ToModal(this ModalInfo modalInfo, string customId, Action<ModalBuilder> modifyModal = null)
{
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);
return builder.Build();
}
}
}