Skip to content

Commit

Permalink
Server-specific emojis with setemoji command
Browse files Browse the repository at this point in the history
  • Loading branch information
cmorley191 committed Feb 9, 2022
1 parent cfcc995 commit 557ac32
Show file tree
Hide file tree
Showing 40 changed files with 500 additions and 190 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

## Extra Features
- Play command works on spotify track, album or playlist links (Right click -> Share -> Copy link to playlist)
- Server-specific emojis used by the bot, configured by the setemoji command

## Setup
- Get the latest release at https://github.com/cmorley191/MusicBot/releases
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/com/jagrosh/jmusicbot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import com.jagrosh.jmusicbot.audio.AloneInVoiceHandler;
import com.jagrosh.jmusicbot.audio.AudioHandler;
Expand All @@ -25,6 +27,7 @@
import com.jagrosh.jmusicbot.gui.GUI;
import com.jagrosh.jmusicbot.playlist.PlaylistLoader;
import com.jagrosh.jmusicbot.playlist.SpotifyAPI;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.settings.SettingsManager;
import java.util.Objects;
import net.dv8tion.jda.api.JDA;
Expand Down Expand Up @@ -173,4 +176,45 @@ public void setGUI(GUI gui)
{
this.gui = gui;
}

private Settings getSettings(CommandEvent event) {
try { return getSettingsManager().getSettings(event.getGuild()); }
catch (IllegalStateException ignore) {}
return getSettingsManager().getSettings(null);
}

public String getSuccess(CommandEvent event)
{
String guildSetting = getSettings(event).getSuccess();
if (guildSetting != null) return guildSetting;
return getConfig().getSuccess();
}

public String getWarning(CommandEvent event)
{
String guildSetting = getSettings(event).getWarning();
if (guildSetting != null) return guildSetting;
return getConfig().getWarning();
}

public String getError(CommandEvent event)
{
String guildSetting = getSettings(event).getError();
if (guildSetting != null) return guildSetting;
return getConfig().getError();
}

public String getLoading(CommandEvent event)
{
String guildSetting = getSettings(event).getLoading();
if (guildSetting != null) return guildSetting;
return getConfig().getLoading();
}

public String getSearching(CommandEvent event)
{
String guildSetting = getSettings(event).getSearching();
if (guildSetting != null) return guildSetting;
return getConfig().getSearching();
}
}
1 change: 0 additions & 1 deletion src/main/java/com/jagrosh/jmusicbot/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public static void main(String[] args)
new SkipratioCmd(bot),
new SettcCmd(bot),
new SetvcCmd(bot),
new SetemojiCmd(bot),

new AutoplaylistCmd(bot),
new DebugCmd(bot),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager;
import com.typesafe.config.Config;
import net.dv8tion.jda.api.entities.Guild;

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/jagrosh/jmusicbot/commands/MusicCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ protected void execute(CommandEvent event)
{
event.getMessage().delete().queue();
} catch(PermissionException ignore){}
event.replyInDm(event.getClient().getError()+" You can only use that command in "+tchannel.getAsMention()+"!");
event.replyInDm(bot.getError(event)+" 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()))
{
event.reply(event.getClient().getError()+" There must be music playing to use that!");
event.reply(bot.getError(event)+" There must be music playing to use that!");
return;
}
if(beListening)
Expand All @@ -70,14 +70,14 @@ protected void execute(CommandEvent event)
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!");
event.reply(bot.getError(event)+"You must be listening in "+(current==null ? "a voice channel" : current.getAsMention())+" to use that!");
return;
}

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

