Search in sources :

Example 11 with GuildPlayer

use of fredboat.audio.player.GuildPlayer in project FredBoat by Frederikam.

the class NowplayingCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getExisting(context.guild);
    if (player != null && player.isPlaying()) {
        AudioTrackContext atc = player.getPlayingTrack();
        AudioTrack at = atc.getTrack();
        EmbedBuilder builder;
        if (at instanceof YoutubeAudioTrack) {
            builder = getYoutubeEmbed(atc, player, (YoutubeAudioTrack) at);
        } else if (at instanceof SoundCloudAudioTrack) {
            builder = getSoundcloudEmbed(atc, player, (SoundCloudAudioTrack) at);
        } else if (at instanceof HttpAudioTrack && at.getIdentifier().contains("gensokyoradio.net")) {
            // Special handling for GR
            builder = getGensokyoRadioEmbed(context);
        } else if (at instanceof HttpAudioTrack) {
            builder = getHttpEmbed(atc, player, (HttpAudioTrack) at);
        } else if (at instanceof BandcampAudioTrack) {
            builder = getBandcampResponse(atc, player, (BandcampAudioTrack) at);
        } else if (at instanceof TwitchStreamAudioTrack) {
            builder = getTwitchEmbed(atc, (TwitchStreamAudioTrack) at);
        } else if (at instanceof BeamAudioTrack) {
            builder = getBeamEmbed(atc, (BeamAudioTrack) at);
        } else {
            builder = getDefaultEmbed(atc, player, at);
        }
        Member requester = atc.getMember() != null ? atc.getMember() : context.guild.getSelfMember();
        builder = CentralMessaging.addNpFooter(builder, requester);
        context.reply(builder.build());
    } else {
        context.reply(context.i18n("npNotPlaying"));
    }
}
Also used : TwitchStreamAudioTrack(com.sedmelluq.discord.lavaplayer.source.twitch.TwitchStreamAudioTrack) HttpAudioTrack(com.sedmelluq.discord.lavaplayer.source.http.HttpAudioTrack) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) GuildPlayer(fredboat.audio.player.GuildPlayer) AudioTrackContext(fredboat.audio.queue.AudioTrackContext) YoutubeAudioTrack(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack) HttpAudioTrack(com.sedmelluq.discord.lavaplayer.source.http.HttpAudioTrack) BeamAudioTrack(com.sedmelluq.discord.lavaplayer.source.beam.BeamAudioTrack) YoutubeAudioTrack(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack) SoundCloudAudioTrack(com.sedmelluq.discord.lavaplayer.source.soundcloud.SoundCloudAudioTrack) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) BandcampAudioTrack(com.sedmelluq.discord.lavaplayer.source.bandcamp.BandcampAudioTrack) TwitchStreamAudioTrack(com.sedmelluq.discord.lavaplayer.source.twitch.TwitchStreamAudioTrack) BeamAudioTrack(com.sedmelluq.discord.lavaplayer.source.beam.BeamAudioTrack) SoundCloudAudioTrack(com.sedmelluq.discord.lavaplayer.source.soundcloud.SoundCloudAudioTrack) BandcampAudioTrack(com.sedmelluq.discord.lavaplayer.source.bandcamp.BandcampAudioTrack) Member(net.dv8tion.jda.core.entities.Member)

Example 12 with GuildPlayer

use of fredboat.audio.player.GuildPlayer in project FredBoat by Frederikam.

the class ForwardCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getExisting(context.guild);
    if (player == null || player.isQueueEmpty()) {
        context.replyWithName(context.i18n("unpauseQueueEmpty"));
        return;
    }
    if (!context.hasArguments()) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    long t;
    try {
        t = TextUtils.parseTimeString(context.args[0]);
    } catch (IllegalStateException e) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    AudioTrackContext atc = player.getPlayingTrack();
    AudioTrack at = atc.getTrack();
    // Ensure bounds
    t = Math.max(0, t);
    t = Math.min(atc.getEffectiveDuration(), t);
    player.seekTo(player.getPosition() + t);
    context.reply(context.i18nFormat("fwdSuccess", TextUtils.escapeAndDefuse(atc.getEffectiveTitle()), TextUtils.formatTime(t)));
}
Also used : GuildPlayer(fredboat.audio.player.GuildPlayer) AudioTrackContext(fredboat.audio.queue.AudioTrackContext) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 13 with GuildPlayer

use of fredboat.audio.player.GuildPlayer in project FredBoat by Frederikam.

