From 787dbf260562631717cd0199129b914662a378b0 Mon Sep 17 00:00:00 2001 From: Nguyen Huynh Date: Thu, 4 Jan 2024 14:41:47 -0500 Subject: [PATCH] finished code for tag command. --- .idea/.gitignore | 8 ++ .idea/compiler.xml | 6 + .idea/gradle.xml | 19 +++ .idea/jarRepositories.xml | 20 +++ .idea/misc.xml | 8 ++ .idea/uiDesigner.xml | 124 ++++++++++++++++++ .idea/vcs.xml | 6 + .../org/hyperskill/community/hyper/App.java | 2 + .../hyper/command/slash/tag/TagCommand.java | 48 +++++++ .../slash/tag/TagMessageConstants.java | 12 ++ 10 files changed, 253 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 app/src/main/java/org/hyperskill/community/hyper/command/slash/tag/TagCommand.java create mode 100644 app/src/main/java/org/hyperskill/community/hyper/command/slash/tag/TagMessageConstants.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..6f95ebf --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d84f16f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/java/org/hyperskill/community/hyper/App.java b/app/src/main/java/org/hyperskill/community/hyper/App.java index aaa984c..18e635e 100644 --- a/app/src/main/java/org/hyperskill/community/hyper/App.java +++ b/app/src/main/java/org/hyperskill/community/hyper/App.java @@ -9,6 +9,7 @@ import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import org.hyperskill.community.hyper.command.slash.PingCommand; +import org.hyperskill.community.hyper.command.slash.tag.TagCommand; public final class App { public static void main(String[] args) { @@ -27,6 +28,7 @@ public static List commands() { List commands = new ArrayList<>(); commands.add(new PingCommand()); + commands.add(new TagCommand()); return commands; } diff --git a/app/src/main/java/org/hyperskill/community/hyper/command/slash/tag/TagCommand.java b/app/src/main/java/org/hyperskill/community/hyper/command/slash/tag/TagCommand.java new file mode 100644 index 0000000..aa19fab --- /dev/null +++ b/app/src/main/java/org/hyperskill/community/hyper/command/slash/tag/TagCommand.java @@ -0,0 +1,48 @@ +package org.hyperskill.community.hyper.command.slash.tag; + +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.interactions.commands.build.Commands; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import org.hyperskill.community.hyper.command.slash.SlashCommand; + + +public class TagCommand extends SlashCommand { + public TagCommand() { + + super(Commands + .slash("tag", "bot message") + + .addOptions( + new OptionData(OptionType.STRING, "id", "id of tag command") + .addChoice(TagMessageConstants.HOW_TO_ASK_ID, TagMessageConstants.HOW_TO_ASK_VALUE) + .addChoice(TagMessageConstants.HOW_TO_CONTACT_SUPPORT_ID, TagMessageConstants.HOW_TO_CONTACT_SUPPORT_VALUE) + ) + ); + } + + /** + * send pre-defined bot messages to user + * + * @param event interaction event + */ + @Override + public void onSlashCommand(SlashCommandInteractionEvent event) { + event.reply(getTagOption(event.getCommandString())).queue(); + } + + /** + * + * parse command string from event and extract message value + * + * @param commandString full command that includes id and value + * + * @return value + */ + private String getTagOption(String commandString){ + + // command string is : /tag id: + String[] commandSegments = commandString.split(":"); + return commandSegments[1].trim(); + } +} diff --git a/app/src/main/java/org/hyperskill/community/hyper/command/slash/tag/TagMessageConstants.java b/app/src/main/java/org/hyperskill/community/hyper/command/slash/tag/TagMessageConstants.java new file mode 100644 index 0000000..e5d6ddf --- /dev/null +++ b/app/src/main/java/org/hyperskill/community/hyper/command/slash/tag/TagMessageConstants.java @@ -0,0 +1,12 @@ +package org.hyperskill.community.hyper.command.slash.tag; + +/** + * Class that contains bot messages + */ +public class TagMessageConstants { + + public static final String HOW_TO_ASK_ID = "how-to-ask-question"; + public static final String HOW_TO_ASK_VALUE = "ask away"; + public static final String HOW_TO_CONTACT_SUPPORT_ID = "how-to-contact-support"; + public static final String HOW_TO_CONTACT_SUPPORT_VALUE = "contact support"; +}