Browse Source

add some javadocs and minor cleanup

main
Stephanie Gredell 2 years ago
parent
commit
e79651220a
  1. 11
      app/src/main/java/musicbot/ButtonInteraction.java
  2. 13
      app/src/main/java/musicbot/ButtonInteractionManager.java
  3. 3
      app/src/main/java/musicbot/CommandManager.java
  4. 5
      app/src/main/java/musicbot/MCommand.java
  5. 2
      app/src/main/java/musicbot/YoutubeSearch.java
  6. 4
      app/src/main/java/musicbot/buttonInteractions/MoreRecommendation.java
  7. 7
      app/src/main/java/musicbot/commands/Recommend.java

11
app/src/main/java/musicbot/ButtonInteraction.java

@ -2,8 +2,19 @@ package musicbot; @@ -2,8 +2,19 @@ package musicbot;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
/**
* Interface to build a button interaction to manage a button event
*/
public interface ButtonInteraction {
/**
* A unique name that identifies the button interaction
* @return String the name of the button
*/
String getName();
/**
* Executes the interaction logic of the button
* @param event
*/
void execute(ButtonInteractionEvent event);
}

13
app/src/main/java/musicbot/ButtonInteractionManager.java

@ -7,9 +7,18 @@ import org.jetbrains.annotations.NotNull; @@ -7,9 +7,18 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* Extension of the Listener Adaptor that manages all the interactions. Because
* JDA doesn't have a class to specifically build button events, this is a custom way
* of doing so.
*/
public class ButtonInteractionManager extends ListenerAdapter {
private final List<ButtonInteraction> buttonInteractions = new ArrayList<>();
/**
* Listener for the button interactions.
* @param event the {@code ButtonInteractionEvent}
*/
@Override
public void onButtonInteraction(@NotNull ButtonInteractionEvent event) {
final String id = event.getComponent().getId();
@ -23,6 +32,10 @@ public class ButtonInteractionManager extends ListenerAdapter { @@ -23,6 +32,10 @@ public class ButtonInteractionManager extends ListenerAdapter {
}
}
/**
* Add a ButtonInteraction to the ButtonInteractionManager
* @param buttonInteraction the ButtonInteractiont to be added
*/
public void add(@NotNull final ButtonInteraction buttonInteraction) {
buttonInteractions.add(buttonInteraction);
}

3
app/src/main/java/musicbot/CommandManager.java

@ -9,6 +9,9 @@ import org.jetbrains.annotations.NotNull; @@ -9,6 +9,9 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* Extension of the Listener Adaptor that manages all the commands.
*/
public class CommandManager extends ListenerAdapter {
private final List<MCommand> commands = new ArrayList<>();

5
app/src/main/java/musicbot/MCommand.java

@ -5,6 +5,11 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData; @@ -5,6 +5,11 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import java.util.List;
/**
* Interface to build a command interaction to manage a button event.
* This class is prefaced with an M (for MusicBot) as to not confuse with
* JDA's Command class.
*/
public interface MCommand {
String getName();

2
app/src/main/java/musicbot/YoutubeSearch.java

@ -19,8 +19,6 @@ import java.util.Optional; @@ -19,8 +19,6 @@ import java.util.Optional;
import java.util.Properties;
public class YoutubeSearch {
private static final String PROPERTIES_FILENAME = "youtube.properties";
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
private static final JsonFactory JSON_FACTORY = new JacksonFactory();

4
app/src/main/java/musicbot/buttonInteractions/MoreRecommendation.java

@ -13,6 +13,10 @@ import java.util.Arrays; @@ -13,6 +13,10 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* This interaction happens when a user requests more recommendations
* after initial /recommend.
*/
public class MoreRecommendation implements ButtonInteraction {
private static final int INCREMENT = 5;
private static final String ARGS_DELIMITER = "_";

7
app/src/main/java/musicbot/commands/Recommend.java

@ -5,7 +5,6 @@ import musicbot.RecommendationService; @@ -5,7 +5,6 @@ import musicbot.RecommendationService;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
@ -74,10 +73,8 @@ public class Recommend implements MCommand { @@ -74,10 +73,8 @@ public class Recommend implements MCommand {
final List<Button> buttons = trackList.stream().map(track -> {
final String artists = String.join(
", ",
Arrays.stream(track.getArtists()).map(ArtistSimplified::getName)
.collect(Collectors.toList()));
final String artists = Arrays.stream(track.getArtists()).map(ArtistSimplified::getName)
.collect(Collectors.joining(", "));
return Button.primary("recommend_" + artists, track.getName());
}).collect(Collectors.toList());

Loading…
Cancel
Save