Search in sources :

Example 1 with IGuildVoiceChannel

use of io.discloader.discloader.entity.channel.IGuildVoiceChannel in project DiscLoader by R3alCl0ud.

the class ChannelCategory method createVoiceChannel.

@Override
public CompletableFuture<IGuildVoiceChannel> createVoiceChannel(String name, IOverwrite... overwrites) {
    CompletableFuture<IGuildVoiceChannel> future = new CompletableFuture<>();
    ChannelPayload data = new ChannelPayload(name, ChannelTypes.VOICE, overwrites);
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.POST, Endpoints.guildChannels(getGuild().getID()), new RESTOptions(data), ChannelJSON.class);
    cf.thenAcceptAsync(channelJSON -> {
        if (channelJSON != null) {
            IGuildVoiceChannel channel = (IGuildVoiceChannel) EntityBuilder.getChannelFactory().buildChannel(channelJSON, getLoader(), getGuild(), false);
            if (channel != null)
                future.complete(channel);
        }
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) ChannelPayload(io.discloader.discloader.network.rest.payloads.ChannelPayload) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel)

Example 2 with IGuildVoiceChannel

use of io.discloader.discloader.entity.channel.IGuildVoiceChannel 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 3 with IGuildVoiceChannel

use of io.discloader.discloader.entity.channel.IGuildVoiceChannel in project DiscLoader by R3alCl0ud.

the class VoiceChannel method edit.

/**
 * Changes the channels settings
 *
 * @param name
 *            The new name for the channel
 * @param position
 *            The new position for the channel
 * @param bitrate
 *            The new {@link #bitrate}
 * @param userLimit
 *            The new {@link #userLimit}
 * @return A Future that completes with a voice channel if successful
 */
public CompletableFuture<IGuildVoiceChannel> edit(String name, int position, int bitrate, int userLimit) {
    CompletableFuture<IGuildVoiceChannel> future = new CompletableFuture<>();
    EditChannel d = new EditChannel(name, null, position, bitrate, userLimit);
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new RESTOptions(d), ChannelJSON.class);
    cf.thenAcceptAsync(channelJSON -> {
        if (channelJSON != null) {
            IGuildVoiceChannel channel = (IGuildVoiceChannel) EntityBuilder.getChannelFactory().buildChannel(channelJSON, getLoader(), getGuild(), false);
            if (channel != null)
                future.complete(channel);
        }
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) EditChannel(io.discloader.discloader.entity.sendable.EditChannel) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel)

Example 4 with IGuildVoiceChannel

use of io.discloader.discloader.entity.channel.IGuildVoiceChannel in project DiscLoader by R3alCl0ud.

the class Guild method setup.

/**
 * Sets up a guild with data from the gateway
 *
 * @param data The guild's data
 */
