use of net.dv8tion.jda.core.managers.AudioManager in project Ardent by adamint.
the class Stop method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
AudioManager audioManager = guild.getAudioManager();
Member member = guild.getMember(user);
if (UserUtils.hasManageServerOrStaff(member) || UserUtils.isBotCommander(member) || (audioManager.isConnected() && audioManager.getConnectedChannel().getMembers().size() == 2)) {
if (audioManager.isConnected()) {
GuildMusicManager manager = getGuildAudioPlayer(guild, channel);
if (manager.player.getPlayingTrack() != null)
manager.player.stopTrack();
manager.scheduler.manager.resetQueue();
getShard().musicManagers.remove(Long.parseLong(guild.getId()));
sendTranslatedMessage("Stopped playback and cleared songs in the queue", sendTo(channel, guild), user);
} else
sendTranslatedMessage("I'm not in a voice channel!", channel, user);
} else
sendTranslatedMessage("You need the Manage Server permission to do this", channel, user);
}
use of net.dv8tion.jda.core.managers.AudioManager in project Ardent by adamint.
the class Play method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length > 1) {
AudioManager audioManager = guild.getAudioManager();
String url = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " ", "");
boolean shouldDeleteMessage = shouldDeleteMessages(guild);
boolean implement = false;
if (!audioManager.isConnected()) {
VoiceChannel success = joinChannel(guild, guild.getMember(user), this, audioManager, channel);
if (success != null) {
loadAndPlay(message, user, this, (TextChannel) channel, url, success, false, true);
implement = true;
}
} else {
loadAndPlay(message, user, this, (TextChannel) sendTo(channel, guild), url, audioManager.getConnectedChannel(), false, true);
implement = true;
}
if (implement) {
if (shouldDeleteMessage) {
try {
message.delete().queue();
} catch (PermissionException ex) {
guild.getOwner().getUser().openPrivateChannel().queue(privateChannel -> {
privateChannel.sendMessage("Auto-deleting music play messages is enabled, " + "but you need to give me the `MANAGE MESSAGES` permission so I can " + "actually delete the messages.").queue();
});
}
}
}
} else
sendTranslatedMessage("You need to include a song name or URL", channel, user);
}
use of net.dv8tion.jda.core.managers.AudioManager in project Ardent by adamint.
the class Recommend method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length > 1) {
AudioManager audioManager = guild.getAudioManager();
if (audioManager.isConnected()) {
VoiceChannel connected = audioManager.getConnectedChannel();
try {
int amount = Integer.parseInt(args[1]);
if (amount <= 0 || amount > 10) {
sendTranslatedMessage("You can only get 10 recommended songs at a time!", channel, user);
return;
}
GuildMusicManager manager = getGuildAudioPlayer(guild, channel);
ArdentTrack ardentTrack = manager.scheduler.manager.getCurrentlyPlaying();
if (ardentTrack == null) {
sendTranslatedMessage("I'm not playing anything right now!", channel, user);
return;
}
String[] nameArgs = StringUtils.removeBracketsParentheses(ardentTrack.getTrack().getInfo().title).split(" ");
StringBuilder name = new StringBuilder();
for (String arg : nameArgs) {
if (!arg.contains(".") && !arg.contains("+") && !arg.contains(":") && !arg.contains("//")) {
name.append(arg);
}
name.append(" ");
}
TrackSearchRequest trackSearchRequest = spotifyApi.searchTracks(name.toString()).build();
try {
Page<Track> tracks = trackSearchRequest.get();
String id = tracks.getItems().get(0).getId();
ArrayList<String> ids = new ArrayList<>();
ids.add(id);
RecommendationsRequest recommendationsRequest = spotifyApi.getRecommendations().tracks(ids).build();
List<Track> recommendations = recommendationsRequest.get();
for (int i = 0; i < amount; i++) {
loadAndPlay(message, user, this, (TextChannel) sendTo(channel, guild), recommendations.get(i).getName(), connected, false, true);
}
} catch (Exception e) {
channel.sendMessage("There were no recommendations available, sorry!").queue();
}
} catch (NumberFormatException e) {
sendTranslatedMessage("That's not a number!", channel, user);
}
} else {
sendTranslatedMessage("I'm not in a voice channel", channel, user);
}
} else
sendTranslatedMessage("Invalid arguments", channel, user);
}
use of net.dv8tion.jda.core.managers.AudioManager in project Ardent by adamint.
the class Remove method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length > 1) {
AudioManager audioManager = guild.getAudioManager();
Member member = guild.getMember(user);
if (audioManager.isConnected()) {
try {
GuildMusicManager manager = getGuildAudioPlayer(guild, channel);
BlockingQueue<ArdentTrack> queue = manager.scheduler.manager.getQueue();
int numberToRemove = Integer.parseInt(args[1]) - 1;
if (numberToRemove >= queue.size() || numberToRemove < 0)
sendTranslatedMessage("Invalid arguments", channel, user);
else {
Iterator<ArdentTrack> iterator = queue.iterator();
int current = 0;
while (iterator.hasNext()) {
ArdentTrack ardentTrack = iterator.next();
AudioTrack track = ardentTrack.getTrack();
String name = track.getInfo().title;
if (current == numberToRemove) {
if (UserUtils.hasManageServerOrStaff(member) || ardentTrack.getAuthor().equalsIgnoreCase(user.getId()) || UserUtils.isBotCommander(member)) {
queue.remove(ardentTrack);
sendTranslatedMessage("Removed {0} from the queue".replace("{0}", name), sendTo(channel, guild), user);
} else {
sendTranslatedMessage("You need to have queued the song or have the Manage Server " + "permission", sendTo(channel, guild), user);
}
}
current++;
}
}
} catch (NumberFormatException ex) {
sendTranslatedMessage("Invalid arguments", channel, user);
}
} else
sendTranslatedMessage("I'm not in a voice channel!", channel, user);
} else
sendTranslatedMessage("That's not a number!", channel, user);
}
use of net.dv8tion.jda.core.managers.AudioManager in project Ardent by adamint.
the class Restart method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
GuildMusicManager musicManager = getGuildAudioPlayer(guild, channel);
ArdentMusicManager player = musicManager.scheduler.manager;
ArdentTrack current = player.getCurrentlyPlaying();
if (current != null) {
AudioManager audioManager = guild.getAudioManager();
if (UserUtils.hasManageServerOrStaff(guild.getMember(user)) || user.getId().equalsIgnoreCase(current.getAuthor()) || UserUtils.isBotCommander(guild.getMember(user)) || (audioManager.isConnected() && audioManager.getConnectedChannel().getMembers().size() == 2)) {
AudioTrack track = current.getTrack();
track.setPosition(0);
sendTranslatedMessage("Restarted the current track", channel, user);
} else {
sendTranslatedMessage("You need to have queued the song or have the Manage Server permission", sendTo(channel, guild), user);
}
} else
sendTranslatedMessage("I'm not playing anything right now!", channel, user);
}
Aggregations