Search in sources :

Example 1 with VoiceEventAdapter

use of io.discloader.discloader.entity.voice.VoiceEventAdapter 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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Options(io.discloader.discloader.common.start.Options) Gson(com.google.gson.Gson) RichEmbed(io.discloader.discloader.core.entity.message.embed.RichEmbed) DiscLoader(io.discloader.discloader.common.DiscLoader) DLLogger(io.discloader.discloader.common.logger.DLLogger) AudioTrackEndReason(com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason) IGuild(io.discloader.discloader.entity.guild.IGuild) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel) IUser(io.discloader.discloader.entity.user.IUser) Files(java.nio.file.Files) VoiceEventAdapter(io.discloader.discloader.entity.voice.VoiceEventAdapter) VoiceConnection(io.discloader.discloader.entity.voice.VoiceConnection) IOException(java.io.IOException) Logger(java.util.logging.Logger) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) Paths(java.nio.file.Paths) CommandRegistry(io.discloader.discloader.common.registry.CommandRegistry) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) UnauthorizedException(io.discloader.discloader.common.exceptions.UnauthorizedException) IChannelCategory(io.discloader.discloader.entity.channel.IChannelCategory) IMessage(io.discloader.discloader.entity.message.IMessage) DLOptions(io.discloader.discloader.common.DLOptions) VoiceConnection(io.discloader.discloader.entity.voice.VoiceConnection) CompletableFuture(java.util.concurrent.CompletableFuture) AudioTrackEndReason(com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason) VoiceEventAdapter(io.discloader.discloader.entity.voice.VoiceEventAdapter) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel)

Example 2 with VoiceEventAdapter

use of io.discloader.discloader.entity.voice.VoiceEventAdapter in project DiscLoader by R3alCl0ud.

the class Main method runVoiceChannelTest.

public static void runVoiceChannelTest() throws Exception {
    CompletableFuture<VoiceConnection> future = new CompletableFuture<>();
    IGuildVoiceChannel channel = guild.getVoiceChannelByName("General");
    VoiceConnection voiceconnection = channel.join().get();
    voiceconnection.addListener(new VoiceEventAdapter() {

        @Override
        public void end(AudioTrack track, AudioTrackEndReason endReason) {
            if (endReason == AudioTrackEndReason.LOAD_FAILED) {
                logger.severe("Test Failed\nFailed to load the audio track.");
            } else {
                logger.info("Track Finished Playing");
            }
            CompletableFuture<VoiceConnection> f16 = voiceconnection.disconnect();
            f16.exceptionally(ex -> {
                future.completeExceptionally(ex);
                return null;
            });
            f16.thenAcceptAsync(vc -> {
                logger.config("Disconnected From VC");
                future.complete(vc);
            });
        }
    });
    voiceconnection.play("https://soundcloud.com/r3alcl0ud/guardians-of-animus");
    future.get();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Options(io.discloader.discloader.common.start.Options) Gson(com.google.gson.Gson) RichEmbed(io.discloader.discloader.core.entity.message.embed.RichEmbed) DiscLoader(io.discloader.discloader.common.DiscLoader) DLLogger(io.discloader.discloader.common.logger.DLLogger) AudioTrackEndReason(com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason) IGuild(io.discloader.discloader.entity.guild.IGuild) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel) IUser(io.discloader.discloader.entity.user.IUser) Files(java.nio.file.Files) VoiceEventAdapter(io.discloader.discloader.entity.voice.VoiceEventAdapter) VoiceConnection(io.discloader.discloader.entity.voice.VoiceConnection) IOException(java.io.IOException) Logger(java.util.logging.Logger) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) Paths(java.nio.file.Paths) CommandRegistry(io.discloader.discloader.common.registry.CommandRegistry) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) UnauthorizedException(io.discloader.discloader.common.exceptions.UnauthorizedException) IChannelCategory(io.discloader.discloader.entity.channel.IChannelCategory) IMessage(io.discloader.discloader.entity.message.IMessage) DLOptions(io.discloader.discloader.common.DLOptions) VoiceConnection(io.discloader.discloader.entity.voice.VoiceConnection) CompletableFuture(java.util.concurrent.CompletableFuture) AudioTrackEndReason(com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason) VoiceEventAdapter(io.discloader.discloader.entity.voice.VoiceEventAdapter) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel)

Aggregations

Gson (com.google.gson.Gson)2 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)2 AudioTrackEndReason (com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason)2 DLOptions (io.discloader.discloader.common.DLOptions)2 DiscLoader (io.discloader.discloader.common.DiscLoader)2 UnauthorizedException (io.discloader.discloader.common.exceptions.UnauthorizedException)2 DLLogger (io.discloader.discloader.common.logger.DLLogger)2 CommandRegistry (io.discloader.discloader.common.registry.CommandRegistry)2 Options (io.discloader.discloader.common.start.Options)2 RichEmbed (io.discloader.discloader.core.entity.message.embed.RichEmbed)2 IChannelCategory (io.discloader.discloader.entity.channel.IChannelCategory)2 IGuildTextChannel (io.discloader.discloader.entity.channel.IGuildTextChannel)2 IGuildVoiceChannel (io.discloader.discloader.entity.channel.IGuildVoiceChannel)2 IGuild (io.discloader.discloader.entity.guild.IGuild)2 IMessage (io.discloader.discloader.entity.message.IMessage)2 IUser (io.discloader.discloader.entity.user.IUser)2 VoiceConnection (io.discloader.discloader.entity.voice.VoiceConnection)2 VoiceEventAdapter (io.discloader.discloader.entity.voice.VoiceEventAdapter)2 File (java.io.File)2 IOException (java.io.IOException)2