use of com.discordbolt.api.command.exceptions.CommandStateException in project BoltBot by DiscordBolt.
the class Playlist method removeSong.
public void removeSong(IUser requester, int index) throws CommandPermissionException, CommandStateException {
if (!(ownerID.equals(requester.getLongID()) || contributors.contains(requester.getLongID())))
throw new CommandPermissionException("You are not allowed to remove songs from " + this.getTitle() + ".");
if (index < 0 || index >= songs.size())
throw new CommandStateException(index + " is not a valid index!");
songs.remove(getSongIDs().get(index));
PlaylistManager.writePlaylistFile(this);
}
use of com.discordbolt.api.command.exceptions.CommandStateException in project BoltBot by DiscordBolt.
the class DJ method starSong.
public void starSong(AudioTrack track, IUser user) throws CommandStateException, CommandPermissionException {
if (track == null || user == null)
throw new CommandStateException("That track can not be found.");
Playlist playlist = MusicModule.getPlaylistManager().getSelectedPlaylist(user.getLongID());
if (playlist == null)
throw new CommandStateException("You must have a selected playlist to save a song!");
playlist.addSong(user, track.getInfo().uri);
}
use of com.discordbolt.api.command.exceptions.CommandStateException in project BoltBot by DiscordBolt.
the class DJ method skip.
public boolean skip(IUser requester) throws CommandStateException {
if (votesToSkip.contains(requester))
throw new CommandStateException("You have already voted to skip the current song!");
votesToSkip.add(requester);
// Filter out users who have voted but are no longer connected to the voice channel
votesToSkip.removeIf(u -> u.getVoiceStateForGuild(guild).getChannel() != getVoiceChannel());
if ((double) votesToSkip.size() / (double) (getVoiceChannel().getConnectedUsers().size() - 1) >= MusicModule.VOTE_SKIP_PERCENT) {
skipCurrentTrack();
votesToSkip.clear();
return true;
}
return false;
}
use of com.discordbolt.api.command.exceptions.CommandStateException in project BoltBot by DiscordBolt.
the class TagModule method tagEditCommand.
@BotCommand(command = { "tag", "edit" }, description = "Edits a Tag", usage = "Tag edit [tag]", module = "Tag Module", minArgs = 4, maxArgs = 100)
public static void tagEditCommand(CommandContext cc) throws CommandException {
Optional<TagData> tag = TagData.getById(cc.getGuild().getLongID(), cc.getArgument(2));
if (!tag.isPresent())
throw new CommandStateException("That tag does not exist!");
if (tag.get().getUserId() != cc.getAuthor().getLongID())
throw new CommandPermissionException("You do not have permission to edit this tag!");
tag.get().setContent(cc.combineArgs(3, cc.getArgCount() - 1));
cc.replyWith("Successfully updated your tag. Use `" + getTagPrefix(cc.getGuild()) + tag.get().getName() + "` to view it.");
}
use of com.discordbolt.api.command.exceptions.CommandStateException in project BoltBot by DiscordBolt.
the class PlaylistCommand method playlistAddCommand.
@BotCommand(command = { "playlist", "add" }, module = MusicModule.MODULE, aliases = "pl", allowPM = true, description = "Add a song to your selected playlist", usage = "Playlist add [URL]", allowedChannels = "music", args = 3)
public static void playlistAddCommand(CommandContext cc) throws CommandException {
Playlist selectedPlaylist = MusicModule.getPlaylistManager().getSelectedPlaylist(cc.getAuthor().getLongID());
if (selectedPlaylist == null)
throw new CommandStateException(NO_PLAYLIST_SELECTED);
String title = selectedPlaylist.addSong(cc.getAuthor(), cc.getArgument(2));
cc.replyWith("Added \"" + title + "\" to " + selectedPlaylist.getTitle());
}
Aggregations