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"));
}
}
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)));
}
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)));
}
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;
}
}
}
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();
}
Aggregations