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

Development #75

Merged
merged 8 commits into from
Dec 5, 2020
Merged
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
29 changes: 8 additions & 21 deletions src/main/java/command/music/JoinCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import client.NanoClient;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.VoiceChannel;
import service.music.CustomEmbedBuilder;
import service.music.GuildMusicManager;
import service.music.HelpProcess;
import service.music.MusicUtils;
Expand All @@ -26,12 +24,6 @@ public JoinCommand(NanoClient nanoClient) {

@Override
protected void execute(CommandEvent event) {
VoiceChannel channel = event.getMember().getVoiceState().getChannel();
if (channel == null) {
event.reply(":x: | You're not connected to any voice channel");
return;
}

GuildMusicManager musicManager = nanoClient.getGuildAudioPlayer(event.getGuild());
musicManager.scheduler.textChannel = event.getTextChannel();

Expand All @@ -41,18 +33,13 @@ protected void execute(CommandEvent event) {
return;
}
}
event.getGuild().getAudioManager().openAudioConnection(channel);

// if (!event.getSelfMember().hasPermission(Permission.VOICE_DEAF_OTHERS) &&
// !event.getSelfMember().getVoiceState().isDeafened()) {
// CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder();
// embedBuilder.addField(":warning: Missing Permission: `Deafen Members`!",
// "Please don't undeafen me! I work better by being deafened because: " +
// "Less lag, more clear, better quality, and doesn't randomly disconnect",
// true);
// event.reply(embedBuilder.build());
// }

event.reply(":white_check_mark: | Connected to :loud_sound: `" + channel.getName() + "`");

VoiceChannel connectedChannel = nanoClient.getMusicService().joinMemberVoiceChannel(event);

if (connectedChannel == null) {
return;
}

event.reply(":white_check_mark: | Connected to :loud_sound: `" + connectedChannel.getName() + "`");
}
}
12 changes: 11 additions & 1 deletion src/main/java/command/music/LeaveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.managers.AudioManager;
import service.music.GuildMusicManager;
import service.music.HelpProcess;
Expand All @@ -26,7 +27,16 @@ public LeaveCommand(NanoClient nanoClient) {
protected void execute(CommandEvent event) {
Guild guild = event.getGuild();

if (event.getSelfMember().getVoiceState().getChannel() == null) {
VoiceChannel selfVoiceChannel = event.getSelfMember().getVoiceState().getChannel();
if (selfVoiceChannel == null) {
return;
}

if (event.getMember().getVoiceState().getChannel() == null) {
return;
}

if (!selfVoiceChannel.getId().equals(event.getMember().getVoiceState().getChannel().getId())) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/command/music/LyricCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void execute(CommandEvent event)
embed.setTitle("Failed");
embed.addField(
":x:",
"Can't search lyric, because `song-title` is empty and currently no playing music.",
"Can't search lyric, because argument for `song-title` is empty and currently not playing any song.",
true);
event.reply(embed.build());
return;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/command/music/NowPlayCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ protected void execute(CommandEvent event) {

if (musicManager.player.getPlayingTrack() == null) {
event.replyError("Not playing anything");
if (event.getGuild().getAudioManager().getConnectedChannel() == null) {
nanoClient.getMusicManagers().remove(event.getGuild().getIdLong());
}
return;
}
musicManager.announceNowPlaying(event);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/command/music/PauseCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public PauseCommand(NanoClient nanoClient) {

@Override
protected void execute(CommandEvent event) {
VoiceChannel userVoiceChannel = event.getMember().getVoiceState().getChannel();
if (userVoiceChannel == null) {
event.reply(":x: | You are not connected to any voice channel");
if (!nanoClient.getMusicService().ensureVoiceState(event)) {
return;
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/command/music/PlayCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public PlayCommand(NanoClient nanoClient) {

@Override
protected void execute(CommandEvent event) {
VoiceChannel channel = event.getMember().getVoiceState().getChannel();
if (channel == null) {
event.reply(":x: | You're not connected to any voice channel");
if (!nanoClient.getMusicService().ensureVoiceState(event)) {
return;
}

Expand Down Expand Up @@ -63,7 +61,7 @@ protected void execute(CommandEvent event) {

if (connectedChannel == null) {
// if not connected to any voice channel, try to join user voice channel.
nanoClient.getMusicService().joinUserVoiceChannel(event);
nanoClient.getMusicService().joinMemberVoiceChannel(event);
}


Expand Down
6 changes: 2 additions & 4 deletions src/main/java/command/music/PlayUrlCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public PlayUrlCommand(NanoClient nanoClient) {

@Override
protected void execute(CommandEvent event) {
VoiceChannel channel = event.getMember().getVoiceState().getChannel();
if (channel == null) {
event.reply(":x: | You're not connected to any voice channel");
if (!nanoClient.getMusicService().ensureVoiceState(event)) {
return;
}

Expand Down Expand Up @@ -65,7 +63,7 @@ protected void execute(CommandEvent event) {

if (connectedChannel == null) {
// if not connected to any voice channel, try to join user voice channel.
nanoClient.getMusicService().joinUserVoiceChannel(event);
nanoClient.getMusicService().joinMemberVoiceChannel(event);
}

nanoClient.loadAndPlayUrl(musicManager, event.getTextChannel(), args, event.getMember());
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/command/music/RecommendationCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public RecommendationCommand(NanoClient nanoClient, YoutubeClient youtubeClient)

@Override
protected void execute(CommandEvent event) {
VoiceChannel channel = event.getMember().getVoiceState().getChannel();
if (channel == null) {
event.reply(":x: | You're not connected to any voice channel.");
if (!nanoClient.getMusicService().ensureVoiceState(event)) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/command/music/RepeatCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import client.NanoClient;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import net.dv8tion.jda.api.entities.VoiceChannel;
import service.music.GuildMusicManager;
import service.music.HelpProcess;
import service.music.MusicUtils;
Expand All @@ -24,12 +25,11 @@ public RepeatCommand(NanoClient nanoClient) {

@Override
protected void execute(CommandEvent event) {
GuildMusicManager musicManager = nanoClient.getGuildAudioPlayer(event.getGuild());
if (!nanoClient.getMusicService().isMemberInVoiceState(event.getMember())) {
event.reply("Are you sure you are in voice channel ?");
if (!nanoClient.getMusicService().ensureVoiceState(event)) {
return;
}

GuildMusicManager musicManager = nanoClient.getGuildAudioPlayer(event.getGuild());
if (musicManager.player.getPlayingTrack() == null) {
event.reply(":x: | Not playing anything");
return;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/command/music/ResumeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public ResumeCommand(NanoClient nanoClient) {

@Override
protected void execute(CommandEvent event) {
VoiceChannel userVoiceChannel = event.getMember().getVoiceState().getChannel();
if (userVoiceChannel == null) {
event.reply(":x: | You are not connected to any voice channel");
if (!nanoClient.getMusicService().ensureVoiceState(event)) {
return;
}

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/command/music/ShowGuildStateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ public ShowGuildStateCommand(NanoClient nanoClient) {

@Override
protected void execute(CommandEvent event) {
GuildMusicManager musicManager = nanoClient.getGuildAudioPlayer(event.getGuild());

// Ensure Voice
if (!nanoClient.getMusicService().isMemberInVoiceState(event.getMember())) {
event.reply(":x: | Are you sure you are in voice channel ?");
if (!nanoClient.getMusicService().ensureVoiceState(event)) {
return;
}

GuildMusicManager musicManager = nanoClient.getGuildAudioPlayer(event.getGuild());
if (musicManager.player.getPlayingTrack() == null) {
event.reply(":x: | Not playing anything");
return;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/command/music/ShowPaginatedQueueCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ public ShowPaginatedQueueCommand(NanoClient nanoClient) {

@Override
protected void execute(CommandEvent event) {
GuildMusicManager musicManager = nanoClient.getGuildAudioPlayer(event.getGuild());

// Ensure Voice
if (!nanoClient.getMusicService().isMemberInVoiceState(event.getMember())) {
event.reply("Are you sure you are in voice channel ?");
if (!nanoClient.getMusicService().ensureVoiceState(event)) {
return;
}

GuildMusicManager musicManager = nanoClient.getGuildAudioPlayer(event.getGuild());
if (musicManager.player.getPlayingTrack() == null) {
event.reply("Not playing anything");
return;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/command/music/ShuffleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public ShuffleCommand(NanoClient nanoClient) {

@Override
protected void execute(CommandEvent event) {
VoiceChannel userVoiceChannel = event.getMember().getVoiceState().getChannel();
if (userVoiceChannel == null) {
event.reply(":x: | You are not connected to any voice channel");
if (!nanoClient.getMusicService().ensureVoiceState(event)) {
return;
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/command/music/SkipCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ public SkipCommand(NanoClient nanoClient) {

@Override
protected void execute(CommandEvent event) {
GuildMusicManager musicManager = nanoClient.getGuildAudioPlayer(event.getGuild());

if (event.getMember().getVoiceState().getChannel() == null) {
event.reply(":x: | You are not connected to any voice channel");
if (!nanoClient.getMusicService().ensureVoiceState(event)) {
return;
}

GuildMusicManager musicManager = nanoClient.getGuildAudioPlayer(event.getGuild());
// Check if player is currently playing audio
if (musicManager.player.getPlayingTrack() == null) {
event.getChannel().sendMessage(":x: | Not playing anything").queue();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/command/music/VolumeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected void execute(CommandEvent event) {
return;
}
musicManager.player.setVolume(volume);
} catch (Exception e) {
} catch (NumberFormatException e) {
event.reply(":x: | Invalid volume number, command e.g. `" + event.getClient().getPrefix()
+ "volume 25` to change volume to 25%");
return;
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/command/music/YoutubeSearchCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import client.NanoClient;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import net.dv8tion.jda.api.entities.VoiceChannel;
import service.music.CustomEmbedBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
Expand Down Expand Up @@ -43,6 +44,11 @@ public YoutubeSearchCommand(NanoClient nano, YoutubeClient youtubeClient)
@Override
protected void execute(CommandEvent event)
{
if (!this.nano.getMusicService().ensureVoiceState(event))
{
return;
}

String keywords = event.getArgs();
if (keywords.isEmpty()) {
CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder();
Expand Down Expand Up @@ -116,14 +122,12 @@ protected void execute(CommandEvent event)
List<YoutubeVideo> finalVideos = videos;
this.nano.getWaiter().waitForEvent(
GuildMessageReceivedEvent.class,
e -> e.getChannel().equals(event.getChannel())
&& e.getAuthor().getId().equals(event.getAuthor().getId())
,
e -> e.getChannel().equals(event.getChannel())&&
e.getAuthor().getId().equals(event.getAuthor().getId()),
e ->
{
if (!this.nano.getMusicService().joinUserVoiceChannel(event))
if (!this.nano.getMusicService().ensureVoiceState(event))
{
event.reply(":x: | You are not connected to any voice channel.");
return;
}

Expand Down Expand Up @@ -158,8 +162,9 @@ protected void execute(CommandEvent event)
this.nano.loadAndPlayUrl(musicManager, event.getTextChannel(),
finalVideos.get(entry).getUrl(), event.getMember());
},
10, TimeUnit.SECONDS, () ->
msg.get().delete().queue()
10,
TimeUnit.SECONDS,
() -> msg.get().delete().queue()
);
}
}
12 changes: 0 additions & 12 deletions src/main/java/listener/MemberVoiceListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public void onGuildVoiceMove(@NotNull GuildVoiceMoveEvent event) {
else {
GuildMusicManager musicManager = nanoClient.getGuildAudioPlayer(event.getGuild());
if (musicManager.isWaitingForUser()) {
System.out.println("RESUME & SET WAITING FALSE");
musicManager.setWaitingForUser(false);
musicManager.player.setPaused(false);
musicManager.getWaitingFuture().cancel(true);
Expand Down Expand Up @@ -170,17 +169,6 @@ public void onGuildVoiceDeafen(@NotNull GuildVoiceDeafenEvent event) {
if (event.getMember().hasPermission(Permission.VOICE_DEAF_OTHERS)) {
event.getGuild().getSelfMember().deafen(true).queue();
}
// else {
// TextChannel textChannel = nanoClient.getGuildAudioPlayer(event.getGuild()).scheduler.textChannel;
//
// CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder();
// embedBuilder.addField(":warning: Missing Permission: `Deafen Members`!",
// "Please don't undeafen me! I work better by being deafened because: " +
// "Less lag, more clear, better quality, and doesn't randomly disconnect",
// true);
//
// textChannel.sendMessage(embedBuilder.build()).queue();
// }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/listener/MusicMessageListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {

if (".play".equals(command[0]) && command.length == 2) {
GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild());
if (musicService.joinUserVoiceChannel(event)) {
if (musicService.joinMemberVoiceChannel(event)) {
// Set default volume value
musicManager.player.setVolume(15);
musicService.loadAndPlay(playerManager, musicManager, event.getChannel(),
Expand Down
Loading