Skip to content

Commit

Permalink
fix DJ permissions in PlayCmd
Browse files Browse the repository at this point in the history
general cleanup
  • Loading branch information
jagrosh committed Oct 21, 2019
1 parent 4579d6c commit 11c9b00
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 40 deletions.
15 changes: 7 additions & 8 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.jagrosh.jmusicbot;

import com.jagrosh.jdautilities.command.CommandClient;
import com.jagrosh.jdautilities.command.CommandClientBuilder;
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import com.jagrosh.jdautilities.examples.command.*;
Expand Down Expand Up @@ -104,20 +103,20 @@ public static void main(String[] args)

new LyricsCmd(bot),
new NowplayingCmd(bot),
new PlayCmd(bot, config.getLoading()),
new PlayCmd(bot),
new PlaylistsCmd(bot),
new QueueCmd(bot),
new RemoveCmd(bot),
new SearchCmd(bot, config.getSearching()),
new SCSearchCmd(bot, config.getSearching()),
new SearchCmd(bot),
new SCSearchCmd(bot),
new ShuffleCmd(bot),
new SkipCmd(bot),

new ForceRemoveCmd(bot),
new ForceskipCmd(bot),
new MoveTrackCmd(bot),
new PauseCmd(bot),
new PlaynextCmd(bot, config.getLoading()),
new PlaynextCmd(bot),
new RepeatCmd(bot),
new SkiptoCmd(bot),
new StopCmd(bot),
Expand Down Expand Up @@ -150,7 +149,6 @@ else if(config.getGame().getName().equalsIgnoreCase("none"))
}
else
cb.setGame(config.getGame());
CommandClient client = cb.build();

if(!prompt.isNoGUI())
{
Expand All @@ -177,8 +175,9 @@ else if(config.getGame().getName().equalsIgnoreCase("none"))
.setToken(config.getToken())
.setAudioEnabled(true)
.setGame(nogame ? null : Game.playing("loading..."))
.setStatus(config.getStatus()==OnlineStatus.INVISIBLE||config.getStatus()==OnlineStatus.OFFLINE ? OnlineStatus.INVISIBLE : OnlineStatus.DO_NOT_DISTURB)
.addEventListener(client, waiter, new Listener(bot))
.setStatus(config.getStatus()==OnlineStatus.INVISIBLE || config.getStatus()==OnlineStatus.OFFLINE
? OnlineStatus.INVISIBLE : OnlineStatus.DO_NOT_DISTURB)
.addEventListener(cb.build(), waiter, new Listener(bot))
.setBulkDeleteSplittingEnabled(true)
.build();
bot.setJDA(jda);
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/com/jagrosh/jmusicbot/commands/DJCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.jagrosh.jmusicbot.commands;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.settings.Settings;
import net.dv8tion.jda.core.Permission;
Expand All @@ -29,17 +30,19 @@ public abstract class DJCommand extends MusicCommand
public DJCommand(Bot bot)
{
super(bot);
this.category = new Category("DJ", event ->
{
if(event.getAuthor().getId().equals(event.getClient().getOwnerId()))
return true;
if(event.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());
});
this.category = new Category("DJ", event -> checkDJPermission(event));
}

public static boolean checkDJPermission(CommandEvent event)
{
if(event.getAuthor().getId().equals(event.getClient().getOwnerId()))
return true;
if(event.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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public class PlaynextCmd extends DJCommand
{
private final String loadingEmoji;

public PlaynextCmd(Bot bot, String loadingEmoji)
public PlaynextCmd(Bot bot)
{
super(bot);
this.loadingEmoji = loadingEmoji;
this.loadingEmoji = bot.getConfig().getLoading();
this.name = "playnext";
this.arguments = "<title|URL>";
this.help = "plays a single song next";
Expand Down
20 changes: 6 additions & 14 deletions src/main/java/com/jagrosh/jmusicbot/commands/music/PlayCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.audio.QueuedTrack;
import com.jagrosh.jmusicbot.commands.DJCommand;
import com.jagrosh.jmusicbot.commands.MusicCommand;
import com.jagrosh.jmusicbot.playlist.PlaylistLoader.Playlist;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil;
import java.util.concurrent.TimeUnit;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.exceptions.PermissionException;

/**
Expand All @@ -47,10 +46,10 @@ public class PlayCmd extends MusicCommand

private final String loadingEmoji;

public PlayCmd(Bot bot, String loadingEmoji)
public PlayCmd(Bot bot)
{
super(bot);
this.loadingEmoji = loadingEmoji;
this.loadingEmoji = bot.getConfig().getLoading();
this.name = "play";
this.arguments = "<title|URL|subcommand>";
this.help = "plays the provided song";
Expand All @@ -67,20 +66,13 @@ public void doCommand(CommandEvent event)
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
if(handler.getPlayer().getPlayingTrack()!=null && handler.getPlayer().isPaused())
{
boolean isDJ = event.getMember().hasPermission(Permission.MANAGE_SERVER);
if(!isDJ)
isDJ = event.isOwner();
Settings settings = event.getClient().getSettingsFor(event.getGuild());
Role dj = settings.getRole(event.getGuild());
if(!isDJ && dj!=null)
isDJ = event.getMember().getRoles().contains(dj);
if(!isDJ)
event.replyError("Only DJs can unpause the player!");
else
if(DJCommand.checkDJPermission(event))
{
handler.getPlayer().setPaused(false);
event.replySuccess("Resumed **"+handler.getPlayer().getPlayingTrack().getInfo().title+"**.");
}
else
event.replyError("Only DJs can unpause the player!");
return;
}
StringBuilder builder = new StringBuilder(event.getClient().getWarning()+" Play Commands:\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/
public class SCSearchCmd extends SearchCmd
{
public SCSearchCmd(Bot bot, String searchingEmoji)
public SCSearchCmd(Bot bot)
{
super(bot, searchingEmoji);
super(bot);
this.searchPrefix = "scsearch:";
this.name = "scsearch";
this.help = "searches Soundcloud for a provided query";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class SearchCmd extends MusicCommand
private final OrderedMenu.Builder builder;
private final String searchingEmoji;

public SearchCmd(Bot bot, String searchingEmoji)
public SearchCmd(Bot bot)
{
super(bot);
this.searchingEmoji = searchingEmoji;
this.searchingEmoji = bot.getConfig().getSearching();
this.name = "search";
this.aliases = new String[]{"ytsearch"};
this.arguments = "<query>";
Expand Down

0 comments on commit 11c9b00

Please sign in to comment.