use of com.jagrosh.jmusicbot.audio.AudioHandler in project MusicBot by jagrosh.
the class Bot method shutdown.
public void shutdown() {
if (shuttingDown)
return;
shuttingDown = true;
threadpool.shutdownNow();
if (jda.getStatus() != JDA.Status.SHUTTING_DOWN) {
jda.getGuilds().stream().forEach(g -> {
g.getAudioManager().closeAudioConnection();
AudioHandler ah = (AudioHandler) g.getAudioManager().getSendingHandler();
if (ah != null) {
ah.stopAndClear();
ah.getPlayer().destroy();
nowplaying.updateTopic(g.getIdLong(), ah, true);
}
});
jda.shutdown();
}
if (gui != null)
gui.dispose();
System.exit(0);
}
use of com.jagrosh.jmusicbot.audio.AudioHandler in project MusicBot by jagrosh.
the class VolumeCmd method doCommand.
@Override
public void doCommand(CommandEvent event) {
AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
Settings settings = event.getClient().getSettingsFor(event.getGuild());
int volume = handler.getPlayer().getVolume();
if (event.getArgs().isEmpty()) {
event.reply(FormatUtil.volumeIcon(volume) + " Current volume is `" + volume + "`");
} else {
int nvolume;
try {
nvolume = Integer.parseInt(event.getArgs());
} catch (NumberFormatException e) {
nvolume = -1;
}
if (nvolume < 0 || nvolume > 150)
event.reply(event.getClient().getError() + " Volume must be a valid integer between 0 and 150!");
else {
handler.getPlayer().setVolume(nvolume);
settings.setVolume(nvolume);
event.reply(FormatUtil.volumeIcon(nvolume) + " Volume changed from `" + volume + "` to `" + nvolume + "`");
}
}
}
use of com.jagrosh.jmusicbot.audio.AudioHandler in project MusicBot by jagrosh.
the class LyricsCmd method doCommand.
@Override
public void doCommand(CommandEvent event) {
String title;
if (event.getArgs().isEmpty()) {
AudioHandler sendingHandler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
if (sendingHandler.isMusicPlaying(event.getJDA()))
title = sendingHandler.getPlayer().getPlayingTrack().getInfo().title;
else {
event.replyError("There must be music playing to use that!");
return;
}
} else
title = event.getArgs();
event.getChannel().sendTyping().queue();
client.getLyrics(title).thenAccept(lyrics -> {
if (lyrics == null) {
event.replyError("Lyrics for `" + title + "` could not be found!" + (event.getArgs().isEmpty() ? " Try entering the song name manually (`lyrics [song name]`)" : ""));
return;
}
EmbedBuilder eb = new EmbedBuilder().setAuthor(lyrics.getAuthor()).setColor(event.getSelfMember().getColor()).setTitle(lyrics.getTitle(), lyrics.getURL());
if (lyrics.getContent().length() > 15000) {
event.replyWarning("Lyrics for `" + title + "` found but likely not correct: " + lyrics.getURL());
} else if (lyrics.getContent().length() > 2000) {
String content = lyrics.getContent().trim();
while (content.length() > 2000) {
int index = content.lastIndexOf("\n\n", 2000);
if (index == -1)
index = content.lastIndexOf("\n", 2000);
if (index == -1)
index = content.lastIndexOf(" ", 2000);
if (index == -1)
index = 2000;
event.reply(eb.setDescription(content.substring(0, index).trim()).build());
content = content.substring(index).trim();
eb.setAuthor(null).setTitle(null, null);
}
event.reply(eb.setDescription(content).build());
} else
event.reply(eb.setDescription(lyrics.getContent()).build());
});
}
use of com.jagrosh.jmusicbot.audio.AudioHandler in project MusicBot by jagrosh.
the class PlayCmd method doCommand.
@Override
public void doCommand(CommandEvent event) {
if (event.getArgs().isEmpty() && event.getMessage().getAttachments().isEmpty()) {
AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
if (handler.getPlayer().getPlayingTrack() != null && handler.getPlayer().isPaused()) {
if (DJCommand.checkDJPermission(event)) {
handler.getPlayer().setPaused(false);
event.replySuccess("Resumed **" + handler.getPlayer().getPlayingTrack().getInfo().title + "**.");
} else
event.replyError("Only DJs can unpause the player!");
return;
}
StringBuilder builder = new StringBuilder(event.getClient().getWarning() + " Play Commands:\n");
builder.append("\n`").append(event.getClient().getPrefix()).append(name).append(" <song title>` - plays the first result from Youtube");
builder.append("\n`").append(event.getClient().getPrefix()).append(name).append(" <URL>` - plays the provided song, playlist, or stream");
for (Command cmd : children) builder.append("\n`").append(event.getClient().getPrefix()).append(name).append(" ").append(cmd.getName()).append(" ").append(cmd.getArguments()).append("` - ").append(cmd.getHelp());
event.reply(builder.toString());
return;
}
String args = event.getArgs().startsWith("<") && event.getArgs().endsWith(">") ? event.getArgs().substring(1, event.getArgs().length() - 1) : event.getArgs().isEmpty() ? event.getMessage().getAttachments().get(0).getUrl() : event.getArgs();
event.reply(loadingEmoji + " Loading... `[" + args + "]`", m -> bot.getPlayerManager().loadItemOrdered(event.getGuild(), args, new ResultHandler(m, event, false)));
}
use of com.jagrosh.jmusicbot.audio.AudioHandler in project MusicBot by jagrosh.
the class MusicCommand method execute.
@Override
protected void execute(CommandEvent event) {
Settings settings = event.getClient().getSettingsFor(event.getGuild());
TextChannel tchannel = settings.getTextChannel(event.getGuild());
if (tchannel != null && !event.getTextChannel().equals(tchannel)) {
try {
event.getMessage().delete().queue();
} catch (PermissionException ignore) {
}
event.replyInDm(event.getClient().getError() + " You can only use that command in " + tchannel.getAsMention() + "!");
return;
}
// no point constantly checking for this later
bot.getPlayerManager().setUpHandler(event.getGuild());
if (bePlaying && !((AudioHandler) event.getGuild().getAudioManager().getSendingHandler()).isMusicPlaying(event.getJDA())) {
event.reply(event.getClient().getError() + " There must be music playing to use that!");
return;
}
if (beListening) {
VoiceChannel current = event.getGuild().getSelfMember().getVoiceState().getChannel();
if (current == null)
current = settings.getVoiceChannel(event.getGuild());
GuildVoiceState userState = event.getMember().getVoiceState();
if (!userState.inVoiceChannel() || userState.isDeafened() || (current != null && !userState.getChannel().equals(current))) {
event.replyError("You must be listening in " + (current == null ? "a voice channel" : current.getAsMention()) + " to use that!");
return;
}
VoiceChannel afkChannel = userState.getGuild().getAfkChannel();
if (afkChannel != null && afkChannel.equals(userState.getChannel())) {
event.replyError("You cannot use that command in an AFK channel!");
return;
}
if (!event.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
try {
event.getGuild().getAudioManager().openAudioConnection(userState.getChannel());
} catch (PermissionException ex) {
event.reply(event.getClient().getError() + " I am unable to connect to " + userState.getChannel().getAsMention() + "!");
return;
}
}
}
doCommand(event);
}
Aggregations