Search in sources :

Example 11 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, int position) {
    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).put("position", position);
    // .put("rate_limit_per_user", Math.min(21600, Math.max(rateLimit, 0)));
    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 12 with IGuildTextChannel

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

the class Main method testTextChannelThings.

public static CompletableFuture<Void> testTextChannelThings(IGuild guild, IChannelCategory category) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    AvoidRateLimits();
    CompletableFuture<IGuildTextChannel> f5 = category.createTextChannel("text-channel");
    f5.exceptionally(ex -> {
        logger.severe("Test Failed");
        ex.printStackTrace();
        System.exit(5);
        return null;
    });
    f5.thenAcceptAsync(textchannel -> {
        logger.config("Text Channel Created");
        AvoidRateLimits();
        CompletableFuture<IMessage> f6 = textchannel.sendMessage("content", new RichEmbed("embed").addField().setTimestamp(), new File("README.md"));
        f6.exceptionally(ex -> {
            logger.severe("Test Failed");
            ex.printStackTrace();
            System.exit(6);
            return null;
        });
        f6.thenAcceptAsync(m1 -> {
            logger.config("Message Created");
            AvoidRateLimits();
            CompletableFuture<IMessage> f7 = m1.edit("editted content");
            f7.exceptionally(ex -> {
                logger.severe("Test Failed");
                ex.printStackTrace();
                System.exit(7);
                return null;
            });
            f7.thenAcceptAsync(m2 -> {
                logger.config("Message Edited");
                AvoidRateLimits();
                CompletableFuture<IMessage> f8 = m2.pin();
                f8.exceptionally(ex -> {
                    logger.severe("Test Failed");
                    ex.printStackTrace();
                    System.exit(8);
                    return null;
                });
                f8.thenAcceptAsync(m3 -> {
                    logger.config("Message Pinned");
                    AvoidRateLimits();
                    CompletableFuture<IMessage> f9 = m3.unpin();
                    f9.exceptionally(ex -> {
                        logger.severe("Test Failed");
                        ex.printStackTrace();
                        System.exit(9);
                        return null;
                    });
                    f9.thenAcceptAsync(m4 -> {
                        logger.config("Message Unpinned");
                        AvoidRateLimits();
                        CompletableFuture<Void> f10 = m4.addReaction("🍠");
                        f10.exceptionally(ex -> {
                            logger.severe("Test Failed");
                            ex.printStackTrace();
                            System.exit(10);
                            return null;
                        });
                        f10.thenAcceptAsync(n -> {
                            logger.config("Reaction added");
                            AvoidRateLimits();
                            CompletableFuture<IMessage> f11 = m4.deleteAllReactions();
                            f11.exceptionally(ex -> {
                                logger.severe("Test Failed");
                                ex.printStackTrace();
                                System.exit(11);
                                return null;
                            });
                            f11.thenAcceptAsync(m5 -> {
                                logger.config("Reaction removed");
                                AvoidRateLimits();
                                future.complete(null);
                            });
                        });
                    });
                });
            });
        });
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) IMessage(io.discloader.discloader.entity.message.IMessage) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) RichEmbed(io.discloader.discloader.core.entity.message.embed.RichEmbed) File(java.io.File)

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