8 changed files with 179 additions and 98 deletions
@ -0,0 +1,41 @@ |
|||||||
|
package musicbot; |
||||||
|
|
||||||
|
import net.dv8tion.jda.api.entities.Guild; |
||||||
|
import net.dv8tion.jda.api.events.ReadyEvent; |
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; |
||||||
|
import net.dv8tion.jda.api.hooks.ListenerAdapter; |
||||||
|
import org.jetbrains.annotations.NotNull; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public class CommandManager extends ListenerAdapter { |
||||||
|
private final List<MCommand> commands = new ArrayList<>(); |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onReady(final ReadyEvent event) { |
||||||
|
for (final Guild guild : event.getJDA().getGuilds()) { |
||||||
|
for (MCommand command : commands) { |
||||||
|
if (command.getOptions() == null) { |
||||||
|
guild.upsertCommand(command.getName(), command.getDescription()).queue(); |
||||||
|
} else { |
||||||
|
guild.upsertCommand(command.getName(), command.getDescription()).addOptions(command.getOptions()).queue(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onSlashCommandInteraction(final @NotNull SlashCommandInteractionEvent event) { |
||||||
|
for(final MCommand command : commands) { |
||||||
|
if(command.getName().equals(event.getName())) { |
||||||
|
command.execute(event); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void add(final MCommand command) { |
||||||
|
commands.add(command); |
||||||
|
} |
||||||
|
} |
||||||
@ -1,65 +0,0 @@ |
|||||||
package musicbot; |
|
||||||
|
|
||||||
import net.dv8tion.jda.api.JDA; |
|
||||||
import net.dv8tion.jda.api.events.ReadyEvent; |
|
||||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; |
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter; |
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionType; |
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData; |
|
||||||
import org.jetbrains.annotations.NotNull; |
|
||||||
|
|
||||||
public class Listeners extends ListenerAdapter { |
|
||||||
@Override |
|
||||||
public void onReady(@NotNull final ReadyEvent event) { |
|
||||||
//final JDA jda = event.getJDA().getGuildById(1197770092243599431L).getJDA();
|
|
||||||
final JDA jda = event.getJDA(); |
|
||||||
|
|
||||||
jda.upsertCommand("music", "find music to play").addOptions( |
|
||||||
new OptionData( |
|
||||||
OptionType.STRING, |
|
||||||
"title", |
|
||||||
"The name of the song", |
|
||||||
true), |
|
||||||
new OptionData( |
|
||||||
OptionType.STRING, |
|
||||||
"artist", |
|
||||||
"The artist of the song", |
|
||||||
true) |
|
||||||
).queue(); |
|
||||||
|
|
||||||
jda.upsertCommand("recommend", "find recommendations for music").addOptions( |
|
||||||
new OptionData( |
|
||||||
OptionType.STRING, |
|
||||||
"artist", |
|
||||||
"Find other songs and artists based on an artist you like" |
|
||||||
), |
|
||||||
new OptionData( |
|
||||||
OptionType.STRING, |
|
||||||
"genre", |
|
||||||
"Find other songs and artists based on a genre you like" |
|
||||||
) |
|
||||||
).queue(); |
|
||||||
|
|
||||||
jda.upsertCommand("artist", "find songs by artist").addOptions( |
|
||||||
new OptionData( |
|
||||||
OptionType.STRING, |
|
||||||
"name", |
|
||||||
"Find tracks by an artist.", |
|
||||||
true |
|
||||||
) |
|
||||||
).queue(); |
|
||||||
|
|
||||||
jda.upsertCommand("genres", "find supported genres").queue(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void onButtonInteraction(@NotNull ButtonInteractionEvent event) { |
|
||||||
final String artist = event.getComponent().getId(); |
|
||||||
final String title = event.getComponent().getLabel(); |
|
||||||
|
|
||||||
final YoutubeSearch youtubeSearch = new YoutubeSearch(); |
|
||||||
final String result = youtubeSearch.searchForMusic(title, artist); |
|
||||||
|
|
||||||
event.reply(result).queue(); |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,16 @@ |
|||||||
|
package musicbot; |
||||||
|
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; |
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public interface MCommand { |
||||||
|
String getName(); |
||||||
|
|
||||||
|
String getDescription(); |
||||||
|
|
||||||
|
List<OptionData> getOptions(); |
||||||
|
|
||||||
|
void execute(SlashCommandInteractionEvent event); |
||||||
|
} |
||||||
Loading…
Reference in new issue