Search in sources :

Example 6 with BotCommand

use of com.discordbolt.api.command.BotCommand in project BoltBot by DiscordBolt.

the class PlaylistCommand method playlistViewCommand.

@BotCommand(command = { "playlist", "view" }, module = MusicModule.MODULE, aliases = "pl", allowPM = true, description = "View a playlist's details", usage = "Playlist view {name}", allowedChannels = "music", minArgs = 2, maxArgs = 100)
public static void playlistViewCommand(CommandContext cc) throws CommandException {
    if (cc.getArgCount() == 2) {
        Playlist playlist = MusicModule.getPlaylistManager().getSelectedPlaylist(cc.getAuthor().getLongID());
        if (playlist == null)
            throw new CommandStateException(NO_PLAYLIST_SELECTED);
        cc.replyWith(playlist.toEmbed());
    } else {
        Optional<Playlist> playlist = MusicModule.getPlaylistManager().getPlaylist(getPlaylistName(cc));
        if (!playlist.isPresent())
            throw new CommandArgumentException(NO_SUCH_PLAYLIST);
        cc.replyWith(playlist.get().toEmbed());
    }
}
Also used : Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 7 with BotCommand

use of com.discordbolt.api.command.BotCommand in project BoltBot by DiscordBolt.

the class PlaylistCommand method playlistShareCommand.

@BotCommand(command = { "playlist", "share" }, module = MusicModule.MODULE, aliases = "pl", allowPM = true, description = "Give another user access to add/remove songs", usage = "Playlist share [@User]", allowedChannels = "music", args = 3)
public static void playlistShareCommand(CommandContext cc) throws CommandException {
    Playlist selectedPlaylist = MusicModule.getPlaylistManager().getSelectedPlaylist(cc.getAuthor().getLongID());
    if (selectedPlaylist == null)
        throw new CommandStateException(NO_PLAYLIST_SELECTED);
    if (cc.getMessage().getMentions().size() != 1) {
        cc.sendUsage();
        return;
    }
    selectedPlaylist.addContributor(cc.getAuthor(), cc.getMessage().getMentions().get(0));
    cc.replyWith("Successfully added " + cc.getMessage().getMentions().get(0).getName() + " as a contributor to playlist " + selectedPlaylist.getTitle());
}
Also used : Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 8 with BotCommand

use of com.discordbolt.api.command.BotCommand in project BoltBot by DiscordBolt.

the class QueueCommand method queueCommand.

@BotCommand(command = "queue", module = MusicModule.MODULE, description = "Show the currently queued songs", usage = "Queue", allowedChannels = "music", args = 1)
public static void queueCommand(CommandContext cc) throws CommandException {
    List<AudioTrack> queue = MusicModule.getVoiceManager().getQueue(cc.getGuild());
    AudioTrack nowPlaying = MusicModule.getVoiceManager().getNowPlaying(cc.getGuild());
    if (nowPlaying == null)
        throw new CommandStateException("The queue is empty! Play something with !Play");
    final long totalTime = MusicModule.getVoiceManager().getQueue(cc.getGuild()).stream().map(AudioTrack::getDuration).reduce(0L, (x, y) -> x + y) + MusicModule.getVoiceManager().getNowPlaying(cc.getGuild()).getDuration();
    EmbedBuilder embed = new EmbedBuilder();
    embed.withTitle(":clock1030: Queue Length");
    embed.withDescription(TimeUtil.getFormattedTime(totalTime));
    embed.withColor(MusicModule.EMBED_COLOR);
    StringBuilder songs = new StringBuilder();
    int i = 2;
    songs.append("***1. ").append(nowPlaying.getInfo().title).append("***").append('\n');
    for (AudioTrack audioTrack : queue) {
        if ((songs.length() + audioTrack.getInfo().title.length()) >= 975 && (i - 1) < queue.size()) {
            songs.append("\n");
            songs.append("    ***... and ").append(queue.size() - (i - 1)).append(" more***");
            break;
        }
        songs.append(i++).append(". ").append(audioTrack.getInfo().title).append('\n');
    }
    embed.appendField(":arrow_forward: Now Playing", songs.length() > 1 ? songs.toString() : "\n", true);
    cc.replyWith(embed.build());
}
Also used : CommandException(com.discordbolt.api.command.exceptions.CommandException) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) List(java.util.List) TimeUtil(com.discordbolt.boltbot.utils.TimeUtil) MusicModule(com.discordbolt.boltbot.modules.music.MusicModule) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) CommandContext(com.discordbolt.api.command.CommandContext) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) BotCommand(com.discordbolt.api.command.BotCommand) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) BotCommand(com.discordbolt.api.command.BotCommand)

Example 9 with BotCommand

use of com.discordbolt.api.command.BotCommand in project BoltBot by DiscordBolt.

the class SeenModule method seenCommand.

@BotCommand(command = "seen", module = "Seen Module", description = "See when the user was last online.", usage = "Seen [User]", minArgs = 2, maxArgs = 100)
public static void seenCommand(CommandContext cc) throws CommandException {
    IUser searchUser = UserUtil.findUser(cc.getMessage(), cc.getMessageContent().indexOf(' ') + 1);
    String name = cc.getMessageContent().substring(cc.getMessageContent().indexOf(' ') + 1, cc.getMessageContent().length());
    if (searchUser == null)
        throw new CommandArgumentException("Sorry, I could not find '" + name + "'.");
    Optional<UserData> userData = UserData.getById(searchUser.getLongID());
    if (!userData.isPresent() || userData.get().getLastStatusChange() == null)
        throw new CommandArgumentException("Sorry, I could not find \"" + name + "\".");
    cc.replyWith(searchUser.getName() + " has been " + userData.get().getStatus().name().replace("dnd", "do not disturb").toLowerCase() + " since " + format(userData.get().getLastStatusChange()) + '.');
}
Also used : UserData(com.discordbolt.boltbot.system.mysql.data.persistent.UserData) IUser(sx.blah.discord.handle.obj.IUser) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 10 with BotCommand

use of com.discordbolt.api.command.BotCommand 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.");
}
Also used : CommandPermissionException(com.discordbolt.api.command.exceptions.CommandPermissionException) TagData(com.discordbolt.boltbot.system.mysql.data.persistent.TagData) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) BotCommand(com.discordbolt.api.command.BotCommand)

Aggregations

BotCommand (com.discordbolt.api.command.BotCommand)20 CommandStateException (com.discordbolt.api.command.exceptions.CommandStateException)12 CommandArgumentException (com.discordbolt.api.command.exceptions.CommandArgumentException)11 Playlist (com.discordbolt.boltbot.modules.music.playlists.Playlist)9 IUser (sx.blah.discord.handle.obj.IUser)3 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)3 TagData (com.discordbolt.boltbot.system.mysql.data.persistent.TagData)2 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)2 CommandContext (com.discordbolt.api.command.CommandContext)1 CommandException (com.discordbolt.api.command.exceptions.CommandException)1 CommandPermissionException (com.discordbolt.api.command.exceptions.CommandPermissionException)1 MusicModule (com.discordbolt.boltbot.modules.music.MusicModule)1 UserData (com.discordbolt.boltbot.system.mysql.data.persistent.UserData)1 TimeUtil (com.discordbolt.boltbot.utils.TimeUtil)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)1 IMessage (sx.blah.discord.handle.obj.IMessage)1 IRole (sx.blah.discord.handle.obj.IRole)1 IVoiceChannel (sx.blah.discord.handle.obj.IVoiceChannel)1