|
7 | 7 | import net.discordjug.javabot.systems.staff_commands.forms.dao.FormsRepository; |
8 | 8 | import net.discordjug.javabot.systems.staff_commands.forms.model.FormData; |
9 | 9 | import net.discordjug.javabot.systems.staff_commands.forms.model.FormField; |
| 10 | +import net.discordjug.javabot.util.Responses; |
10 | 11 | import net.dv8tion.jda.api.components.textinput.TextInputStyle; |
11 | 12 | import net.dv8tion.jda.api.entities.Message; |
12 | 13 | import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; |
|
17 | 18 | import net.dv8tion.jda.api.interactions.commands.OptionType; |
18 | 19 | import net.dv8tion.jda.api.interactions.commands.build.OptionData; |
19 | 20 | import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; |
| 21 | +import net.dv8tion.jda.api.modals.Modal; |
20 | 22 | import xyz.dynxsty.dih4jda.interactions.AutoCompletable; |
21 | 23 |
|
22 | 24 | /** |
23 | 25 | * The `/form add-field` command. This command allows for modification of |
24 | 26 | * {@link FormData} by adding new fields to it. See |
25 | 27 | * {@link RemoveFieldFormSubcommand} for the command used to remove fields from |
26 | 28 | * a form.<br> |
27 | | - * Currently, due to Discord limitations, only 5 fields are allowed per form. |
| 29 | + * Currently, due to Discord limitations, only {@link Modal#MAX_COMPONENTS} fields are allowed per form. |
28 | 30 | * Trying to add more fields will have no effect. |
29 | 31 | * |
30 | 32 | * @see FormData |
@@ -57,32 +59,29 @@ public AddFieldFormSubcommand(FormsRepository formsRepo, BotConfig botConfig) { |
57 | 59 | .addOption(OptionType.STRING, FORM_PLACEHOLDER_FIELD, "Field placeholder") |
58 | 60 | .addOption(OptionType.BOOLEAN, FORM_REQUIRED_FIELD, |
59 | 61 | "Whether or not the user has to input data in this field. Default: false") |
60 | | - .addOptions( |
61 | | - new OptionData(OptionType.STRING, FORM_STYLE_FIELD, "Input style. Default: SHORT", false) |
62 | | - .addChoices( |
63 | | - Arrays.stream(TextInputStyle.values()).filter(t -> t != TextInputStyle.UNKNOWN) |
64 | | - .map(style -> new Choice(style.name(), style.name())).toList())) |
| 62 | + .addOptions(new OptionData(OptionType.STRING, FORM_STYLE_FIELD, "Input style. Default: SHORT", false) |
| 63 | + .addChoices(Arrays.stream(TextInputStyle.values()).filter(t -> t != TextInputStyle.UNKNOWN) |
| 64 | + .map(style -> new Choice(style.name(), style.name())).toList())) |
65 | 65 | .addOption(OptionType.STRING, FORM_VALUE_FIELD, "Initial field value")); |
66 | 66 | } |
67 | 67 |
|
68 | 68 | @Override |
69 | 69 | public void execute(SlashCommandInteractionEvent event) { |
70 | 70 | if (!checkForStaffRole(event)) return; |
71 | | - event.deferReply(true).queue(); |
72 | 71 | Optional<FormData> formOpt = formsRepo.getForm(event.getOption(FORM_ID_FIELD, OptionMapping::getAsLong)); |
73 | 72 | if (formOpt.isEmpty()) { |
74 | | - event.getHook().sendMessage("A form with this ID was not found.").queue(); |
| 73 | + Responses.error(event, "A form with this ID was not found.").queue(); |
75 | 74 | return; |
76 | 75 | } |
77 | 76 | FormData form = formOpt.get(); |
78 | 77 |
|
79 | 78 | if (form.fields().size() >= Message.MAX_COMPONENT_COUNT) { |
80 | | - event.getHook().sendMessage("Can't add more than 5 components to a form").queue(); |
| 79 | + Responses.error(event, "Can't add more than %s components to a form", Message.MAX_COMPONENT_COUNT).queue(); |
81 | 80 | return; |
82 | 81 | } |
83 | 82 |
|
84 | 83 | formsRepo.addField(form, createFormFieldFromEvent(event)); |
85 | | - event.getHook().sendMessage("Added a new field to the form.").queue(); |
| 84 | + event.reply("Added a new field to the form.").setEphemeral(true).queue(); |
86 | 85 | } |
87 | 86 |
|
88 | 87 | @Override |
|
0 commit comments