Search in sources :

Example 11 with RESTOptions

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

the class Guild method getPruneCount.

@Override
public CompletableFuture<Integer> getPruneCount(int days) {
    CompletableFuture<Integer> future = new CompletableFuture<>();
    JSONObject payload = new JSONObject().put("days", days);
    CompletableFuture<PruneCountJSON> cf = getLoader().rest.request(Methods.GET, Endpoints.guildPrune(getID()), new RESTOptions(payload), PruneCountJSON.class);
    cf.thenAcceptAsync(data -> {
        future.complete(Integer.valueOf(data.pruned));
    });
    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) PruneCountJSON(io.discloader.discloader.network.json.PruneCountJSON)

Example 12 with RESTOptions

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

the class Guild method kick.

@Override
public CompletableFuture<IGuildMember> kick(IGuildMember member, String reason) {
    if (!isOwner() && getCurrentMember().getPermissions().hasPermission(Permissions.KICK_MEMBERS))
        throw new PermissionsException("Insufficient Permissions");
    CompletableFuture<IGuildMember> future = new CompletableFuture<>();
    CompletableFuture<Void> kickFuture = loader.rest.request(Methods.DELETE, Endpoints.guildMember(getID(), member.getID()), new RESTOptions(reason), Void.class);
    kickFuture.thenAcceptAsync(n -> {
        future.complete(member);
    });
    kickFuture.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException)

Example 13 with RESTOptions

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

the class Guild method fetchMember.

public CompletableFuture<IGuildMember> fetchMember(long memberID) {
    CompletableFuture<IGuildMember> future = new CompletableFuture<IGuildMember>();
    CompletableFuture<MemberJSON> cf = loader.rest.request(Methods.GET, Endpoints.guildMember(getID(), memberID), new RESTOptions(), MemberJSON.class);
    cf.thenAcceptAsync(data -> {
        future.complete(addMember(data, true));
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) IGuildMember(io.discloader.discloader.entity.guild.IGuildMember) MemberJSON(io.discloader.discloader.network.json.MemberJSON)

Example 14 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(int limit) {
    CompletableFuture<IAuditLog> future = new CompletableFuture<>();
    JSONObject params = new JSONObject().put("limit", limit);
    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 15 with RESTOptions

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

the class Guild method edit.

public CompletableFuture<IGuild> edit(String name, String icon, IGuildVoiceChannel afkChannel) throws IOException {
    if (!isOwner() && !getCurrentMember().getPermissions().hasPermission(Permissions.MANAGE_GUILD)) {
        throw new PermissionsException();
    }
    CompletableFuture<IGuild> future = new CompletableFuture<>();
    String base64 = new String("data:image/jpg;base64," + Base64.encodeBase64String(Files.readAllBytes(Paths.get(icon))));
    JSONObject payload = new JSONObject().put("name", name).put("icon", base64);
    CompletableFuture<GuildJSON> cf = getLoader().rest.request(Methods.PATCH, Endpoints.guild(getID()), new RESTOptions(payload), GuildJSON.class);
    cf.thenAcceptAsync(guildJSON -> {
        IGuild guild = clone();
        guild.setup(guildJSON);
        future.complete(guild);
    });
    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) GuildJSON(io.discloader.discloader.network.json.GuildJSON) IGuild(io.discloader.discloader.entity.guild.IGuild) PermissionsException(io.discloader.discloader.common.exceptions.PermissionsException)

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