Search in sources :

Example 1 with GuildMusic

use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.

the class NameCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException {
    GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
    if (guildMusic == null || guildMusic.getScheduler().isStopped()) {
        BotUtils.sendMessage(TextUtils.NO_PLAYING_MUSIC, context.getChannel());
        return;
    }
    BotUtils.sendMessage(String.format(Emoji.MUSICAL_NOTE + " Currently playing: **%s**", FormatUtils.formatTrackName(guildMusic.getScheduler().getAudioPlayer().getPlayingTrack().getInfo())), context.getChannel());
}
Also used : GuildMusic(me.shadorc.shadbot.music.GuildMusic)

Example 2 with GuildMusic

use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.

the class PlayCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    if (!context.hasArg()) {
        throw new MissingArgumentException();
    }
    IVoiceChannel botVoiceChannel = context.getClient().getOurUser().getVoiceStateForGuild(context.getGuild()).getChannel();
    IVoiceChannel userVoiceChannel = context.getAuthor().getVoiceStateForGuild(context.getGuild()).getChannel();
    if (botVoiceChannel != null && !botVoiceChannel.equals(userVoiceChannel)) {
        throw new IllegalCmdArgumentException(String.format("I'm currently playing music in voice channel %s" + ", join me before using this command.", botVoiceChannel.mention()));
    }
    if (userVoiceChannel == null) {
        throw new IllegalCmdArgumentException("Join a voice channel before using this command.");
    }
    if (botVoiceChannel == null && !BotUtils.hasPermissions(userVoiceChannel, Permissions.VOICE_CONNECT, Permissions.VOICE_SPEAK)) {
        BotUtils.sendMessage(TextUtils.missingPerm(Permissions.VOICE_CONNECT, Permissions.VOICE_SPEAK), context.getChannel());
        LogUtils.infof("{Guild ID: %d} Shadbot wasn't allowed to connect/speak in a voice channel.", context.getGuild().getLongID());
        return;
    }
    String identifier;
    if (context.getArg().startsWith("soundcloud ")) {
        identifier = AudioLoadResultListener.SC_SEARCH + StringUtils.remove(context.getArg(), "soundcloud ");
    } else if (NetUtils.isValidURL(context.getArg())) {
        identifier = context.getArg();
    } else {
        identifier = AudioLoadResultListener.YT_SEARCH + context.getArg();
    }
    GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
    if (guildMusic != null && guildMusic.isWaiting()) {
        if (guildMusic.getDj().equals(context.getAuthor())) {
            throw new IllegalCmdArgumentException(String.format("(**%s**) You're already selecting a music. " + "Enter a number or use `%scancel` to cancel the selection.", context.getAuthorName(), context.getPrefix()));
        }
        if (identifier.startsWith(AudioLoadResultListener.SC_SEARCH) || identifier.startsWith(AudioLoadResultListener.YT_SEARCH)) {
            BotUtils.sendMessage(String.format(Emoji.HOURGLASS + " **%s** is already selecting a music, please wait for him to finish.", guildMusic.getDj().getName()), context.getChannel());
            return;
        }
    }
    if (guildMusic == null) {
        guildMusic = GuildMusicManager.createGuildMusic(context.getGuild());
    }
    if (guildMusic.getScheduler().getPlaylist().size() >= Config.MAX_PLAYLIST_SIZE - 1 && !PremiumManager.isPremium(context.getGuild(), context.getAuthor())) {
        BotUtils.sendMessage(TextUtils.PLAYLIST_LIMIT_REACHED, context.getChannel());
        return;
    }
    guildMusic.setChannel(context.getChannel());
    AudioLoadResultListener resultListener = new AudioLoadResultListener(guildMusic, context.getAuthor(), userVoiceChannel, identifier, context.getCommandName().endsWith("first"));
    GuildMusicManager.PLAYER_MANAGER.loadItemOrdered(guildMusic, identifier, resultListener);
}
Also used : IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) AudioLoadResultListener(me.shadorc.shadbot.listener.music.AudioLoadResultListener) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) GuildMusic(me.shadorc.shadbot.music.GuildMusic) IVoiceChannel(sx.blah.discord.handle.obj.IVoiceChannel)

