-
-
Notifications
You must be signed in to change notification settings - Fork 104
Modal component added for modmail #715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cd8fad2
9c38021
c69a1ba
38fb874
880b125
207473b
3167619
01670b9
db69693
6c4aa90
e6d05d4
5ab11d6
c06ebbf
c1ca87d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "recommendations": [ | ||
| "vscjava.vscode-gradle", | ||
| "github.vscode-pull-request-github", | ||
| "vscjava.vscode-java-pack", | ||
| "alexcvzz.vscode-sqlite" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| //Configure the JDK to Java 18 in settings | ||
| "java.compile.nullAnalysis.mode": "disabled", | ||
| "java.format.settings.url": "meta/formatting/google-style-eclipse.xml", | ||
| "editor.formatOnSave": true, | ||
| "editor.formatOnPaste": true, | ||
| "java.format.enabled": true, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,11 +8,16 @@ | |
| import net.dv8tion.jda.api.entities.Role; | ||
| import net.dv8tion.jda.api.entities.User; | ||
| import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; | ||
| import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; | ||
| import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
| import net.dv8tion.jda.api.interactions.InteractionHook; | ||
| import net.dv8tion.jda.api.interactions.commands.Command; | ||
| import net.dv8tion.jda.api.interactions.commands.OptionType; | ||
| import net.dv8tion.jda.api.interactions.commands.build.OptionData; | ||
| import net.dv8tion.jda.api.interactions.components.ActionRow; | ||
| import net.dv8tion.jda.api.interactions.components.Modal; | ||
| import net.dv8tion.jda.api.interactions.components.text.TextInput; | ||
| import net.dv8tion.jda.api.interactions.components.text.TextInputStyle; | ||
| import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.slf4j.Logger; | ||
|
|
@@ -43,7 +48,7 @@ public final class ModMailCommand extends SlashCommandAdapter { | |
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(ModMailCommand.class); | ||
| public static final String COMMAND_NAME = "modmail"; | ||
| private static final String OPTION_MESSAGE = "message"; | ||
| private static final String MESSAGE = "message"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it has to be clear what this field is and where its used. the current name doesnt tell. |
||
| private static final String OPTION_STAY_ANONYMOUS = "stay-anonymous"; | ||
| private static final String OPTION_GUILD = "server"; | ||
| private static final int COOLDOWN_DURATION_VALUE = 30; | ||
|
|
@@ -65,8 +70,6 @@ public ModMailCommand(JDA jda, Config config) { | |
| super(COMMAND_NAME, "Contact the moderators of the selected guild", | ||
| CommandVisibility.GLOBAL); | ||
|
|
||
| OptionData messageOption = new OptionData(OptionType.STRING, OPTION_MESSAGE, | ||
| "What do you want to tell them?", true); | ||
| OptionData guildOption = new OptionData(OptionType.STRING, OPTION_GUILD, | ||
| "The server to contact mods from", true); | ||
| OptionData anonymousOption = new OptionData(OptionType.BOOLEAN, OPTION_STAY_ANONYMOUS, | ||
|
|
@@ -79,7 +82,7 @@ public ModMailCommand(JDA jda, Config config) { | |
|
|
||
| guildOption.addChoices(choices); | ||
|
|
||
| getData().addOptions(messageOption, guildOption, anonymousOption); | ||
| getData().addOptions(guildOption, anonymousOption); | ||
|
|
||
| modMailChannelNamePredicate = | ||
| Pattern.compile(config.getModMailChannelPattern()).asMatchPredicate(); | ||
|
|
@@ -104,10 +107,34 @@ public void onSlashCommand(SlashCommandInteractionEvent event) { | |
| if (handleIsOnCooldown(userId, event)) { | ||
| return; | ||
| } | ||
|
|
||
| TextInput body = TextInput.create(MESSAGE, "Message", TextInputStyle.PARAGRAPH) | ||
| .setPlaceholder("What do you want to tell them?") | ||
| .setMinLength(5) | ||
| .setMaxLength(1000) | ||
| .build(); | ||
|
|
||
| boolean stayAnonymous = event.getOption(OPTION_STAY_ANONYMOUS).getAsBoolean(); | ||
| long guildToContact = event.getOption(OPTION_GUILD).getAsLong(); | ||
|
|
||
| String componentId = | ||
| generateComponentId(String.valueOf(stayAnonymous), String.valueOf(guildToContact)); | ||
| Modal modal = Modal.create(componentId, "Send this to the moderators") | ||
| .addActionRows(ActionRow.of(body)) | ||
| .build(); | ||
|
|
||
| event.replyModal(modal).queue(); | ||
|
|
||
| authorToLastModMailInvocation.put(userId, Instant.now()); | ||
| } | ||
|
|
||
| @Override | ||
| public void onModalSubmitted(ModalInteractionEvent event, List<String> args) { | ||
| long userId = event.getUser().getIdLong(); | ||
|
|
||
| event.deferReply().setEphemeral(true).queue(); | ||
|
|
||
| long userGuildId = event.getOption(OPTION_GUILD).getAsLong(); | ||
| long userGuildId = event.getJDA().getGuildById(args.get(1)).getIdLong(); | ||
| Optional<TextChannel> modMailAuditLog = getModMailChannel(event.getJDA(), userGuildId); | ||
| if (modMailAuditLog.isEmpty()) { | ||
| logger.warn( | ||
|
|
@@ -116,11 +143,10 @@ public void onSlashCommand(SlashCommandInteractionEvent event) { | |
| return; | ||
| } | ||
|
|
||
| MessageCreateAction message = | ||
| createModMessage(event, userId, modMailAuditLog.orElseThrow()); | ||
| MessageCreateAction message = createModMessage(event, Boolean.parseBoolean(args.get(0)), | ||
| userId, modMailAuditLog.orElseThrow()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code is easier to read if you extract the args seperated and at the beginning: boolean stayAnonymous = Boolean.parseBoolean(args.get(0));
long guildToContact = Long.parseLong(args.get(1));
... |
||
|
|
||
| sendMessage(event, message); | ||
|
|
||
| } | ||
|
|
||
| private boolean handleIsOnCooldown(long userId, SlashCommandInteractionEvent event) { | ||
|
|
@@ -141,10 +167,9 @@ private Optional<TextChannel> getModMailChannel(JDA jda, long guildId) { | |
| .findAny(); | ||
| } | ||
|
|
||
| private MessageCreateAction createModMessage(SlashCommandInteractionEvent event, long userId, | ||
| TextChannel modMailAuditLog) { | ||
| String userMessage = event.getOption(OPTION_MESSAGE).getAsString(); | ||
| boolean wantsToStayAnonymous = event.getOption(OPTION_STAY_ANONYMOUS).getAsBoolean(); | ||
| private MessageCreateAction createModMessage(ModalInteractionEvent event, | ||
| boolean wantsToStayAnonymous, long userId, TextChannel modMailAuditLog) { | ||
| String userMessage = event.getValue(MESSAGE).getAsString(); | ||
|
|
||
| User user = wantsToStayAnonymous ? null : event.getUser(); | ||
| MessageCreateAction message = | ||
|
|
@@ -165,7 +190,7 @@ private MessageCreateAction createModMessage(SlashCommandInteractionEvent event, | |
| return message; | ||
| } | ||
|
|
||
| private void sendMessage(SlashCommandInteractionEvent event, MessageCreateAction message) { | ||
| private void sendMessage(ModalInteractionEvent event, MessageCreateAction message) { | ||
| InteractionHook hook = event.getHook(); | ||
| message.mapToResult().map(result -> { | ||
| if (result.isSuccess()) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.