Expand All @@ -89,7 +89,7 @@ protected void execute(CommandEvent event)
}
catch(PermissionException ex)
{
event.reply(event.getClient().getError()+" I am unable to connect to "+userState.getChannel().getAsMention()+"!");
event.reply(bot.getError(event)+" I am unable to connect to "+userState.getChannel().getAsMention()+"!");
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
*/
public class PrefixCmd extends AdminCommand
{
private final Bot bot;

public PrefixCmd(Bot bot)
{
this.bot = bot;
this.name = "prefix";
this.help = "sets a server-specific prefix";
this.arguments = "<prefix|NONE>";
Expand All @@ -39,20 +42,20 @@ protected void execute(CommandEvent event)
{
if(event.getArgs().isEmpty())
{
event.replyError("Please include a prefix or NONE");
event.reply(bot.getError(event)+"Please include a prefix or NONE");
return;
}

Settings s = event.getClient().getSettingsFor(event.getGuild());
if(event.getArgs().equalsIgnoreCase("none"))
{
s.setPrefix(null);
event.replySuccess("Prefix cleared.");
event.reply(bot.getSuccess(event)+"Prefix cleared.");
}
else
{
s.setPrefix(event.getArgs());
event.replySuccess("Custom prefix set to `" + event.getArgs() + "` on *" + event.getGuild().getName() + "*");
event.reply(bot.getSuccess(event)+"Custom prefix set to `" + event.getArgs() + "` on *" + event.getGuild().getName() + "*");
}
}
}
13 changes: 8 additions & 5 deletions src/main/java/com/jagrosh/jmusicbot/commands/admin/SetdjCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
*/
public class SetdjCmd extends AdminCommand
{
private final Bot bot;

public SetdjCmd(Bot bot)
{
this.bot = bot;
this.name = "setdj";
this.help = "sets the DJ role for certain music commands";
this.arguments = "<rolename|NONE>";
Expand All @@ -43,26 +46,26 @@ protected void execute(CommandEvent event)
{
if(event.getArgs().isEmpty())
{
event.reply(event.getClient().getError()+" Please include a role name or NONE");
event.reply(bot.getError(event)+" Please include a role name or NONE");
return;
}
Settings s = event.getClient().getSettingsFor(event.getGuild());
if(event.getArgs().equalsIgnoreCase("none"))
{
s.setDJRole(null);
event.reply(event.getClient().getSuccess()+" DJ role cleared; Only Admins can use the DJ commands.");
event.reply(bot.getSuccess(event)+" DJ role cleared; Only Admins can use the DJ commands.");
}
else
{
List<Role> list = FinderUtil.findRoles(event.getArgs(), event.getGuild());
if(list.isEmpty())
event.reply(event.getClient().getWarning()+" No Roles found matching \""+event.getArgs()+"\"");
event.reply(bot.getWarning(event)+" No Roles found matching \""+event.getArgs()+"\"");
else if (list.size()>1)
event.reply(event.getClient().getWarning()+FormatUtil.listOfRoles(list, event.getArgs()));
event.reply(bot.getWarning(event)+FormatUtil.listOfRoles(list, event.getArgs()));
else
{
s.setDJRole(list.get(0));
event.reply(event.getClient().getSuccess()+" DJ commands can now be used by users with the **"+list.get(0).getName()+"** role.");
event.reply(bot.getSuccess(event)+" DJ commands can now be used by users with the **"+list.get(0).getName()+"** role.");
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/com/jagrosh/jmusicbot/commands/admin/SettcCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
*/
public class SettcCmd extends AdminCommand
{
private final Bot bot;

public SettcCmd(Bot bot)
{
this.bot = bot;
this.name = "settc";
this.help = "sets the text channel for music commands";
this.arguments = "<channel|NONE>";
Expand All @@ -43,26 +46,26 @@ protected void execute(CommandEvent event)
{
if(event.getArgs().isEmpty())
{
event.reply(event.getClient().getError()+" Please include a text channel or NONE");
event.reply(bot.getError(event)+" Please include a text channel or NONE");
return;
}
Settings s = event.getClient().getSettingsFor(event.getGuild());
if(event.getArgs().equalsIgnoreCase("none"))
{
s.setTextChannel(null);
event.reply(event.getClient().getSuccess()+" Music commands can now be used in any channel");
event.reply(bot.getSuccess(event)+" Music commands can now be used in any channel");
}
else
{
List<TextChannel> list = FinderUtil.findTextChannels(event.getArgs(), event.getGuild());
if(list.isEmpty())
event.reply(event.getClient().getWarning()+" No Text Channels found matching \""+event.getArgs()+"\"");
event.reply(bot.getWarning(event)+" No Text Channels found matching \""+event.getArgs()+"\"");
else if (list.size()>1)
event.reply(event.getClient().getWarning()+FormatUtil.listOfTChannels(list, event.getArgs()));
event.reply(bot.getWarning(event)+FormatUtil.listOfTChannels(list, event.getArgs()));
else
{
s.setTextChannel(list.get(0));
event.reply(event.getClient().getSuccess()+" Music commands can now only be used in <#"+list.get(0).getId()+">");
event.reply(bot.getSuccess(event)+" Music commands can now only be used in <#"+list.get(0).getId()+">");
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/com/jagrosh/jmusicbot/commands/admin/SetvcCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
*/
public class SetvcCmd extends AdminCommand
{
private final Bot bot;

public SetvcCmd(Bot bot)
{
this.bot = bot;
this.name = "setvc";
this.help = "sets the voice channel for playing music";
this.arguments = "<channel|NONE>";
Expand All @@ -43,26 +46,26 @@ protected void execute(CommandEvent event)
{
if(event.getArgs().isEmpty())
{
event.reply(event.getClient().getError()+" Please include a voice channel or NONE");
event.reply(bot.getError(event)+" Please include a voice channel or NONE");
return;
}
Settings s = event.getClient().getSettingsFor(event.getGuild());
if(event.getArgs().equalsIgnoreCase("none"))
{
s.setVoiceChannel(null);
event.reply(event.getClient().getSuccess()+" Music can now be played in any channel");
event.reply(bot.getSuccess(event)+" Music can now be played in any channel");
}
else
{
List<VoiceChannel> list = FinderUtil.findVoiceChannels(event.getArgs(), event.getGuild());
if(list.isEmpty())
event.reply(event.getClient().getWarning()+" No Voice Channels found matching \""+event.getArgs()+"\"");
event.reply(bot.getWarning(event)+" No Voice Channels found matching \""+event.getArgs()+"\"");
else if (list.size()>1)
event.reply(event.getClient().getWarning()+FormatUtil.listOfVChannels(list, event.getArgs()));
event.reply(bot.getWarning(event)+FormatUtil.listOfVChannels(list, event.getArgs()));
else
{
s.setVoiceChannel(list.get(0));
event.reply(event.getClient().getSuccess()+" Music can now only be played in "+list.get(0).getAsMention());
event.reply(bot.getSuccess(event)+" Music can now only be played in "+list.get(0).getAsMention());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
*/
public class SkipratioCmd extends AdminCommand
{
private final Bot bot;

public SkipratioCmd(Bot bot)
{
this.bot = bot;
this.name = "setskip";
this.help = "sets a server-specific skip percentage";
this.arguments = "<0 - 100>";
Expand All @@ -42,16 +45,16 @@ protected void execute(CommandEvent event)
int val = Integer.parseInt(event.getArgs().endsWith("%") ? event.getArgs().substring(0,event.getArgs().length()-1) : event.getArgs());
if( val < 0 || val > 100)
{
event.replyError("The provided value must be between 0 and 100!");
event.reply(bot.getError(event)+"The provided value must be between 0 and 100!");
return;
}
Settings s = event.getClient().getSettingsFor(event.getGuild());
s.setSkipRatio(val / 100.0);
event.replySuccess("Skip percentage has been set to `" + val + "%` of listeners on *" + event.getGuild().getName() + "*");
event.reply(bot.getSuccess(event)+"Skip percentage has been set to `" + val + "%` of listeners on *" + event.getGuild().getName() + "*");
}
catch(NumberFormatException ex)
{
event.replyError("Please include an integer between 0 and 100 (default is 55). This number is the percentage of listening users that must vote to skip a song.");
event.reply(bot.getError(event)+"Please include an integer between 0 and 100 (default is 55). This number is the percentage of listening users that must vote to skip a song.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public void doCommand(CommandEvent event)
{
if (event.getArgs().isEmpty())
{
event.replyError("You need to mention a user!");
event.reply(bot.getError(event)+"You need to mention a user!");
return;
}

AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
if (handler.getQueue().isEmpty())
{
event.replyError("There is nothing in the queue!");
event.reply(bot.getError(event)+"There is nothing in the queue!");
return;
}

Expand All @@ -68,7 +68,7 @@ public void doCommand(CommandEvent event)

if(found.isEmpty())
{
event.replyError("Unable to find the user!");
event.reply(bot.getError(event)+"Unable to find the user!");
return;
}
else if(found.size()>1)
Expand Down Expand Up @@ -109,11 +109,11 @@ private void removeAllEntries(User target, CommandEvent event)
int count = ((AudioHandler) event.getGuild().getAudioManager().getSendingHandler()).getQueue().removeAll(target.getIdLong());
if (count == 0)
{
event.replyWarning("**"+target.getName()+"** doesn't have any songs in the queue!");
event.reply(bot.getWarning(event)+"**"+target.getName()+"** doesn't have any songs in the queue!");
}
else
{
event.replySuccess("Successfully removed `"+count+"` entries from **"+target.getName()+"**#"+target.getDiscriminator()+".");
event.reply(bot.getSuccess(event)+"Successfully removed `"+count+"` entries from **"+target.getName()+"**#"+target.getDiscriminator()+".");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.audio.RequestMetadata;
import com.jagrosh.jmusicbot.commands.DJCommand;
import net.dv8tion.jda.api.entities.User;

/**
*
Expand All @@ -42,7 +41,7 @@ public void doCommand(CommandEvent event)
{
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
RequestMetadata rm = handler.getRequestMetadata();
event.reply(event.getClient().getSuccess()+" Skipped **"+handler.getPlayer().getPlayingTrack().getInfo().title
event.reply(bot.getSuccess(event)+" Skipped **"+handler.getPlayer().getPlayingTrack().getInfo().title
+"** "+(rm.getOwner() == 0L ? "(autoplay)" : "(requested by **" + rm.user.username + "**)"));
handler.getPlayer().stopTrack();
}
Expand Down
Loading

0 comments on commit 557ac32

Please sign in to comment.