Skip to content
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

finished code for tag command. #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/src/main/java/org/hyperskill/community/hyper/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -27,6 +28,7 @@ public static List<Command> commands() {
List<Command> commands = new ArrayList<>();

commands.add(new PingCommand());
commands.add(new TagCommand());

return commands;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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: <value>
String[] commandSegments = commandString.split(":");
return commandSegments[1].trim();
}
}
Original file line number Diff line number Diff line change
@@ -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";
}