use of io.discloader.discloader.entity.voice.VoiceConnection in project DiscLoader by R3alCl0ud.
the class VoiceChannel method join.
@Override
public CompletableFuture<VoiceConnection> join() {
if (EntityRegistry.getVoiceConnectionByID(guild.getID()) != null) {
VoiceConnection connection = EntityRegistry.getVoiceConnectionByID(guild.getID());
connection.updateChannel(this);
return CompletableFuture.completedFuture(connection);
}
CompletableFuture<VoiceConnection> future = new CompletableFuture<VoiceConnection>();
VoiceConnection connection = new VoiceConnection(this, future);
EntityRegistry.addVoiceConnection(connection);
return future;
}
use of io.discloader.discloader.entity.voice.VoiceConnection in project DiscLoader by R3alCl0ud.
the class IGuildVoiceChannel method join.
@Override
public default CompletableFuture<VoiceConnection> join() {
CompletableFuture<VoiceConnection> future = new CompletableFuture<>();
if (EntityRegistry.getVoiceConnectionByID(getGuild().getID()) != null) {
EntityRegistry.getVoiceConnectionByID(getGuild().getID()).disconnect().thenAcceptAsync(action -> {
VoiceConnection connection = new VoiceConnection(this, future);
EntityRegistry.addVoiceConnection(connection);
});
return future;
}
VoiceConnection connection = new VoiceConnection(this, future);
EntityRegistry.addVoiceConnection(connection);
return future;
}
use of io.discloader.discloader.entity.voice.VoiceConnection in project DiscLoader by R3alCl0ud.
the class VoiceServerUpdate method handle.
public void handle(SocketPacket packet) {
try {
VoiceServerUpdateJSON data = gson.fromJson(gson.toJson(packet.d), VoiceServerUpdateJSON.class);
VoiceConnection connection = EntityRegistry.getVoiceConnectionByID(SnowflakeUtil.parse(data.guild_id));
if (connection != null) {
connection.endpointReceived(data.endpoint, data.token);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of io.discloader.discloader.entity.voice.VoiceConnection in project DiscLoader by R3alCl0ud.
the class VoiceStateUpdate method handle.
@Override
public void handle(SocketPacket packet) {
String d = this.gson.toJson(packet.d);
VoiceStateJSON data = this.gson.fromJson(d, VoiceStateJSON.class);
IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
if (guild.getMember(data.user_id) == null)
return;
VoiceState currentState = new VoiceState(data, guild);
VoiceState oldState = guild.getVoiceStates().get(SnowflakeUtil.parse(data.user_id));
VoiceConnection connection = EntityRegistry.getVoiceConnectionByID(guild.getID());
if (connection != null && SnowflakeUtil.toString(loader.user).equals(data.user_id)) {
connection.setSessionID(data.session_id);
connection.setStateUpdated(true);
connection.setVoiceChannel(currentState.channel);
}
guild.updateVoiceState(currentState);
if (shouldEmit()) {
if (currentState.channel != null && (oldState != null && oldState.channel != null)) {
loader.emit(new VoiceSwitchEvent(currentState.member, oldState.channel));
} else if (currentState.channel != null) {
loader.emit(new VoiceJoinEvent(currentState.member));
} else if (oldState != null && oldState.channel != null) {
loader.emit(new VoiceLeaveEvent(currentState.member, oldState.channel));
}
if (oldState != null) {
VoiceStateUpdateEvent event = new VoiceStateUpdateEvent(oldState, currentState);
loader.emit(event);
}
}
}
use of io.discloader.discloader.entity.voice.VoiceConnection in project DiscLoader by R3alCl0ud.
the class Main method testVoiceThings.
public static CompletableFuture<Void> testVoiceThings(IGuild guild, IChannelCategory category) {
CompletableFuture<Void> future = new CompletableFuture<>();
CompletableFuture<IGuildVoiceChannel> f13 = category.createVoiceChannel("voice-channel");
f13.exceptionally(ex -> {
logger.severe("Test Failed");
ex.printStackTrace();
System.exit(13);
return null;
});
f13.thenAcceptAsync(voicechannel -> {
AvoidRateLimits();
CompletableFuture<VoiceConnection> f14 = voicechannel.join();
f14.exceptionally(ex -> {
logger.severe("Test Failed");
ex.printStackTrace();
System.exit(14);
return null;
});
f14.thenAcceptAsync(voiceconnection -> {
voiceconnection.addListener(new VoiceEventAdapter() {
@Override
public void end(AudioTrack track, AudioTrackEndReason endReason) {
logger.info("Track Finished Playing");
if (endReason == AudioTrackEndReason.LOAD_FAILED) {
logger.severe("Test Failed\nFailed to load the audio track.");
System.exit(15);
return;
}
CompletableFuture<VoiceConnection> f16 = voiceconnection.disconnect();
f16.exceptionally(ex -> {
logger.severe("Test Failed");
ex.printStackTrace();
System.exit(16);
return null;
});
f16.thenAcceptAsync(vc -> {
logger.config("Disconnected From VC");
future.complete(null);
});
}
});
voiceconnection.play("./audio_test.wav");
});
});
return future;
}
Aggregations