use of net.dv8tion.jda.core.managers.AudioManager in project Ardent by adamint.
the class Volume method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
AudioManager audioManager = guild.getAudioManager();
if (audioManager.isConnected()) {
GuildMusicManager guildMusicManager = getGuildAudioPlayer(guild, channel);
AudioPlayer player = guildMusicManager.player;
if (args.length == 1) {
sendTranslatedMessage("The current player volume is " + player.getVolume(), sendTo(channel, guild), user);
} else {
if (UserUtils.hasTierOnePermissions(user) || EntityGuild.get(guild).isPremium()) {
try {
int volume = Integer.parseInt(args[1]);
player.setVolume(volume);
sendTranslatedMessage("Set player volume to " + volume, sendTo(channel, guild), user);
} catch (NumberFormatException ex) {
sendTranslatedMessage("That's not a number!", channel, user);
}
} else
sendTranslatedMessage("You must be a patron to do this! To help us out and get this perk, pledge even " + "a dollar a month at https://patreon.com/ardent", channel, user);
}
} else
sendTranslatedMessage("I'm not in a voice channel!", channel, user);
}
use of net.dv8tion.jda.core.managers.AudioManager in project Ardent by adamint.
the class Pause 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.isPaused()) {
sendTranslatedMessage("Paused music playback", channel, user);
manager.player.setPaused(true);
} else {
sendTranslatedMessage("Can't pause an already-paused player!", channel, 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 MantaroBot by Mantaro.
the class AudioCmdUtils method connectToVoiceChannel.
static boolean connectToVoiceChannel(GuildMessageReceivedEvent event) {
VoiceChannel userChannel = event.getMember().getVoiceState().getChannel();
if (userChannel == null) {
event.getChannel().sendMessage("❌ **Please join a voice channel!**").queue();
return false;
}
if (!event.getGuild().getMember(event.getJDA().getSelfUser()).hasPermission(userChannel, Permission.VOICE_CONNECT)) {
event.getChannel().sendMessage(":heavy_multiplication_x: I cannot connect to this channel due to the lack of permission.").queue();
return false;
}
VoiceChannel guildMusicChannel = null;
if (MantaroData.db().getGuild(event.getGuild()).getData().getMusicChannel() != null) {
guildMusicChannel = event.getGuild().getVoiceChannelById(MantaroData.db().getGuild(event.getGuild()).getData().getMusicChannel());
}
AudioManager audioManager = event.getGuild().getAudioManager();
if (guildMusicChannel != null) {
if (!userChannel.equals(guildMusicChannel)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I can only play music on channel **" + guildMusicChannel.getName() + "**!").queue();
return false;
}
if (!audioManager.isConnected() && !audioManager.isAttemptingToConnect()) {
audioManager.openAudioConnection(userChannel);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Connected to channel **" + userChannel.getName() + "**!").queue();
}
return true;
}
if (audioManager.isConnected() && !audioManager.getConnectedChannel().equals(userChannel)) {
event.getChannel().sendMessage(String.format(EmoteReference.WARNING + "I'm already connected on channel **%s**! (Use the `move` command to move me to another channel)", audioManager.getConnectedChannel().getName())).queue();
return false;
}
if (audioManager.isAttemptingToConnect() && !audioManager.getQueuedAudioConnection().equals(userChannel)) {
event.getChannel().sendMessage(String.format(EmoteReference.ERROR + "I'm already trying to connect to channel **%s**! (Use the `move` command to move me to another channel)", audioManager.getQueuedAudioConnection().getName())).queue();
return false;
}
if (!audioManager.isConnected() && !audioManager.isAttemptingToConnect()) {
openAudioConnection(event, audioManager, userChannel);
}
return true;
}
use of net.dv8tion.jda.core.managers.AudioManager in project MantaroBot by Mantaro.
the class TrackScheduler method onTrackSchedulerStop.
private void onTrackSchedulerStop() {
getVoteStop().clear();
Guild g = getGuild();
if (g == null)
return;
AudioManager m = g.getAudioManager();
if (m == null)
return;
m.closeAudioConnection();
AudioTrackContext previousTrack;
try {
previousTrack = getPreviousTrack();
if (previousTrack != null && previousTrack.getRequestedChannel() != null && previousTrack.getRequestedChannel().canTalk())
previousTrack.getRequestedChannel().sendMessage(":mega: Finished playing queue! Hope you enjoyed it.").queue(message -> message.delete().queueAfter(20, TimeUnit.SECONDS));
}//fuck
catch (Exception ignored) {
}
}
use of net.dv8tion.jda.core.managers.AudioManager in project Ardent by adamint.
the class VoteToSkip method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
AudioManager audioManager = guild.getAudioManager();
VoiceChannel connected = audioManager.getConnectedChannel();
if (connected != null && connected.getMembers().stream().filter((member -> member.getUser().getId().equals(user.getId()))).collect(Collectors.toList()).size() > 0) {
GuildMusicManager guildMusicManager = getGuildAudioPlayer(guild, channel);
ArdentTrack track = guildMusicManager.scheduler.manager.getCurrentlyPlaying();
if (track == null) {
sendTranslatedMessage("I'm not playing anything right now!", channel, user);
return;
}
if (track.getVotedToSkip().contains(user.getId())) {
sendTranslatedMessage("You already voted to skip >.>", channel, user);
return;
}
track.addSkipVote(user);
if (track.getVotedToSkip().size() >= Math.round(connected.getMembers().size() / 2)) {
sendTranslatedMessage("Half of the people in the channel voted to skip the current song", channel, user);
guildMusicManager.scheduler.manager.nextTrack();
} else
sendTranslatedMessage("Your vote to skip has been recorded. You need half of the users in the channel to force a " + "skip", channel, user);
} else
sendTranslatedMessage("Either I or you aren't in a voice channel", channel, user);
}
Aggregations