Search in sources :

Example 36 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(IUser user) {
    CompletableFuture<IAuditLog> future = new CompletableFuture<>();
    JSONObject params = new JSONObject().put("user_id", SnowflakeUtil.asString(user));
    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 37 with RESTOptions

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

the class Guild method getAuditLog.

/*
	 * (non-Javadoc)
	 * 
	 * @see io.discloader.discloader.entity.guild.IGuild#getAuditLog(io.discloader.
	 * discloader.entity.auditlog.ActionTypes, short)
	 */
@Override
public CompletableFuture<IAuditLog> getAuditLog(ActionTypes action, int limit) {
    CompletableFuture<IAuditLog> future = new CompletableFuture<>();
    CompletableFuture<AuditLogJSON> cf = loader.rest.request(Methods.GET, Endpoints.auditLogs(getID()) + "?action_type=" + action.toInt() + "&limit=" + limit, new RESTOptions(), 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) 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 38 with RESTOptions

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

the class Guild method fetchInvites.

@Override
public CompletableFuture<List<IInvite>> fetchInvites() {
    CompletableFuture<List<IInvite>> future = new CompletableFuture<List<IInvite>>();
    CompletableFuture<InviteJSON[]> cf = getLoader().rest.request(Methods.GET, Endpoints.guildInvites(getID()), new RESTOptions(), InviteJSON[].class);
    cf.thenAcceptAsync(inJ -> {
        List<IInvite> ins = new ArrayList<>();
        for (int i = 0; i < inJ.length; i++) {
            IInvite in = new Invite(inJ[i], getLoader());
            invites.put(in.getCode(), in);
            ins.add(in);
        }
        future.complete(ins);
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) InviteJSON(io.discloader.discloader.network.json.InviteJSON) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IInvite(io.discloader.discloader.entity.invite.IInvite) Invite(io.discloader.discloader.core.entity.invite.Invite) IInvite(io.discloader.discloader.entity.invite.IInvite)

Example 39 with RESTOptions

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

the class Guild method ban.

@Override
public CompletableFuture<IGuildMember> ban(IGuildMember member, String reason) throws PermissionsException {
    if (!hasPermission(Permissions.BAN_MEMBERS))
        throw new PermissionsException("");
    CompletableFuture<IGuildMember> future = new CompletableFuture<>();
    loader.rest.request(Methods.PUT, Endpoints.guildBanMember(getID(), member.getID()), new RESTOptions(reason), Void.class).thenAcceptAsync(action -> {
        future.complete(member);
    });
    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 40 with RESTOptions

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

the class Guild method ban.

@Override
public CompletableFuture<IGuildMember> ban(IGuildMember member) {
    if (!hasPermission(Permissions.BAN_MEMBERS))
        throw new PermissionsException("");
    CompletableFuture<IGuildMember> future = new CompletableFuture<>();
    loader.rest.request(Methods.PUT, Endpoints.guildBanMember(getID(), member.getID()), new RESTOptions(), Void.class).thenAcceptAsync(action -> {
        future.complete(member);
    });
    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)

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