Skip to content

Commit

Permalink
Merge pull request jagrosh#308 from MichailiK/pr/feature/config/aliases
Browse files Browse the repository at this point in the history
Add configurable aliases for all commands
  • Loading branch information
jagrosh authored Nov 9, 2019
2 parents 11c9b00 + 179f447 commit a4f13ca
Show file tree
Hide file tree
Showing 35 changed files with 134 additions and 31 deletions.
17 changes: 16 additions & 1 deletion src/main/java/com/jagrosh/jmusicbot/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public class BotConfig
private long owner, maxSeconds;
private OnlineStatus status;
private Game game;

private Config aliases;


private boolean valid = false;

public BotConfig(Prompt prompt)
Expand Down Expand Up @@ -94,6 +96,7 @@ public void load()
useEval = config.getBoolean("eval");
maxSeconds = config.getLong("maxtime");
playlistsFolder = config.getString("playlistsfolder");
aliases = config.getConfig("aliases");
dbots = owner == 113156185389092864L;

// we may need to write a new config file
Expand Down Expand Up @@ -300,4 +303,16 @@ public boolean isTooLong(AudioTrack track)
return false;
return Math.round(track.getDuration()/1000.0) > maxSeconds;
}

public String[] getAliases(String command)
{
try
{
return aliases.getStringList(command).toArray(new String[0]);
}
catch(NullPointerException | ConfigException.Missing e)
{
return new String[0];
}
}
}
16 changes: 8 additions & 8 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static void main(String[] args)
.setGuildSettingsManager(settings)
.addCommands(aboutCommand,
new PingCommand(),
new SettingsCmd(),
new SettingsCmd(bot),

new LyricsCmd(bot),
new NowplayingCmd(bot),
Expand All @@ -122,17 +122,17 @@ public static void main(String[] args)
new StopCmd(bot),
new VolumeCmd(bot),

new SetdjCmd(),
new SettcCmd(),
new SetvcCmd(),
new SetdjCmd(bot),
new SettcCmd(bot),
new SetvcCmd(bot),

new AutoplaylistCmd(bot),
new DebugCmd(bot),
new PlaylistCmd(bot),
new SetavatarCmd(),
new SetgameCmd(),
new SetnameCmd(),
new SetstatusCmd(),
new SetavatarCmd(bot),
new SetgameCmd(bot),
new SetnameCmd(bot),
new SetstatusCmd(bot),
new ShutdownCmd(bot)
);
if(config.useEval())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.List;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.commons.utils.FinderUtil;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.AdminCommand;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil;
Expand All @@ -29,11 +30,12 @@
*/
public class SetdjCmd extends AdminCommand
{
public SetdjCmd()
public SetdjCmd(Bot bot)
{
this.name = "setdj";
this.help = "sets the DJ role for certain music commands";
this.arguments = "<rolename|NONE>";
this.aliases = bot.getConfig().getAliases(this.name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.List;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.commons.utils.FinderUtil;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.AdminCommand;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil;
Expand All @@ -29,11 +30,12 @@
*/
public class SettcCmd extends AdminCommand
{
public SettcCmd()
public SettcCmd(Bot bot)
{
this.name = "settc";
this.help = "sets the text channel for music commands";
this.arguments = "<channel|NONE>";
this.aliases = bot.getConfig().getAliases(this.name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.List;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.commons.utils.FinderUtil;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.AdminCommand;
import com.jagrosh.jmusicbot.settings.Settings;
import com.jagrosh.jmusicbot.utils.FormatUtil;
Expand All @@ -29,11 +30,12 @@
*/
public class SetvcCmd extends AdminCommand
{
public SetvcCmd()
public SetvcCmd(Bot bot)
{
this.name = "setvc";
this.help = "sets the voice channel for playing music";
this.arguments = "<channel|NONE>";
this.aliases = bot.getConfig().getAliases(this.name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ForceRemoveCmd(Bot bot)
this.name = "forceremove";
this.help = "removes all entries by a user from the queue";
this.arguments = "<user>";
this.aliases = new String[]{"forcedelete", "modremove", "moddelete"};
this.aliases = bot.getConfig().getAliases(this.name);
this.beListening = false;
this.bePlaying = true;
this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ForceskipCmd(Bot bot)
super(bot);
this.name = "forceskip";
this.help = "skips the current song";
this.aliases = new String[]{"modskip"};
this.aliases = bot.getConfig().getAliases(this.name);
this.bePlaying = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public MoveTrackCmd(Bot bot)
this.name = "movetrack";
this.help = "move a track in the current queue to a different position";
this.arguments = "<from> <to>";
this.aliases = new String[]{"move"};
this.aliases = bot.getConfig().getAliases(this.name);
this.bePlaying = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public PauseCmd(Bot bot)
super(bot);
this.name = "pause";
this.help = "pauses the current song";
this.aliases = bot.getConfig().getAliases(this.name);
this.bePlaying = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public PlaynextCmd(Bot bot)
this.name = "playnext";
this.arguments = "<title|URL>";
this.help = "plays a single song next";
this.aliases = bot.getConfig().getAliases(this.name);
this.beListening = true;
this.bePlaying = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public RepeatCmd(Bot bot)
this.name = "repeat";
this.help = "re-adds music to the queue when finished";
this.arguments = "[on|off]";
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public SkiptoCmd(Bot bot)
this.name = "skipto";
this.help = "skips to the specified song";
this.arguments = "<position>";
this.aliases = new String[]{"jumpto"};
this.aliases = bot.getConfig().getAliases(this.name);
this.bePlaying = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public StopCmd(Bot bot)
super(bot);
this.name = "stop";
this.help = "stops the current song and clears the queue";
this.aliases = bot.getConfig().getAliases(this.name);
this.bePlaying = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public VolumeCmd(Bot bot)
{
super(bot);
this.name = "volume";
this.aliases = new String[]{"vol"};
this.aliases = bot.getConfig().getAliases(this.name);
this.help = "sets or shows volume";
this.arguments = "[0-150]";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.settings.Settings;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.MessageBuilder;
Expand All @@ -32,11 +33,11 @@ public class SettingsCmd extends Command
{
private final static String EMOJI = "\uD83C\uDFA7"; // 🎧

public SettingsCmd()
public SettingsCmd(Bot bot)
{
this.name = "settings";
this.help = "shows the bots settings";
this.aliases = new String[]{"status"};
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public LyricsCmd(Bot bot)
this.name = "lyrics";
this.arguments = "[song name]";
this.help = "shows the lyrics to the currently-playing song";
this.aliases = bot.getConfig().getAliases(this.name);
this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS};
this.bePlaying = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public NowplayingCmd(Bot bot)
super(bot);
this.name = "nowplaying";
this.help = "shows the song that is currently playing";
this.aliases = new String[]{"np","current"};
this.aliases = bot.getConfig().getAliases(this.name);
this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public PlayCmd(Bot bot)
this.name = "play";
this.arguments = "<title|URL|subcommand>";
this.help = "plays the provided song";
this.aliases = bot.getConfig().getAliases(this.name);
this.beListening = true;
this.bePlaying = false;
this.children = new Command[]{new PlaylistCmd(bot)};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public PlaylistsCmd(Bot bot)
super(bot);
this.name = "playlists";
this.help = "shows the available playlists";
this.aliases = new String[]{"pls"};
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = true;
this.beListening = false;
this.beListening = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public QueueCmd(Bot bot)
this.name = "queue";
this.help = "shows the current queue";
this.arguments = "[pagenum]";
this.aliases = new String[]{"list"};
this.aliases = bot.getConfig().getAliases(this.name);
this.bePlaying = true;
this.botPermissions = new Permission[]{Permission.MESSAGE_ADD_REACTION,Permission.MESSAGE_EMBED_LINKS};
builder = new Paginator.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public RemoveCmd(Bot bot)
this.name = "remove";
this.help = "removes a song from the queue";
this.arguments = "<position|ALL>";
this.aliases = new String[]{"delete"};
this.aliases = bot.getConfig().getAliases(this.name);
this.beListening = true;
this.bePlaying = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public SCSearchCmd(Bot bot)
this.searchPrefix = "scsearch:";
this.name = "scsearch";
this.help = "searches Soundcloud for a provided query";
this.aliases = new String[]{};
this.aliases = bot.getConfig().getAliases(this.name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public SearchCmd(Bot bot)
super(bot);
this.searchingEmoji = bot.getConfig().getSearching();
this.name = "search";
this.aliases = new String[]{"ytsearch"};
this.aliases = bot.getConfig().getAliases(this.name);
this.arguments = "<query>";
this.help = "searches Youtube for a provided query";
this.beListening = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public ShuffleCmd(Bot bot)
super(bot);
this.name = "shuffle";
this.help = "shuffles songs you have added";
this.aliases = bot.getConfig().getAliases(this.name);
this.beListening = true;
this.bePlaying = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public SkipCmd(Bot bot)
super(bot);
this.name = "skip";
this.help = "votes to skip the current song";
this.aliases = new String[]{"voteskip"};
this.aliases = bot.getConfig().getAliases(this.name);
this.beListening = true;
this.bePlaying = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public AutoplaylistCmd(Bot bot)
this.name = "autoplaylist";
this.arguments = "<name|NONE>";
this.help = "sets the default playlist for the server";
this.aliases = bot.getConfig().getAliases(this.name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public DebugCmd(Bot bot)
this.bot = bot;
this.name = "debug";
this.help = "shows debug info";
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public EvalCmd(Bot bot)
this.bot = bot;
this.name = "eval";
this.help = "evaluates nashorn code";
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.OwnerCommand;
import com.jagrosh.jmusicbot.commands.owner.AutoplaylistCmd;
import com.jagrosh.jmusicbot.playlist.PlaylistLoader.Playlist;

/**
Expand All @@ -38,6 +37,7 @@ public PlaylistCmd(Bot bot)
this.name = "playlist";
this.arguments = "<append|delete|make|setdefault>";
this.help = "playlist management";
this.aliases = bot.getConfig().getAliases(this.name);
this.children = new OwnerCommand[]{
new ListCmd(),
new AppendlistCmd(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.InputStream;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.commands.OwnerCommand;
import com.jagrosh.jmusicbot.utils.OtherUtil;
import net.dv8tion.jda.core.entities.Icon;
Expand All @@ -28,11 +29,12 @@
*/
public class SetavatarCmd extends OwnerCommand
{
public SetavatarCmd()
public SetavatarCmd(Bot bot)
{
this.name = "setavatar";
this.help = "sets the avatar of the bot";
this.arguments = "<url>";
this.aliases = bot.getConfig().getAliases(this.name);
this.guildOnly = false;
}

Expand Down
Loading

0 comments on commit a4f13ca

Please sign in to comment.