use of net.dv8tion.jda.core.entities.GuildVoiceState in project MantaroBot by Mantaro.
the class VoiceChannelListener method onLeave.
private void onLeave(VoiceChannel vc) {
GuildVoiceState vs = vc.getGuild().getSelfMember().getVoiceState();
if (validate(vs))
return;
if (isAlone(vc)) {
GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(vc.getGuild());
if (gmm != null) {
TrackScheduler scheduler = gmm.getTrackScheduler();
if (scheduler != null && scheduler.getCurrentTrack() != null && scheduler.getRequestedChannelParsed() != null) {
TextChannel tc = scheduler.getRequestedChannelParsed();
if (tc.canTalk()) {
tc.sendMessage(EmoteReference.THINKING + "I'll leave **" + vc.getName() + "** in 2 minutes because I was left all alone :<").queue(m -> m.delete().queueAfter(30, TimeUnit.SECONDS));
}
}
gmm.setAwaitingDeath(true);
gmm.scheduleLeave();
gmm.getAudioPlayer().setPaused(true);
}
}
}
use of net.dv8tion.jda.core.entities.GuildVoiceState in project MantaroBot by Mantaro.
the class VoiceChannelListener method onJoin.
private void onJoin(VoiceChannel vc) {
GuildVoiceState vs = vc.getGuild().getSelfMember().getVoiceState();
if (validate(vs))
return;
if (!isAlone(vc)) {
GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(vc.getGuild());
if (gmm != null) {
TrackScheduler scheduler = gmm.getTrackScheduler();
if (scheduler.getCurrentTrack() != null) {
if (gmm.isAwaitingDeath()) {
TextChannel tc = scheduler.getRequestedChannelParsed();
if (tc.canTalk()) {
tc.sendMessage(EmoteReference.POPPER + "Resuming playback because someone joined!").queue();
}
}
}
gmm.cancelLeave();
gmm.setAwaitingDeath(false);
gmm.getAudioPlayer().setPaused(false);
}
}
}
use of net.dv8tion.jda.core.entities.GuildVoiceState in project MantaroBot by Mantaro.
the class VoiceChannelListener method onGuildVoiceMute.
private void onGuildVoiceMute(GuildVoiceMuteEvent event) {
if (event.getMember().getUser().getIdLong() != event.getJDA().getSelfUser().getIdLong())
return;
GuildVoiceState vs = event.getVoiceState();
if (validate(vs))
return;
GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
if (gmm != null) {
if (event.isMuted()) {
TrackScheduler scheduler = gmm.getTrackScheduler();
if (scheduler.getCurrentTrack() != null && scheduler.getRequestedChannelParsed() != null) {
TextChannel tc = scheduler.getRequestedChannelParsed();
if (tc.canTalk()) {
tc.sendMessage(EmoteReference.SAD + "Pausing player because I got muted :(").queue();
}
gmm.getAudioPlayer().setPaused(true);
}
} else {
if (!isAlone(vs.getChannel())) {
if (gmm.getTrackScheduler().getCurrentTrack() != null) {
gmm.getAudioPlayer().setPaused(false);
}
}
}
}
}
use of net.dv8tion.jda.core.entities.GuildVoiceState 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) {
}
});
}
Aggregations