Skip to content

Commit

Permalink
Fix remote control
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasave committed Nov 24, 2023
1 parent a7def56 commit bce671b
Show file tree
Hide file tree
Showing 30 changed files with 78 additions and 76 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private static void startBot()
new AutoplaylistCmd(bot),
new DebugCmd(bot),
new OverviewCmd(bot),
new AdminCmd(bot),
new ServerCmd(bot),
new PlaylistCmd(bot),
new SetavatarCmd(bot),
new SetgameCmd(bot),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public AdminCommand()
{
if(event.getAuthor().getId().equals(event.getClient().getOwnerId()))
return true;
if(event.getGuild()==null)
if(event.getMessage().getMember().getGuild()==null)
return true;
return event.getMember().hasPermission(Permission.MANAGE_SERVER);
});
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/jagrosh/jmusicbot/commands/DJCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public static boolean checkDJPermission(CommandEvent event)
{
if(event.getAuthor().getId().equals(event.getClient().getOwnerId()))
return true;
if(event.getGuild()==null)
if(event.getMessage().getMember().getGuild()==null)
return true;
if(event.getMember().hasPermission(Permission.MANAGE_SERVER))
return true;
Settings settings = event.getClient().getSettingsFor(event.getGuild());
Role dj = settings.getRole(event.getGuild());
return dj!=null && (event.getMember().getRoles().contains(dj) || dj.getIdLong()==event.getGuild().getIdLong());
Settings settings = event.getClient().getSettingsFor(event.getMessage().getMember().getGuild());
Role dj = settings.getRole(event.getMessage().getMember().getGuild());
return dj!=null && (event.getMember().getRoles().contains(dj) || dj.getIdLong()==event.getMessage().getMember().getGuild().getIdLong());
}
}
22 changes: 12 additions & 10 deletions src/main/java/com/jagrosh/jmusicbot/commands/MusicCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.GuildVoiceState;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.VoiceChannel;
Expand Down Expand Up @@ -48,9 +49,10 @@ public MusicCommand(Bot bot)
@Override
protected void execute(CommandEvent event)
{
Settings settings = event.getClient().getSettingsFor(event.getGuild());
TextChannel tchannel = settings.getTextChannel(event.getGuild());
LOG.info("Received a MusicCommand from " + event.getAuthor().getName() + " on channel " + event.getChannel().getName() + " from server " + event.getGuild().getName() + ": " + event.getMessage().getContentStripped());
Guild guild = event.getMessage().getMember().getGuild();
Settings settings = event.getClient().getSettingsFor(guild);
TextChannel tchannel = settings.getTextChannel(guild);
LOG.info("Received a MusicCommand from " + event.getAuthor().getName() + " on channel " + event.getChannel().getName() + " from server " + guild.getName() + ": " + event.getMessage().getContentStripped());
if(tchannel!=null && !event.getTextChannel().equals(tchannel))
{
try
Expand All @@ -60,36 +62,36 @@ protected void execute(CommandEvent event)
event.replyInDm(event.getClient().getError()+" You can only use that command in "+tchannel.getAsMention()+"!");
return;
}
bot.getPlayerManager().setUpHandler(event.getGuild()); // no point constantly checking for this later
if(bePlaying && !((AudioHandler)event.getGuild().getAudioManager().getSendingHandler()).isMusicPlaying(event.getJDA()))
bot.getPlayerManager().setUpHandler(guild); // no point constantly checking for this later
if(bePlaying && !((AudioHandler)guild.getAudioManager().getSendingHandler()).isMusicPlaying(event.getJDA()))
{
event.reply(event.getClient().getError()+" There must be music playing to use that!");
return;
}
if(beListening)
{
VoiceChannel current = event.getGuild().getSelfMember().getVoiceState().getChannel();
VoiceChannel current = guild.getSelfMember().getVoiceState().getChannel();
if(current==null)
current = settings.getVoiceChannel(event.getGuild());
current = settings.getVoiceChannel(guild);
GuildVoiceState userState = event.getMember().getVoiceState();
if(!userState.inVoiceChannel() || userState.isDeafened() || (current!=null && !userState.getChannel().equals(current)))
{
event.replyError("You must be listening in "+(current==null ? "a voice channel" : current.getAsMention())+" to use that!");
return;
}

VoiceChannel afkChannel = userState.getGuild().getAfkChannel();
VoiceChannel afkChannel = guild.getAfkChannel();
if(afkChannel != null && afkChannel.equals(userState.getChannel()))
{
event.replyError("You cannot use that command in an AFK channel!");
return;
}

if(!event.getGuild().getSelfMember().getVoiceState().inVoiceChannel())
if(!guild.getSelfMember().getVoiceState().inVoiceChannel())
{
try
{
userState.getGuild().getAudioManager().openAudioConnection(userState.getChannel());
guild.getAudioManager().openAudioConnection(userState.getChannel());
}
catch(PermissionException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected void execute(CommandEvent event)
return;
}

Settings s = event.getClient().getSettingsFor(event.getGuild());
Settings s = event.getClient().getSettingsFor(event.getMessage().getMember().getGuild());
if(event.getArgs().equalsIgnoreCase("none"))
{
s.setPrefix(null);
Expand All @@ -52,7 +52,7 @@ protected void execute(CommandEvent event)
else
{
s.setPrefix(event.getArgs());
event.replySuccess("Custom prefix set to `" + event.getArgs() + "` on *" + event.getGuild().getName() + "*");
event.replySuccess("Custom prefix set to `" + event.getArgs() + "` on *" + event.getMessage().getMember().getGuild().getName() + "*");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ protected void execute(CommandEvent event)
event.reply(event.getClient().getError()+" Please include a role name or NONE");
return;
}
Settings s = event.getClient().getSettingsFor(event.getGuild());
Settings s = event.getClient().getSettingsFor(event.getMessage().getMember().getGuild());
if(event.getArgs().equalsIgnoreCase("none"))
{
s.setDJRole(null);
event.reply(event.getClient().getSuccess()+" DJ role cleared; Only Admins can use the DJ commands.");
}
else
{
List<Role> list = FinderUtil.findRoles(event.getArgs(), event.getGuild());
List<Role> list = FinderUtil.findRoles(event.getArgs(), event.getMessage().getMember().getGuild());
if(list.isEmpty())
event.reply(event.getClient().getWarning()+" No Roles found matching \""+event.getArgs()+"\"");
else if (list.size()>1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ protected void execute(CommandEvent event)
event.reply(event.getClient().getError()+" Please include a text channel or NONE");
return;
}
Settings s = event.getClient().getSettingsFor(event.getGuild());
Settings s = event.getClient().getSettingsFor(event.getMessage().getMember().getGuild());
if(event.getArgs().equalsIgnoreCase("none"))
{
s.setTextChannel(null);
event.reply(event.getClient().getSuccess()+" Music commands can now be used in any channel");
}
else
{
List<TextChannel> list = FinderUtil.findTextChannels(event.getArgs(), event.getGuild());
List<TextChannel> list = FinderUtil.findTextChannels(event.getArgs(), event.getMessage().getMember().getGuild());
if(list.isEmpty())
event.reply(event.getClient().getWarning()+" No Text Channels found matching \""+event.getArgs()+"\"");
else if (list.size()>1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ protected void execute(CommandEvent event)
event.reply(event.getClient().getError()+" Please include a voice channel or NONE");
return;
}
Settings s = event.getClient().getSettingsFor(event.getGuild());
Settings s = event.getClient().getSettingsFor(event.getMessage().getMember().getGuild());
if(event.getArgs().equalsIgnoreCase("none"))
{
s.setVoiceChannel(null);
event.reply(event.getClient().getSuccess()+" Music can now be played in any channel");
}
else
{
List<VoiceChannel> list = FinderUtil.findVoiceChannels(event.getArgs(), event.getGuild());
List<VoiceChannel> list = FinderUtil.findVoiceChannels(event.getArgs(), event.getMessage().getMember().getGuild());
if(list.isEmpty())
event.reply(event.getClient().getWarning()+" No Voice Channels found matching \""+event.getArgs()+"\"");
else if (list.size()>1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ protected void execute(CommandEvent event)
event.replyError("The provided value must be between 0 and 100!");
return;
}
Settings s = event.getClient().getSettingsFor(event.getGuild());
Settings s = event.getClient().getSettingsFor(event.getMessage().getMember().getGuild());
s.setSkipRatio(val / 100.0);
event.replySuccess("Skip percentage has been set to `" + val + "%` of listeners on *" + event.getGuild().getName() + "*");
event.replySuccess("Skip percentage has been set to `" + val + "%` of listeners on *" + event.getMessage().getMember().getGuild().getName() + "*");
}
catch(NumberFormatException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void doCommand(CommandEvent event)
return;
}

AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
AudioHandler handler = (AudioHandler) event.getMessage().getMember().getGuild().getAudioManager().getSendingHandler();
if (handler.getQueue().isEmpty())
{
event.replyError("There is nothing in the queue!");
Expand All @@ -64,7 +64,7 @@ public void doCommand(CommandEvent event)


User target;
List<Member> found = FinderUtil.findMembers(event.getArgs(), event.getGuild());
List<Member> found = FinderUtil.findMembers(event.getArgs(), event.getMessage().getMember().getGuild());

if(found.isEmpty())
{
Expand Down Expand Up @@ -106,7 +106,7 @@ else if(found.size()>1)

private void removeAllEntries(User target, CommandEvent event)
{
int count = ((AudioHandler) event.getGuild().getAudioManager().getSendingHandler()).getQueue().removeAll(target.getIdLong());
int count = ((AudioHandler) event.getMessage().getMember().getGuild().getAudioManager().getSendingHandler()).getQueue().removeAll(target.getIdLong());
if (count == 0)
{
event.replyWarning("**"+target.getName()+"** doesn't have any songs in the queue!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ForceskipCmd(Bot bot)
@Override
public void doCommand(CommandEvent event)
{
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
AudioHandler handler = (AudioHandler)event.getMessage().getMember().getGuild().getAudioManager().getSendingHandler();
RequestMetadata rm = handler.getRequestMetadata();
if (handler.getPlayer().getPlayingTrack().getInfo().title.contains("Efteling") && rm.user.username.contains("demisaurus")) {
event.reply("Sorry, Efteling music cannot be skipped. Please try again when a different song is playing.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void doCommand(CommandEvent event)
}

// Validate that from and to are available
AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
AudioHandler handler = (AudioHandler) event.getMessage().getMember().getGuild().getAudioManager().getSendingHandler();
FairQueue<QueuedTrack> queue = handler.getQueue();
if (isUnavailablePosition(queue, from))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public PauseCmd(Bot bot)
@Override
public void doCommand(CommandEvent event)
{
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
AudioHandler handler = (AudioHandler)event.getMessage().getMember().getGuild().getAudioManager().getSendingHandler();
if(handler.getPlayer().isPaused())
{
event.replyWarning("The player is already paused! Use `"+event.getClient().getPrefix()+"play` to unpause!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void doCommand(CommandEvent event)
String args = event.getArgs().startsWith("<") && event.getArgs().endsWith(">")
? event.getArgs().substring(1,event.getArgs().length()-1)
: event.getArgs().isEmpty() ? event.getMessage().getAttachments().get(0).getUrl() : event.getArgs();
event.reply(loadingEmoji+" Loading... `["+args+"]`", m -> bot.getPlayerManager().loadItemOrdered(event.getGuild(), args, new ResultHandler(m,event,false)));
event.reply(loadingEmoji+" Loading... `["+args+"]`", m -> bot.getPlayerManager().loadItemOrdered(event.getMessage().getMember().getGuild(), args, new ResultHandler(m,event,false)));
}

private class ResultHandler implements AudioLoadResultHandler
Expand All @@ -82,7 +82,7 @@ private void loadSingle(AudioTrack track)
+FormatUtil.formatTime(track.getDuration())+"` > `"+FormatUtil.formatTime(bot.getConfig().getMaxSeconds()*1000)+"`")).queue();
return;
}
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
AudioHandler handler = (AudioHandler)event.getMessage().getMember().getGuild().getAudioManager().getSendingHandler();
int pos = handler.addTrackToFront(new QueuedTrack(track, event.getAuthor()))+1;
String addMsg = FormatUtil.filter(event.getClient().getSuccess()+" Added **"+track.getInfo().title
+"** (`"+FormatUtil.formatTime(track.getDuration())+"`) "+(pos==0?"to begin playing":" to the queue at position "+pos));
Expand Down Expand Up @@ -114,7 +114,7 @@ public void noMatches()
if(ytsearch)
m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" No results found for `"+event.getArgs()+"`.")).queue();
else
bot.getPlayerManager().loadItemOrdered(event.getGuild(), "ytsearch:"+event.getArgs(), new ResultHandler(m,event,true));
bot.getPlayerManager().loadItemOrdered(event.getMessage().getMember().getGuild(), "ytsearch:"+event.getArgs(), new ResultHandler(m,event,true));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected void execute(CommandEvent event)
{
String args = event.getArgs();
RepeatMode value;
Settings settings = event.getClient().getSettingsFor(event.getGuild());
Settings settings = event.getClient().getSettingsFor(event.getMessage().getMember().getGuild());
if(args.isEmpty())
{
if(settings.getRepeatMode() == RepeatMode.OFF)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void doCommand(CommandEvent event)
event.reply(event.getClient().getError()+" `"+event.getArgs()+"` is not a valid integer!");
return;
}
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
AudioHandler handler = (AudioHandler)event.getMessage().getMember().getGuild().getAudioManager().getSendingHandler();
RequestMetadata rm = handler.getRequestMetadata();
if (handler.getPlayer().getPlayingTrack().getInfo().title.contains("Efteling") && rm.user.username.contains("demisaurus")) {
event.reply("Sorry, Efteling music cannot be skipped. Please try again when a different song is playing.");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jagrosh/jmusicbot/commands/dj/StopCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public StopCmd(Bot bot)
@Override
public void doCommand(CommandEvent event)
{
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
AudioHandler handler = (AudioHandler)event.getMessage().getMember().getGuild().getAudioManager().getSendingHandler();
handler.stopAndClear();
event.getGuild().getAudioManager().closeAudioConnection();
event.getMessage().getMember().getGuild().getAudioManager().closeAudioConnection();
event.reply(event.getClient().getSuccess()+" The player has stopped and the queue has been cleared.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public VolumeCmd(Bot bot)
@Override
public void doCommand(CommandEvent event)
{
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
Settings settings = event.getClient().getSettingsFor(event.getGuild());
AudioHandler handler = (AudioHandler)event.getMessage().getMember().getGuild().getAudioManager().getSendingHandler();
Settings settings = event.getClient().getSettingsFor(event.getMessage().getMember().getGuild());
int volume = handler.getPlayer().getVolume();
if(event.getArgs().isEmpty())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public SettingsCmd(Bot bot)
@Override
protected void execute(CommandEvent event)
{
Settings s = event.getClient().getSettingsFor(event.getGuild());
Settings s = event.getClient().getSettingsFor(event.getMessage().getMember().getGuild());
MessageBuilder builder = new MessageBuilder()
.append(EMOJI + " **")
.append(FormatUtil.filter(event.getSelfUser().getName()))
.append("** settings:");
TextChannel tchan = s.getTextChannel(event.getGuild());
VoiceChannel vchan = s.getVoiceChannel(event.getGuild());
Role role = s.getRole(event.getGuild());
TextChannel tchan = s.getTextChannel(event.getMessage().getMember().getGuild());
VoiceChannel vchan = s.getVoiceChannel(event.getMessage().getMember().getGuild());
Role role = s.getRole(event.getMessage().getMember().getGuild());
EmbedBuilder ebuilder = new EmbedBuilder()
.setColor(event.getSelfMember().getColor())
.setDescription("Text Channel: " + (tchan == null ? "Any" : "**#" + tchan.getName() + "**")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void doCommand(CommandEvent event)
String title;
if(event.getArgs().isEmpty())
{
AudioHandler sendingHandler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
AudioHandler sendingHandler = (AudioHandler) event.getMessage().getMember().getGuild().getAudioManager().getSendingHandler();
if (sendingHandler.isMusicPlaying(event.getJDA()))
title = sendingHandler.getPlayer().getPlayingTrack().getInfo().title;
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public NowplayingCmd(Bot bot)
@Override
public void doCommand(CommandEvent event)
{
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
AudioHandler handler = (AudioHandler)event.getMessage().getMember().getGuild().getAudioManager().getSendingHandler();
Message m = handler.getNowPlaying(event.getJDA());
if(m==null)
{
event.reply(handler.getNoMusicPlaying(event.getJDA()));
bot.getNowplayingHandler().clearLastNPMessage(event.getGuild());
bot.getNowplayingHandler().clearLastNPMessage(event.getMessage().getMember().getGuild());
}
else
{
Expand Down
Loading

0 comments on commit bce671b

Please sign in to comment.