use of com.sedmelluq.discord.lavaplayer.player.AudioPlayer 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 com.sedmelluq.discord.lavaplayer.player.AudioPlayer in project Ardent by adamint.
the class Music method checkMusicConnections.
public static void checkMusicConnections() {
for (Shard shard : ShardManager.getShards()) {
shard.executorService.scheduleAtFixedRate(() -> {
try {
for (Guild guild : shard.jda.getGuilds()) {
GuildMusicManager manager = getGuildAudioPlayer(guild, null, shard);
if (manager != null) {
GuildVoiceState voiceState = guild.getSelfMember().getVoiceState();
if (voiceState.inVoiceChannel()) {
TextChannel channel = manager.scheduler.manager.getChannel();
if (channel == null)
channel = guild.getPublicChannel();
if (channel != null) {
if (channel.canTalk()) {
VoiceChannel voiceChannel = voiceState.getChannel();
AudioPlayer player = manager.player;
if (voiceState.isGuildMuted()) {
shard.help.sendTranslatedMessage("Pausing player now because I'm muted", channel, null);
player.setPaused(true);
}
if (voiceChannel.getMembers().size() == 1 && !EntityGuild.get(guild).isPremium()) {
shard.help.sendTranslatedMessage("Left {0} because no one was in the channel!".replace("{0}", voiceChannel.getName()), channel, null);
guild.getAudioManager().closeAudioConnection();
}
}
}
}
}
}
} catch (Exception ex) {
new BotException(ex);
}
}, 5, 5, TimeUnit.MINUTES);
}
}
use of com.sedmelluq.discord.lavaplayer.player.AudioPlayer in project MantaroBot by Mantaro.
the class VoiceLeave method run.
@Override
public void run() {
MantaroBot.getInstance().getAudioManager().getMusicManagers().forEach((guildId, manager) -> {
try {
Guild guild = MantaroBot.getInstance().getGuildById(guildId);
if (guild == null)
return;
GuildVoiceState voiceState = guild.getSelfMember().getVoiceState();
if (voiceState == null)
return;
if (voiceState.inVoiceChannel()) {
TextChannel channel = guild.getPublicChannel();
if (channel != null) {
if (channel.canTalk()) {
VoiceChannel voiceChannel = voiceState.getChannel();
AudioPlayer player = manager.getAudioPlayer();
GuildMusicManager mm = MantaroBot.getInstance().getAudioManager().getMusicManager(guild);
if (player == null || mm == null || voiceChannel == null)
return;
if (mm.getTrackScheduler().getCurrentTrack().getRequestedChannel() != null) {
channel = mm.getTrackScheduler().getCurrentTrack().getRequestedChannel();
}
if (voiceState.isGuildMuted()) {
channel.sendMessage(EmoteReference.SAD + "Pausing player because I got muted :(").queue();
player.setPaused(true);
}
if (voiceChannel.getMembers().size() == 1) {
channel.sendMessage(EmoteReference.THINKING + "I decided to leave **" + voiceChannel.getName() + "** " + "because I was left all " + "alone :<").queue();
if (mm.getTrackScheduler().getAudioPlayer().getPlayingTrack() != null) {
mm.getTrackScheduler().getAudioPlayer().getPlayingTrack().stop();
mm.getTrackScheduler().getQueue().clear();
mm.getTrackScheduler().next(true);
} else {
guild.getAudioManager().closeAudioConnection();
}
}
}
}
}
} catch (Exception ignored) {
}
});
}
use of com.sedmelluq.discord.lavaplayer.player.AudioPlayer in project Ardent by adamint.
the class StuckVoiceConnection method run.
@Override
public void run() {
for (Shard shard : getShards()) {
for (Guild guild : shard.jda.getGuilds()) {
GuildMusicManager guildMusicManager = Music.getGuildAudioPlayer(guild, null, shard);
AudioPlayer player = guildMusicManager.player;
if (!player.isPaused() && guild.getAudioManager().getConnectedChannel() != null && guild.getAudioManager().getConnectedChannel().getMembers().size() > 1) {
AudioTrack playingTrack = player.getPlayingTrack();
if (playingTrack != null) {
long position = playingTrack.getPosition();
if (position == 0 || (position > 0 && !guild.getAudioManager().isConnected())) {
String textChannelId = voiceChannelsAtZeroDuration.get(guild.getId());
if (textChannelId == null) {
ArdentMusicManager ardentMusicManager = guildMusicManager.scheduler.manager;
TextChannel channel = ardentMusicManager.getChannel();
voiceChannelsAtZeroDuration.put(guild.getId(), channel.getId());
} else {
TextChannel channel = guild.getTextChannelById(textChannelId);
ArdentMusicManager ardentMusicManager = guildMusicManager.scheduler.manager;
if (ardentMusicManager != null) {
List<ArdentTrack> queue = ardentMusicManager.getQueueAsList();
shard.musicManagers.remove(Long.parseLong(guild.getId()));
GuildMusicManager manager = Music.getGuildAudioPlayer(guild, channel, shard);
for (ArdentTrack track : queue) {
manager.scheduler.manager.addToQueue(new ArdentTrack(track.getAuthor(), track.getAddedFrom(), track.getTrack().makeClone()));
}
} else
shard.musicManagers.remove(Long.parseLong(guild.getId()));
if (channel == null)
channel = guild.getPublicChannel();
try {
channel.sendMessage("I detected that my audio connection was stuck and reset my player. #BlameDiscord").queue();
} catch (Exception e) {
new BotException(e);
}
}
}
} else {
voiceChannelsAtZeroDuration.remove(guild.getId());
}
}
}
}
}
Aggregations