Search in sources :

Example 16 with RESTOptions

use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.

the class Guild method createCategory.

@Override
public CompletableFuture<IChannelCategory> createCategory(String name) {
    CompletableFuture<IChannelCategory> future = new CompletableFuture<>();
    JSONObject chanSet = new JSONObject().put("name", name).put("type", 4);
    loader.rest.request(Methods.POST, Endpoints.guildChannels(getID()), new RESTOptions(chanSet), ChannelJSON.class).thenAcceptAsync(d -> {
        IChannel channel = EntityBuilder.getChannelFactory().buildChannel(d, loader, this, false);
        if (channel instanceof IChannelCategory)
            future.complete((IChannelCategory) channel);
    });
    return future;
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) CompletableFuture(java.util.concurrent.CompletableFuture) IChannel(io.discloader.discloader.entity.channel.IChannel) JSONObject(org.json.JSONObject) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IChannelCategory(io.discloader.discloader.entity.channel.IChannelCategory)

Example 17 with RESTOptions

use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.

the class Guild method getAuditLog.

@Override
public CompletableFuture<IAuditLog> getAuditLog(IAuditLogEntry before) {
    CompletableFuture<IAuditLog> future = new CompletableFuture<>();
    JSONObject params = new JSONObject().put("before", SnowflakeUtil.asString(before));
    CompletableFuture<AuditLogJSON> cf = loader.rest.request(Methods.GET, Endpoints.auditLogs(getID()), new RESTOptions(params), AuditLogJSON.class);
    cf.thenAcceptAsync(al -> {
        future.complete(new AuditLog(this, al));
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JSONObject(org.json.JSONObject) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IAuditLog(io.discloader.discloader.entity.auditlog.IAuditLog) AuditLogJSON(io.discloader.discloader.network.json.AuditLogJSON) AuditLog(io.discloader.discloader.core.entity.auditlog.AuditLog) IAuditLog(io.discloader.discloader.entity.auditlog.IAuditLog)

Example 18 with RESTOptions

use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.

the class Guild method getVoiceRegions.

@Override
public CompletableFuture<List<VoiceRegion>> getVoiceRegions() {
    CompletableFuture<List<VoiceRegion>> future = new CompletableFuture<List<VoiceRegion>>();
    CompletableFuture<VoiceRegionJSON[]> cf = getLoader().rest.request(Methods.GET, Endpoints.guildRegions(getID()), new RESTOptions(), VoiceRegionJSON[].class);
    cf.thenAcceptAsync(regions -> {
        List<VoiceRegion> rgs = new ArrayList<>();
        for (VoiceRegionJSON region : regions) {
            rgs.add(new VoiceRegion(region));
        }
        future.complete(rgs);
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) VoiceRegion(io.discloader.discloader.entity.guild.VoiceRegion) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) VoiceRegionJSON(io.discloader.discloader.network.json.VoiceRegionJSON)

Example 19 with RESTOptions

use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.

the class Guild method createEmoji.

@Override
public CompletableFuture<IGuildEmoji> createEmoji(String name, String image, IRole... roles) {
    CompletableFuture<IGuildEmoji> future = new CompletableFuture<>();
    String base64 = null;
    try {
        base64 = new String("data:image/jpg;base64," + Base64.encodeBase64String(Files.readAllBytes(Paths.get(image))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    String[] rids = new String[roles.length];
    for (int i = 0; i < rids.length; i++) {
        rids[i] = SnowflakeUtil.asString(roles[i]);
    }
    CreateEmoji ce = new CreateEmoji(name, base64, rids);
    CompletableFuture<EmojiJSON> cf = getLoader().rest.request(Methods.POST, Endpoints.guildEmojis(getID()), new RESTOptions(ce), EmojiJSON.class);
    cf.thenAcceptAsync(ed -> {
        future.complete(new GuildEmoji(ed, this));
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : IGuildEmoji(io.discloader.discloader.entity.guild.IGuildEmoji) CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) CreateEmoji(io.discloader.discloader.entity.sendable.CreateEmoji) IGuildEmoji(io.discloader.discloader.entity.guild.IGuildEmoji) IOException(java.io.IOException) EmojiJSON(io.discloader.discloader.network.json.EmojiJSON)

Example 20 with RESTOptions

use of io.discloader.discloader.network.rest.RESTOptions in project DiscLoader by R3alCl0ud.

the class Guild method createCategory.

@Override
public CompletableFuture<IChannelCategory> createCategory(String name, IOverwrite... overwrites) {
    CompletableFuture<IChannelCategory> future = new CompletableFuture<>();
    JSONArray ows = new JSONArray();
    for (IOverwrite ow : overwrites) {
        ows.put(ow);
    }
    JSONObject chanSet = new JSONObject().put("name", name).put("type", 4).put("permission_overwrites", ows);
    loader.rest.request(Methods.POST, Endpoints.guildChannels(getID()), new RESTOptions(chanSet), ChannelJSON.class).thenAcceptAsync(d -> {
        IChannel channel = EntityBuilder.getChannelFactory().buildChannel(d, loader, this, false);
        if (channel instanceof IChannelCategory)
            future.complete((IChannelCategory) channel);
    });
    return future;
}
Also used : ChannelJSON(io.discloader.discloader.network.json.ChannelJSON) CompletableFuture(java.util.concurrent.CompletableFuture) IChannel(io.discloader.discloader.entity.channel.IChannel) JSONObject(org.json.JSONObject) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) JSONArray(org.json.JSONArray) IOverwrite(io.discloader.discloader.entity.IOverwrite) IChannelCategory(io.discloader.discloader.entity.channel.IChannelCategory)

Aggregations

RESTOptions (io.discloader.discloader.network.rest.RESTOptions)62 CompletableFuture (java.util.concurrent.CompletableFuture)61 JSONObject (org.json.JSONObject)29 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)23 ChannelJSON (io.discloader.discloader.network.json.ChannelJSON)21 IGuildMember (io.discloader.discloader.entity.guild.IGuildMember)11 EventListenerAdapter (io.discloader.discloader.common.event.EventListenerAdapter)10 IGuildChannel (io.discloader.discloader.entity.channel.IGuildChannel)10 IGuildTextChannel (io.discloader.discloader.entity.channel.IGuildTextChannel)9 AuditLog (io.discloader.discloader.core.entity.auditlog.AuditLog)8 IAuditLog (io.discloader.discloader.entity.auditlog.IAuditLog)8 IChannelCategory (io.discloader.discloader.entity.channel.IChannelCategory)8 IMessage (io.discloader.discloader.entity.message.IMessage)8 AuditLogJSON (io.discloader.discloader.network.json.AuditLogJSON)8 ArrayList (java.util.ArrayList)8 IOverwrite (io.discloader.discloader.entity.IOverwrite)7 IGuild (io.discloader.discloader.entity.guild.IGuild)7 IInvite (io.discloader.discloader.entity.invite.IInvite)7 HashMap (java.util.HashMap)7 List (java.util.List)7