Example 3 with GuildMusic

use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.

the class RepeatCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException {
    GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
    if (guildMusic == null || guildMusic.getScheduler().isStopped()) {
        BotUtils.sendMessage(TextUtils.NO_PLAYING_MUSIC, context.getChannel());
        return;
    }
    RepeatMode mode = Utils.getValueOrNull(RepeatMode.class, context.getArg());
    if (context.hasArg() && !RepeatMode.PLAYLIST.equals(mode)) {
        throw new MissingArgumentException();
    }
    // By default, modification are made on song repeat mode
    if (mode == null) {
        mode = RepeatMode.SONG;
    }
    TrackScheduler scheduler = guildMusic.getScheduler();
    scheduler.setRepeatMode(scheduler.getRepeatMode().equals(mode) ? RepeatMode.NONE : mode);
    BotUtils.sendMessage(String.format("%s %sRepetition %s", scheduler.getRepeatMode().equals(RepeatMode.NONE) ? Emoji.PLAY : Emoji.REPEAT, RepeatMode.PLAYLIST.equals(mode) ? "Playlist " : "", scheduler.getRepeatMode().equals(RepeatMode.NONE) ? "disabled" : "enabled"), context.getChannel());
}
Also used : RepeatMode(me.shadorc.shadbot.music.RepeatMode) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) GuildMusic(me.shadorc.shadbot.music.GuildMusic) TrackScheduler(me.shadorc.shadbot.music.TrackScheduler)

Example 4 with GuildMusic

use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.

the class ShuffleCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException {
    GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
    if (guildMusic == null || guildMusic.getScheduler().isStopped()) {
        BotUtils.sendMessage(TextUtils.NO_PLAYING_MUSIC, context.getChannel());
        return;
    }
    guildMusic.getScheduler().shufflePlaylist();
    BotUtils.sendMessage(Emoji.CHECK_MARK + " Playlist shuffled.", context.getChannel());
}
Also used : GuildMusic(me.shadorc.shadbot.music.GuildMusic)

Example 5 with GuildMusic

use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.

the class SkipCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
    if (guildMusic == null || guildMusic.getScheduler().isStopped()) {
        BotUtils.sendMessage(TextUtils.NO_PLAYING_MUSIC, context.getChannel());
        return;
    }
    if (context.hasArg()) {
        Integer num = CastUtils.asIntBetween(context.getArg(), 1, guildMusic.getScheduler().getPlaylist().size());
        if (num == null) {
            throw new IllegalCmdArgumentException(String.format("Number must be between 1 and %d.", guildMusic.getScheduler().getPlaylist().size()));
        }
        guildMusic.getScheduler().skipTo(num);
        return;
    }
    if (guildMusic.getScheduler().nextTrack()) {
        // If the music has been started correctly, we resume it in case the previous music was on pause
        guildMusic.getScheduler().getAudioPlayer().setPaused(false);
    } else {
        guildMusic.end();
    }
}
Also used : IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) GuildMusic(me.shadorc.shadbot.music.GuildMusic)

Aggregations

GuildMusic (me.shadorc.shadbot.music.GuildMusic)15 IllegalCmdArgumentException (me.shadorc.shadbot.exception.IllegalCmdArgumentException)6 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)5 TrackScheduler (me.shadorc.shadbot.music.TrackScheduler)2 IVoiceChannel (sx.blah.discord.handle.obj.IVoiceChannel)2 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)1 AudioLoadResultListener (me.shadorc.shadbot.listener.music.AudioLoadResultListener)1 RepeatMode (me.shadorc.shadbot.music.RepeatMode)1 IGuild (sx.blah.discord.handle.obj.IGuild)1 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)1