Skip to content

Commit

Permalink
Changed default from youtube to soundcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
RichtXO committed Oct 23, 2024
1 parent 17cc0aa commit db8bcc9
Showing 1 changed file with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions src/main/java/com/richtxo/commands/music/Play.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public Mono<Void> handle(ChatInputInteractionEvent event) {
.map(ApplicationCommandInteractionOptionValue::asString).orElse("");
String provider = event.getOption("provider")
.flatMap(ApplicationCommandInteractionOption::getValue)
.map(ApplicationCommandInteractionOptionValue::asString).orElse("ytsearch");
.map(ApplicationCommandInteractionOptionValue::asString).orElse("scsearch");
Snowflake guildId = event.getInteraction().getGuildId().orElse(Snowflake.of(0));
AudioProvider voice = GuildAudioManager.of(guildId).getProvider();

if (isURL(searchQuery) && searchQuery.toUpperCase().contains("spotify".toUpperCase())){
Join.autoDisconnect(channel, voice)
.and(loadSpotifyItem(event, searchQuery, provider)).subscribe();
Expand All @@ -86,7 +87,7 @@ public Mono<Void> handle(ChatInputInteractionEvent event) {

private boolean isURL(String input){
try {
new URI(input).toURL();
new URI(input);
return true;
} catch (Exception ignored){
return false;
Expand All @@ -103,7 +104,7 @@ private Mono<Void> loadSpotifyItem(ChatInputInteractionEvent event, String url,
if (song == null)
return event.editReply("Can't fetch Spotify song!").then();

return Mono.create(monoSink -> PLAYER_MANAGER.loadItem(String.format("%s: %s", provider, song.toString())
return Mono.create(monoSink -> PLAYER_MANAGER.loadItem(String.format("%s: %s", provider, song)
, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack audioTrack) {
Expand Down Expand Up @@ -153,34 +154,32 @@ public void loadFailed(FriendlyException e) {
private void loadSpotifySongs(ChatInputInteractionEvent event, String provider, Snowflake guildId,
SpotifyPlaylist playlist) {
for (SpotifySong song : playlist.getSongs()){
Mono.create(monoSink -> {
PLAYER_MANAGER.loadItem(String.format("%s: %s", provider, song), new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack audioTrack) {
// Shouldn't come in here
}
Mono.create(monoSink -> PLAYER_MANAGER.loadItem(String.format("%s: %s", provider, song), new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack audioTrack) {
// Shouldn't come in here
}

@Override
public void playlistLoaded(AudioPlaylist audioPlaylist) {
if (audioPlaylist.isSearchResult()) {
play(guildId, audioPlaylist.getTracks().getFirst());
monoSink.success();
}
@Override
public void playlistLoaded(AudioPlaylist audioPlaylist) {
if (audioPlaylist.isSearchResult()) {
play(guildId, audioPlaylist.getTracks().getFirst());
monoSink.success();
}
}

@Override
public void noMatches() {
event.editReply(String.format("Can't find match to `%s`", song.toString())).subscribe();
monoSink.error(new Exception("Not Found"));
}
@Override
public void noMatches() {
event.editReply(String.format("Can't find match to `%s`", song)).subscribe();
monoSink.error(new Exception("Not Found"));
}

@Override
public void loadFailed(FriendlyException e) {
event.editReply(String.format("Can't play `%s`", song.toString())).subscribe();
monoSink.error(e);
}
});
}).subscribe();
@Override
public void loadFailed(FriendlyException e) {
event.editReply(String.format("Can't play `%s`", song)).subscribe();
monoSink.error(e);
}
})).subscribe();
}
}

Expand Down Expand Up @@ -261,9 +260,7 @@ public void playlistLoaded(AudioPlaylist audioPlaylist) {
event.editReply().withEmbeds(selectionEmbed.build()).withComponents(
ActionRow.of(oneBtn, twoBtn, threeBtn, fourBtn, fiveBtn),
ActionRow.of(cancelBtn)).then(listener)
.doOnError(t -> {
System.out.println("error!!!!!!!!!!!!" + t);
}).subscribe();
.doOnError(t -> System.out.println("error!!!!!!!!!!!!" + t)).subscribe();
monoSink.success();
}

Expand Down

0 comments on commit db8bcc9

Please sign in to comment.