@Override
public void setup(GuildJSON data) {
    try {
        name = data.name;
        icon = data.icon;
        iconURL = icon != null ? Endpoints.guildIcon(getID(), icon) : null;
        ownerID = SnowflakeUtil.parse(data.owner_id);
        memberCount = data.member_count;
        voiceRegion = new VoiceRegion(data.region);
        splashHash = data.splash;
        if (data.roles != null) {
            for (RoleJSON role : data.roles) {
                addRole(role);
            }
        }
        if (data.members != null && data.members.length > 0) {
            for (MemberJSON member : data.members) {
                addMember(member);
            }
        }
        if (data.channels != null && data.channels.length > 0) {
            for (ChannelJSON channelData : data.channels) {
                IGuildChannel chan = (IGuildChannel) EntityRegistry.addChannel(channelData, getLoader(), this);
                if (chan instanceof IGuildTextChannel)
                    textChannels.put(chan.getID(), (IGuildTextChannel) chan);
                else if (chan instanceof IGuildVoiceChannel)
                    voiceChannels.put(chan.getID(), (IGuildVoiceChannel) chan);
            }
        }
        if (data.presences != null && data.presences.length > 0) {
            for (PresenceJSON presence : data.presences) {
                this.setPresence(presence);
            }
        }
        if (data.emojis != null && data.emojis.length > 0) {
            for (EmojiJSON e : data.emojis) {
                this.guildEmojis.put(SnowflakeUtil.parse(e.id), new GuildEmoji(e, this));
            }
        }
        if (data.voice_states != null && data.voice_states.length > 0) {
            for (VoiceStateJSON v : data.voice_states) {
                this.rawStates.put(SnowflakeUtil.parse(v.user_id), new VoiceState(v, this));
            }
        }
        this.available = data.unavailable == true ? false : true;
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : VoiceState(io.discloader.discloader.entity.voice.VoiceState) IGuildChannel(io.discloader.discloader.entity.channel.IGuildChannel) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) GuildSyncException(io.discloader.discloader.common.exceptions.GuildSyncException) UnauthorizedException(io.discloader.discloader.common.exceptions.UnauthorizedException) MissmatchException(io.discloader.discloader.common.exceptions.MissmatchException) AccountTypeException(io.discloader.discloader.common.exceptions.AccountTypeException) RoleJSON(io.discloader.discloader.network.json.RoleJSON) ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) VoiceRegion(io.discloader.discloader.entity.guild.VoiceRegion) VoiceStateJSON(io.discloader.discloader.network.json.VoiceStateJSON) IGuildEmoji(io.discloader.discloader.entity.guild.IGuildEmoji) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) PresenceJSON(io.discloader.discloader.network.json.PresenceJSON) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel) MemberJSON(io.discloader.discloader.network.json.MemberJSON) EmojiJSON(io.discloader.discloader.network.json.EmojiJSON)

Example 5 with IGuildVoiceChannel

use of io.discloader.discloader.entity.channel.IGuildVoiceChannel in project DiscLoader by R3alCl0ud.

the class Guild method createVoiceChannel.

@Override
public CompletableFuture<IGuildVoiceChannel> createVoiceChannel(String name, int bitRate, int userLimit, IChannelCategory category, IOverwrite... overwrites) {
    CompletableFuture<IGuildVoiceChannel> future = new CompletableFuture<>();
    if (!hasPermission(Permissions.MANAGE_CHANNELS)) {
        PermissionsException ex = new PermissionsException("Insufficient Permissions");
        future.completeExceptionally(ex);
        // return early
        return future;
    }
    // normalize
    bitRate = Math.max(8, Math.min(96, bitRate)) * 1000;
    // normalize
    userLimit = Math.max(0, Math.min(99, userLimit));
    ChannelPayload data = new ChannelPayload(name, bitRate, userLimit, overwrites);
    if (category != null && getChannelCategoryByID(category.getID()) != null) {
        data.setParent(category);
    }
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.POST, Endpoints.guildChannels(getID()), new RESTOptions(data), ChannelJSON.class);
    cf.thenAcceptAsync(channelJSON -> {
        if (channelJSON != null) {
            IGuildVoiceChannel channel = (IGuildVoiceChannel) EntityBuilder.getChannelFactory().buildChannel(channelJSON, getLoader(), this, false);
            if (channel != null)
                future.complete(channel);
        }
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) ChannelPayload(io.discloader.discloader.network.rest.payloads.ChannelPayload) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException)

Aggregations

IGuildVoiceChannel (io.discloader.discloader.entity.channel.IGuildVoiceChannel)7 CompletableFuture (java.util.concurrent.CompletableFuture)6 ChannelJSON (io.discloader.discloader.network.json.ChannelJSON)5 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)4 UnauthorizedException (io.discloader.discloader.common.exceptions.UnauthorizedException)3 IGuildTextChannel (io.discloader.discloader.entity.channel.IGuildTextChannel)3 IOException (java.io.IOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 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 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)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 IGuild (io.discloader.discloader.entity.guild.IGuild)2