Search in sources :

Example 1 with IGuildTextChannel

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

the class Guild method createTextChannel.

@Override
public CompletableFuture<IGuildTextChannel> createTextChannel(String name, IChannelCategory category, IOverwrite... overwrites) {
    CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
    JSONObject data = new JSONObject().put("parent_id", SnowflakeUtil.toString(category)).put("name", name).put("type", 0);
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.POST, Endpoints.guildChannels(getID()), new RESTOptions(data), ChannelJSON.class);
    cf.thenAcceptAsync(channelJSON -> {
        if (channelJSON != null) {
            IGuildTextChannel channel = (IGuildTextChannel) 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) JSONObject(org.json.JSONObject) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel)

Example 2 with IGuildTextChannel

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

the class TextChannel method edit.

@Override
public CompletableFuture<IGuildTextChannel> edit(String name, String topic) {
    if (!this.permissionsOf(guild.getCurrentMember()).hasAny(Permissions.MANAGE_CHANNELS, Permissions.ADMINISTRATOR) && !guild.isOwner()) {
        throw new PermissionsException("Insufficient Permissions");
    }
    if (name.length() < 2 || name.length() > 100) {
        throw new RuntimeException("Name.length() out of bounds [2-100]");
    }
    if (topic.length() > 1024) {
        throw new RuntimeException("Topic.length() out of bounds [" + topic.length() + " > 1024]");
    }
    CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
    JSONObject payload = new JSONObject().put("name", sanitizeChannelName(name)).put("topic", topic);
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new RESTOptions(payload), ChannelJSON.class);
    cf.thenAcceptAsync(data -> {
        IGuildTextChannel channel = (IGuildTextChannel) EntityBuilder.getChannelFactory().buildChannel(data, getLoader(), getGuild(), false);
        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) JSONObject(org.json.JSONObject) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException)

Example 3 with IGuildTextChannel

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

the class TextChannel method setNSFW.

@Override
public CompletableFuture<IGuildTextChannel> setNSFW(boolean nsfw) {
    if (!this.permissionsOf(guild.getCurrentMember()).hasAny(Permissions.MANAGE_CHANNELS, Permissions.ADMINISTRATOR) && !guild.isOwner()) {
        throw new PermissionsException("Insufficient Permissions");
    }
    CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
    JSONObject payload = new JSONObject().put("nsfw", nsfw);
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.PATCH, Endpoints.channel(getID()), new RESTOptions(payload), ChannelJSON.class);
    cf.thenAcceptAsync(data -> {
        IGuildTextChannel channel = (IGuildTextChannel) EntityBuilder.getChannelFactory().buildChannel(data, getLoader(), getGuild(), false);
        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) JSONObject(org.json.JSONObject) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException)

Example 4 with IGuildTextChannel

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

the class ChannelCategory method createTextChannel.

@Override
public CompletableFuture<IGuildTextChannel> createTextChannel(String name, IOverwrite... overwrites) {
    CompletableFuture<IGuildTextChannel> future = new CompletableFuture<>();
    ChannelPayload data = new ChannelPayload(name, ChannelTypes.TEXT, overwrites);
    CompletableFuture<ChannelJSON> cf = loader.rest.request(Methods.POST, Endpoints.guildChannels(getGuild().getID()), new RESTOptions(data), ChannelJSON.class);
    cf.thenAcceptAsync(channelJSON -> {
        if (channelJSON != null) {
            IGuildTextChannel channel = (IGuildTextChannel) 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) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel)

Example 5 with IGuildTextChannel

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

the class Listener method GuildCreate.

@Override
public void GuildCreate(GuildCreateEvent e) {
    if (e.getGuild().getName().equals(Main.guildName)) {
        Main.guild = e.getGuild();
        IGuildTextChannel channel = Main.guild.getTextChannelByName("general");
        if (channel != null) {
            channel.createInvite().onSuccess(invite -> {
                Main.logger.warning("Invite code for the test guild: " + invite.getCode());
                try {
                    if (Main.appOwner != null) {
                        Main.appOwner.sendMessage("Testing Area: " + Endpoints.inviteLink(invite.getCode())).get();
                    }
                } catch (InterruptedException | ExecutionException e1) {
                    e1.printStackTrace();
                }
            }).onException(ex -> {
                ex.printStackTrace();
            }).execute();
        }
    }
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) Endpoints(io.discloader.discloader.network.util.Endpoints) GuildCreateEvent(io.discloader.discloader.common.event.guild.GuildCreateEvent) ReadyEvent(io.discloader.discloader.common.event.ReadyEvent) EventListenerAdapter(io.discloader.discloader.common.event.EventListenerAdapter) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

IGuildTextChannel (io.discloader.discloader.entity.channel.IGuildTextChannel)12 ChannelJSON (io.discloader.discloader.network.json.ChannelJSON)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)7 JSONObject (org.json.JSONObject)6 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)5 IMessage (io.discloader.discloader.entity.message.IMessage)3 RichEmbed (io.discloader.discloader.core.entity.message.embed.RichEmbed)2 File (java.io.File)2 ExecutionException (java.util.concurrent.ExecutionException)2 EventListenerAdapter (io.discloader.discloader.common.event.EventListenerAdapter)1 ReadyEvent (io.discloader.discloader.common.event.ReadyEvent)1 GuildCreateEvent (io.discloader.discloader.common.event.guild.GuildCreateEvent)1 AccountTypeException (io.discloader.discloader.common.exceptions.AccountTypeException)1 GuildSyncException (io.discloader.discloader.common.exceptions.GuildSyncException)1 MissmatchException (io.discloader.discloader.common.exceptions.MissmatchException)1 UnauthorizedException (io.discloader.discloader.common.exceptions.UnauthorizedException)1 IGuildChannel (io.discloader.discloader.entity.channel.IGuildChannel)1 IGuildVoiceChannel (io.discloader.discloader.entity.channel.IGuildVoiceChannel)1 IGuildEmoji (io.discloader.discloader.entity.guild.IGuildEmoji)1