the class RewindCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getExisting(context.guild);
    if (player == null || player.isQueueEmpty()) {
        context.replyWithName(context.i18n("queueEmpty"));
        return;
    }
    if (!context.hasArguments()) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    long t;
    try {
        t = TextUtils.parseTimeString(context.args[0]);
    } catch (IllegalStateException e) {
        HelpCommand.sendFormattedCommandHelp(context);
        return;
    }
    long currentPosition = player.getPosition();
    // Ensure bounds
    t = Math.max(0, t);
    t = Math.min(currentPosition, t);
    player.seekTo(currentPosition - t);
    context.reply(context.i18nFormat("rewSuccess", TextUtils.escapeAndDefuse(player.getPlayingTrack().getEffectiveTitle()), TextUtils.formatTime(t)));
}
Also used : GuildPlayer(fredboat.audio.player.GuildPlayer)

Example 14 with GuildPlayer

use of fredboat.audio.player.GuildPlayer in project FredBoat by Frederikam.

the class JoinCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getOrCreate(context.guild);
    VoiceChannel vc = player.getUserCurrentVoiceChannel(context.invoker);
    try {
        player.joinChannel(vc);
        if (vc != null) {
            context.reply(context.i18nFormat("joinJoining", vc.getName()));
        }
    } catch (IllegalStateException ex) {
        if (vc != null) {
            context.reply(context.i18nFormat("joinErrorAlreadyJoining", vc.getName()));
        } else {
            throw ex;
        }
    }
}
Also used : GuildPlayer(fredboat.audio.player.GuildPlayer) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel)

Example 15 with GuildPlayer

use of fredboat.audio.player.GuildPlayer in project FredBoat by Frederikam.

the class PlayCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    if (!context.invoker.getVoiceState().inVoiceChannel()) {
        context.reply(context.i18n("playerUserNotInChannel"));
        return;
    }
    if (!playerLimiter.checkLimitResponsive(context, Launcher.getBotController().getPlayerRegistry()))
        return;
    if (!context.msg.getAttachments().isEmpty()) {
        GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getOrCreate(context.guild);
        for (Attachment atc : context.msg.getAttachments()) {
            player.queue(atc.getUrl(), context);
        }
        player.setPause(false);
        return;
    }
    if (!context.hasArguments()) {
        GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getExisting(context.guild);
        handleNoArguments(context, player);
        return;
    }
    if (TextUtils.isSplitSelect(context.rawArgs)) {
        SelectCommand.select(context, videoSelectionCache);
        return;
    }
    String url = StringUtils.strip(context.args[0], "<>");
    // Search youtube for videos and let the user select a video
    if (!url.startsWith("http") && !url.startsWith(FILE_PREFIX)) {
        searchForVideos(context);
        return;
    }
    if (url.startsWith(FILE_PREFIX)) {
        // LocalAudioSourceManager does not manage this itself
        url = url.replaceFirst(FILE_PREFIX, "");
    }
    GuildPlayer player = Launcher.getBotController().getPlayerRegistry().getOrCreate(context.guild);
    player.queue(url, context);
    player.setPause(false);
    context.deleteMessage();
}
Also used : GuildPlayer(fredboat.audio.player.GuildPlayer) Attachment(net.dv8tion.jda.core.entities.Message.Attachment)

Aggregations

GuildPlayer (fredboat.audio.player.GuildPlayer)29 AudioTrackContext (fredboat.audio.queue.AudioTrackContext)9 ArrayList (java.util.ArrayList)5 Member (net.dv8tion.jda.core.entities.Member)5 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)5 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)4 TextChannel (net.dv8tion.jda.core.entities.TextChannel)4 Command (fredboat.commandmeta.abs.Command)3 CommandContext (fredboat.commandmeta.abs.CommandContext)3 Launcher (fredboat.main.Launcher)3 Context (fredboat.messaging.internal.Context)3 TextUtils (fredboat.util.TextUtils)3 Nonnull (javax.annotation.Nonnull)3 Guild (net.dv8tion.jda.core.entities.Guild)3 JSONObject (org.json.JSONObject)3 PlayerRegistry (fredboat.audio.player.PlayerRegistry)2 SplitAudioTrackContext (fredboat.audio.queue.SplitAudioTrackContext)2 MessagingException (fredboat.commandmeta.MessagingException)2 ICommandRestricted (fredboat.commandmeta.abs.ICommandRestricted)2 PermissionLevel (fredboat.definitions.PermissionLevel)2